I try to update the last row in a table with user's input email the email column is optional
Html:
I used first form to return item details and update Mysql table - works fine, I put second input for email updates, if a user wants to receive updates
form action="actionemail.php" method="POST" onsubmit="return checkMail(this);">...</form>
The checkMail doesn't work
Javascript
function checkMail(){
if ( theForm.checkbox.checked == false)
{
alert('Did not check box');
return false;
} else {
return 'Thank you we will update you';
}
}
I want to update the last row in table with the user email input to Email column, So I have two calls for server the form works fine
I used this code in php script (details are deleted)
<?
php $servername = "localhost"; $username = ""; $password = "";
$dbname ="";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error()); }
//$time = date('Y-m-d H:i:s'); //$IP = "$_SERVER[REMOTE_ADDR]";
$email = $_POST["email"];
//$sql = "INSERT INTO enterlog (ItemCode, EnterDate, IPAddress, Email) VALUES ('$itemCode', '$time', '$IP', '$email')";
$last = "SELECT MAX(LogID) FROM enterlog";
$sql_update = "UPDATE enterlog SET Email='.$email.' WHERE logid=$last";
if (mysqli_query($conn, $sql_update)) {
echo "<h5>thank you"; } else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn); }
mysqli_close($conn);
?>
I get this error (new):
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT MAX(LogID) FROM enterlog' at line 1
I manage to add new line to table, I can't add the email optional input to the last line.
So what's wrong?