问题描述:

I wrote a function to update a record. The form displays with all the correct data but after editing data and submitting form, the isset function does not work and record is not updated. Need a little help. Thanks.

/* function to edit employee */

function emp_edit()

}

global $link;

$employeeid = $_GET['id'];

$query = "SELECT * FROM employees where employeeid='$employeeid'";

$result = mysqli_query($link, $query);

$row = mysqli_fetch_assoc($result);

$fname = $row['fname'];

$lname = $row['lname'];

$email = $row['email'];

$zip = $row['zip'];

print "<h3>Edit Employee Record</h3>";

print "<form method='post' action='emp_maintenance.php'>

<br><input type='hidden' name='employeeid' value='$employeeid'>

<br><input type='text' name='fname' value='$fname'> First Name<br>

<br><input type='text' name='lname' value='$lname'> Last Name<br>

<br><input type='text' name='email' value='$email'> Email<br>

<br><input type='text' name='zip' value='$zip'> Zip Code<br>

<br><input type='submit' name='edit3' value='Update'><br>

</form>";

if(isset($_POST['edit3']))

{

$fname = $_POST['fname'];

$lname = $_POST['lname'];

$email = $_POST['email'];

$zip = $_POST['zip'];

$query = "UPDATE employees SET fname='$fname', lname='$lname', email = '$email', zip = '$zip' WHERE employeeid = '$employeeid'";

mysqli_query($link, $query);

}

}

网友答案:

Well as you already find out you need to use opening brackets insted of closing ones. One oteh think I would like to recommend is that after isset condition you use php function is_empty("filed"). Reason for that is when someone is updating the form one more more fields could be left black and in this case you are "deleting" the data when you overwrite value in table with empty string.

相关阅读:
Top