update.php不返​​回错误,但没有数据库更新

时间:2018-06-30 18:26:22

标签: php sql-update

我在这里已经检查了与此类似的问题,并尝试了一些解决方案,但无法使其正常工作。我是php的新手,由于没有错误返回,因此无法弄清楚问题出在哪里。

这是一个简单的错误,但我找不到它。这是我的update.php,下一个是我的updateform.php。

<?php
session_start();
//check the session
if (!isset($_SESSION['email'])){
    exit();
}else{
    //include the header
    include ("../includes/header.php");
    require_once ('../includes/mysqli_connect.php');

    #execute UPDATE statement
    $id = mysqli_real_escape_string($dbc, $_POST['emp_id']); 
    $fname = mysqli_real_escape_string($dbc,  
    $_POST['first_name']); 
    $lname = mysqli_real_escape_string($dbc, 
    $_POST['last_name']); 
    $ad = mysqli_real_escape_string($dbc, $_POST['address']); 
    $ci = mysqli_real_escape_string($dbc, $_POST['city']); 
    $st = mysqli_real_escape_string($dbc, $_POST['state']); 
    $zip = mysqli_real_escape_string($dbc, $_POST['zipcode']); 
    $ph = mysqli_real_escape_string($dbc, $_POST['phone']); 
    $e = mysqli_real_escape_string($dbc, $_POST['email']); 


    $query = "UPDATE employees SET  
    first_name='$fname',last_name='$lname',
    address='$ad', city='$ci', state='$st', zipcode='$zip', 
    phone='$ph', email='$e'  WHERE emp_id='$id'"; 
    $result = @mysqli_query ($dbc, $query); 
    if ($result){
        echo "<center><p><b>The member account has been updated.
    </b></p>"; 
        echo "<a href=index.php>Home</a></center>"; 
    }else {
        echo "<p>The record could not be updated due to a system 
    error" . mysqli_connect_error() . "</p>"; 
    }
    mysqli_close($dbc);
    //include the footer
    include ("../includes/footer.php");
}

?>



<?php
session_start();
//check session first
if (!isset($_SESSION['email'])){
    echo "You are not logged in!";
    exit();
}else{
    //include the header
    include ("../includes/header.php");
    require_once ('../../mysqli_connect.php');
    $id=$_GET['id']; 
    $query = "SELECT * FROM employees WHERE emp_id=$id"; 
    $result = @mysqli_query ($dbc, $query);
    $num = mysqli_num_rows($result);
    if ($num > 0) { // If it ran OK, display all the records.
        while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
?>
    <form action="eupdate.php" method="post">
    First Name: <input name="fname" size=50 value="<? echo  $row['first_name']; ?>"><p>
    Last Name: <input name="lname" size=50 value="<? echo  $row['last_name']; ?>"><p>
    Address: <input name="address" size=50 value="<? echo  $row['address']; ?>"><p>
    City: <input name="city" size=50 value="<? echo  $row['city'];  
    ?>"><p>
    State: <input name="state" size=2 value="<? echo $row['state']; ?>"><p>
    Zipcode: <input name="zipcode" size=5 value="<? echo $row['zipcode']; ?>"><p>
    Phone Number: <input name="phone" size=10 value="<? echo

$ row ['phone']; ?>“>

        电子邮件:“>

    <input type=submit value=update>
    <input type=reset value=reset>
    <input type=hidden name="id" value="<? echo $row['id'];?>">
    </form>
 <?
        } //end while statement
    } //end if statement
    mysqli_close($dbc);
    //include the footer
    include ("../includes/footer.php");
}
?>

在此先感谢任何人提供的建议。

编辑

谢谢! @RiggsFolly。

那很有帮助。现在它正在返回这些通知,但我不知道如何解决。它们拼写正确。有什么建议么?

  

注意:未定义的索引:第17行的/home/teasdal2/public_html/bcr/htdocs/Home/eupdate.php中的名字注意:

     

未定义索引:/home/teasdal2/public_html/bcr/htdocs/Home/eupdate.php,在第18行上的姓氏

0 个答案:

没有答案