This question already has an answer here:
- Update Multiple Rows in one PHP 2 answers
I have a simple issue that I can't solve. I've tried googling and looking on SO, but found nothing that helps.
Basically, I have a PHP page that has inputs, and the inputs are POST
ed to another PHP file that in turn queries a few MySQL statements and updates the database with the information in the first PHP page.
This is my PHP with the form:
<!DOCTYPE html lang="en">
<head>
<meta charset="utf-8">
<title>form page</title>
</head>
<body>
<form action="mainfileupdatetest.php" method="POST">
<p>
<label for="test">A:</label>
<input type="text" name="test" id="test">
<label for="test2">B:</label>
<input type="text" name="test2" id="test2">
<label for="test3">A:</label>
<input type="text" name="test3" id="test3">
<label for="test4">B:</label>
<input type="text" name="test4" id="test4">
</p>
<button type="submit" value="submit">
</form>
<?php
$mysqli->close();
?>
</body>
</html>
And this is the PHP file that updates the database:
<?php
$link = mysqli_connect("localhost", "root", "fakepassword", "fakedb");
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
$test = mysqli_real_escape_string($link, $_REQUEST['test']);
$test2 = mysqli_real_escape_string($link, $_REQUEST['test2']);
$test3 = mysqli_real_escape_string($link, $_REQUEST['test3']);
$test4 = mysqli_real_escape_string($link, $_REQUEST['test4']);
$sql = "UPDATE mainfile SET A='$test', B='$test2' WHERE id='1'";
$sql = "UPDATE mainfile SET A='$test3', B='$test4' WHERE id='2'";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not execute $sql. " . mysqli_error($link);
}
mysqli_close($link);
?>
There are no PHP or MySQL errors that pop up, but when I input information into the form, only certain ones get saved into the database by MySQL.
This is the table as seen on PHPMyAdmin:
And when I input information like this:
(side question, why doesn't the submit
button show the name I gave it? [value:submit
])
But on the database:
That happens. Anyone able to enlighten me?
</div>