Hi
I’ve created 3 webpages to update a record within a phpmyadmin table.
The 1st page shows the database content and asks the user to select the “record id” they wish to update.
The 2nd page shows a form to change the content of the record.
The 3rd page offers the user a button to update another record, and includes the updating code.
The pages run together fine with no errors, but when i view my table, the record that should “supposedly” be changed remains the same.
If anyone could point me in the right direction it would be much appreciated!
//////////////////////////////////////
1st page:
<?php
$conn = mysql_connect (“localhost”,“root”,“”) or die (mysql_error());
mysql_select_db(“Library”);
$sql= “SELECT * FROM books”;
$result= mysql_query($sql, $conn) or die (mysql_error());
$num_rows = mysql_num_rows($result);
print “<b>There are $num_rows records in the database:</b><p>”;
print " <table>
";
print " <tr>
";
while ($field = mysql_fetch_field($result))
{
print " <th>$field->name</th>
";
}
print " </tr>
";
while($row= mysql_fetch_assoc($result))
{
print " <tr>
";
foreach ($row as $name => $value)
{
print " <td>$value</td>
";
}
print " </tr>
";
}
print " </table>
";
?>
<form method =“POST” action =“updatechangeform.php”>
<p>
Enter the Book ID to Edit: <input type=“text” name=“BookID” size=“5”>
<input type=“submit” value=“Update”>
<input type=“reset”>
</p>
///////////////////////////////////////////
2nd page:
<?php
include(“dbinfo.inc.php”);
$conn=@mysql_connect(localhost,$username,$password);
$rs=@mysql_select_db(“library”) or die( “Unable to select database”);
$id=$_POST[‘BookID’];
$sql=“SELECT * FROM books WHERE BookID=‘$id’”;
$result=mysql_query($sql);
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$title=mysql_result($result,$i,‘title’);
$cost=mysql_result($result,$i,‘cost’);
$stock=mysql_result($result,$i,‘noinstock’);
++$i;
}
?>
<form action=“updateanother.php” method=“POST”>
<label><b>Enter A Title:</b></label>
<input type =“text” name =“title”/></br>
<label><b>Enter The Cost:</b></label>
<input type =“text” name =“cost”/></br>
<label><b>No In Stock</b></label>
<input type =“text” name =“stock”/></br>
<button type =“submit”>
Update
</button>
<input type=“reset”>
</form>
/////////////////////////////////////////
3rd page:
<?php
include(“dbinfo.inc.php”);
$conn=@mysql_connect(localhost,$username,$password);
$rs=@mysql_select_db(“library”) or die( “Unable to select database”);
$id=$_POST[‘BookID’];
$title=$_POST[‘title’];
$cost=$_POST[‘cost’];
$noinstock=$_POST[‘noinstock’];
$sql=“UPDATE books SET title=‘$title’ ,cost=‘$cost’, noinstock=‘$noinstock’ WHERE id=‘$id’”;
mysql_query($sql);
mysql_close();
?>
<form method=“POST” action=“update.php”>
<input type=“submit” value=“Update Another Record”>
</form>
/////////////////////////////////////////
Thanks