Hi,
Im just in the middle of creating an update script for my mysql database but don't know why it's not working. p.s. I'm a little new to PHP, but know quite a bit, it's probably something really small.. *facepalm*
Here's the script:
the form (update.php)
<?
// Connect to the database
$link = mysql_connect('###', '###', '###');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('###', $link);
$id = $_GET['id'];
// Ask the database for the information from the links table
$query="SELECT * FROM orders WHERE id='$id'";
$result = mysql_query("SELECT * FROM orders");
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$name=mysql_result($result,$i,"Name");
$location=mysql_result($result,$i,"Location");
$fault=mysql_result($result,$i,"Fault");
?>
<form action="updated.php" method="post">
<input type="hidden" name="ud_id" value="<? echo "$id";?>">
Name: <input type="text" name="ud_name" value="<? echo "$name"?>"><br>
Location: <input type="text" name="ud_location" value="<? echo "$location"?>"><br>
Fault: <input type="text" name="ud_fault" value="<? echo "$fault"?>"><br>
<input type="Submit" value="Update">
</form>
<?
++$i;
}
?>
------------------------------------------------------
(processor) updated.php
<?php
// Connect to the database
$link = mysql_connect('###', '###', '###');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('###', $link);
$query="UPDATE orders SET Name='" . $_POST['ud_name'] . "', Location='" . $_POST['ud_location'] . "', Fault='" . $_POST['ud_fault'] . "' WHERE $id='" . $_POST['ud_id'] . "'";
echo $query;
$checkresult = mysql_query($query);
if ($checkresult) echo '<p>update query succeeded';
else echo '<p>update query failed';
mysql_close();
?>
------------------------------------------------------
Every time I want to update, it comes up with:
UPDATE orders SET Name='TEST', Location='TEST', fault='jbjh' WHERE =''
update query failed
Any help would be appreciated. :)