CMS errors...Help?
Posted: Sun Feb 06, 2011 5:51 am
I followed a tutorial online for a simple cms. Using the code on the tutorial, it worked great. I changed the db fields and adjusted the code to match my needs and the script won't work. Could someone please take a look and see where I erred? Thanks
db sql
update.php
change.php
record.php
db sql
Code: Select all
CREATE TABLE IF NOT EXISTS `lunchspecial` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`category` varchar(35) DEFAULT NULL,
`order_number` varchar(12) DEFAULT NULL,
`meal` varchar(35) DEFAULT NULL,
`spicy` varchar(12) DEFAULT NULL,
`price` varchar(12) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=32 ;Code: Select all
<html><head><title>Update Form</title>
</head>
<body>
<?php
$link = mysql_connect("localhost", "root", "pass");
mysql_select_db("DATABASE_NAME", $link);
$result = mysql_query("SELECT * FROM `lunchspecial` LIMIT 0, 55 " , $link);
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=600 border=0>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td>$field</td>\n";
print "</tr>\n";
}
print "</table>\n";
mysql_close($link);
?>
<br>
<form method="POST" action="change.php">
<pre>
Enter Order Number to Edit:
<input type="text" name="id" size="5">
<input type="submit" value="Submit">
<input type="reset">
</pre>
</form>
</body>
</html>Code: Select all
<?php
$id=$_POST['id'];
$db="DATABASE_NAME";
$link = mysql_connect("localhost", "root", "pass");
mysql_select_db("DATABASE_NAME", $link);
$query = ("SELECT * FROM `lunchspecial` WHERE id='$id'");
$result = mysql_query($query);
$num = mysql_num_rows($result);
$i=0;
while ($i < $num) {
$category=mysql_result($result,$i,"category");
$order_number=mysql_result($result,$i,"order_number");
$meal=mysql_result($result,$i,"meal");
$price=mysql_result($result,$i,"price");
?>
<html><head><title>Change Record form</title>
<style type="text/css">
td {font-family: tahoma, arial, verdana; font-size: 10pt }
</style>
</head>
<body>
<table width="600" cellpadding="10" cellspacing="0" border="0">
<tr align="center" valign="top">
<td align="center" colspan="1" rowspan="1" bgcolor="#64b1ff">
<h3>Edit and Submit</h3>
<form action="record.php" method="post">
<input type="hidden" name="ud_id" value="<?php echo "$id" ?>">
category:<input type="text" name="ud_firstname" value="<?php echo "$category"?>"><br>
order_number:<input type="text" name="ud_firstname" value="<?php echo "$order_number"?>"><br>
meal: <input type="text" name="ud_lastname" value="<?php echo "$meal"?>"><br>
price: <input type="text" name="ud_birthday" value="<?php echo "$price"?>"><br>
<input type="Submit" value="Update">
</form>
</td></tr></table>
<?php
++$i;
}
?>
</body>
</html>Code: Select all
<html><head><title></title></head>
<body>
<?php
$ud_id=$_POST['ud_id'];
$ud_category=$_POST['ud_category'];
$order_number=$_POST['order_number'];
$ud_meal=$_POST['ud_meal'];
$ud_price=$_POST['ud_price'];
$db="DATABASE_NAME";
$link = mysql_connect("localhost", "root", "pass");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
mysql_query(" UPDATE `lunchspecial` SET category='$ud_category' , order_number='$order_number' , meal='$ud_meal' , price='$ud_price' WHERE id='$ud_id'");
echo "Record Updated";
mysql_close($link);
?>
<p> </p>
<a href="update.php">Update another item</a>
</body>
</html>