I have a simple, unsecured, local database that I'm learning with (yes still using MySQL for now) I can view my database rows in a table and click on an edit button which then displays the single record chosen with each column inside a text box to update and save.
This is part of my edit page which displays five text boxes that I'm attempting to update the db with
<?php
while ($row=mysql_fetch_array($result))
{
?>
<form action="updateinfo.php" method="post">
<tr>
<td align="right">Partnumber:</td>
<td align="left"><input type="text" name="partnumber" value="<?php echo $row['partnumber'];?>"/></td>
</tr>
Here is my updateinfo
<?php
mysql_connect("localhost","name","password") or die("Error: ".mysql_error());
mysql_select_db("toner");
$partnumber = $_POST['partnumber'];
$description = $_POST['description'];
$vendor = $_POST['vendor'];
$price = $_POST['price'];
$quantity = $_POST['quantity'];
$sql = "UPDATE inventory SET partnumber ='".$partnumber."',description ='".$description."',vendor ='".$vendor."',price ='".$price."',quantity ='".$quantity."' WHERE partnumber = '".$partnumber ."'";
mysql_query($sql) or die ("Error: ".mysql_error());
echo "Database updated.";
header( "refresh:5;url =toner.php" );
?>
It displays Database updated but no changes are made, any assistance is appreciated, and yes I'm aware its vulnerable to injection and that I should be using PDO or MySQLi but I'm still a beginner and this is where I've chosen to start learning. Thank you.
Instead of this
<form action="updateinfo.php" method="post"
$sql = "UPDATE inventory SET partnumber ='".$partnumber."',description ='".$description."',vendor ='".$vendor."',price ='".$price."',quantity ='".$quantity."' WHERE partnumber = '".$partnumber ."'";
Use this :
<form action="updateinfo.php" method="post">
$sql = "UPDATE inventory SET partnumber ='".$partnumber."',description ='".$description."',vendor ='".$vendor."',price ='".$price."',quantity ='".$quantity."' WHERE partnumber = '".$partnumber."'";
Remove space from '".$partnumber ."'
Try now maybe it will help you.
<?php
while ($row=mysql_fetch_array($result))
{
?>
<form action="updateinfo.php" method="post"
<tr>
<td align="right">Partnumber:</td>
<td align="left"><input type="text" name="partnumber" value="<?php echo $row['partnumber'];?>"/></td>
</tr>
If this loop runs 5 times:
</form>
partnumber