This form is driving me scatty!!
I cannot for the life of me see where I am going wrong!!
I am attempting to buid a form that will form part of a rudimentry CMS, this being the record editing page.
It lists the items fine & displays the form fine but every time I submit the changes I get my query error handling message "update failed".
It's gonna be something obvious I am sure but can anybody please help?
Thanks.
I cannot for the life of me see where I am going wrong!!
I am attempting to buid a form that will form part of a rudimentry CMS, this being the record editing page.
It lists the items fine & displays the form fine but every time I submit the changes I get my query error handling message "update failed".
It's gonna be something obvious I am sure but can anybody please help?
Thanks.
Code:
<?
//connect to mysql
mysql_connect("localhost","","");
//select database
mysql_select_db("uniquecrauk");
//If cmd has not been initialized
if(!isset($cmd))
{
//display all the items
$result = mysql_query("select * from gallery order by id");
echo"<table border='1'>";
echo"<tr><td>ID No.</td><td>Name</td><td>Action</td><tr>";
//run the while loop that grabs all the gallery items
while($r=mysql_fetch_array($result))
{
//grab the name and the ID of the gallery item
$name=$r["name"];//extract the name
$id=$r["ID"];//extract the id
//make the name a link
echo"<tr><td>$id</td><td>$name</td><td><a href='edit.php?cmd=edit&id=$id'>Click To Edit</a></td><tr>";
}
echo "</table>";
}
?>
<?
//the form bit
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["id"];
$sql = "SELECT * FROM gallery WHERE ID=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
<?php echo"record number:$id"; ?>
<form action="edit.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">
<table><tr><td>
Name:</td></tr><tr><td><INPUT TYPE="TEXT" NAME="name" VALUE="<?php echo $myrow["name"] ?>" SIZE=60></td></tr><tr><td>
Price:</td></tr><tr><td><INPUT TYPE="TEXT" NAME="price" VALUE="<?php echo $myrow["price"] ?>" SIZE=12></td></tr><tr><td>
Thumb:</td></tr><tr><td><INPUT TYPE="TEXT" NAME="thumb" VALUE="<?php echo $myrow["thumb"] ?>" SIZE=60></td></tr><tr><td>
Image:</td></tr><tr><td><INPUT TYPE="TEXT" NAME="image" VALUE="<?php echo $myrow["image"] ?>" SIZE=60></td></tr><tr><td>
Description:</td></tr><tr><td><TEXTAREA NAME="description" ROWS=10 COLS=30><? echo $myrow["description"] ?></TEXTAREA><br></td></tr><tr><td>
Style:</td></tr><tr><td><INPUT TYPE="TEXT" NAME="style" VALUE="<?php echo $myrow["style"] ?>" SIZE=30><br></td></tr><tr><td><tr><td>
Style ID:</td></tr><tr><td><INPUT TYPE="TEXT" NAME="style_id" VALUE="<?php echo $myrow["style_id"] ?>" SIZE=30></td></tr><tr><td>
New:</td></tr><tr><td><INPUT TYPE="TEXT" NAME="new" VALUE="<?php echo $myrow["new"] ?>" SIZE=30></td></tr><tr><td>
Special:</td></tr><tr><td><INPUT TYPE="TEXT" NAME="special" VALUE="<?php echo $myrow["special"] ?>" SIZE=30></td></tr><tr><td>
Catagory:</td></tr><tr><td><INPUT TYPE="TEXT" NAME="cat" VALUE="<?php echo $myrow["cat"] ?>" SIZE=30></td></tr><tr><td>
Gallery:</td></tr><tr><td><INPUT TYPE="TEXT" NAME="gallery" VALUE="<?php echo $myrow["gallery"] ?>" SIZE=30></td></tr><tr><td>
<input type="hidden" name="cmd" value="edit">
<input type="submit" name="submit" value="submit">
</tr><table>
</form>
<? } ?>
<?
//the query bit
if ($_POST["$submit"])
{
$id = $_POST['id'];
$name = $_POST['name'];
$price = $_POST['price'];
$thumb = $_POST['thumb'];
$image = $_POST['image'];
$description = $_POST['description'];
$style = $_POST['style'];
$style_id = $_POST['style_id'];
$new = $_POST['new'];
$special = $_POST['special'];
$cat = $_POST['cat'];
$gallery = $_POST['gallery'];
$sql = "UPDATE gallery SET name='$name', price= '$price', thumb= '$thumb', image= '$image', description= '$description', style= '$style', style_id='$style_id', new= '$new', special= '$special', cat= '$cat', gallery= '$gallery' WHERE ID=$id";
$result = mysql_query($sql);
if ($result)
{
echo( "Record $name Updated." );
}
else
{
echo "Update Failed";
}
?><a href ='edit.php'>return</a><?php
}
}
?>