Hi,
I am trying to work through a learning php book I recently purchased. I am stuck. This code is supposed to populate a dropdown box with all the records from a mysql database. I can then select a record and modify it on the next page. I can get it to populate the dropbox and move to the mod page to edit the fields but when i submit the edits I get a bunch of errors that I can't figure out how to fix. (I'm still new to php)
admin_modrecord.php //this part appears to work correctly
<?
$conn = mysql_connect("127.0.0.1","edittedout","edittedout") or die(mysql_error());
$db = mysql_select_db("edittedout", $conn) or die(mysql_error());
$sql = "SELECT ID, ISBN, TITLE FROM MASTER_PRODUCTS ORDER BY TITLE ASC";
$sql_result = mysql_query($sql) or die (mysql_error());
if (!$sql_result) {
echo "Something has gone wrong!";
} else {
echo "
<HTML>
<HEAD>
<TITLE>XYZ Company: Modify a Product</TITLE>
</HEAD>
<BODY>
<h1>Select a Product from the XYZ Company Catalog</h1>
<FORM method=\"POST\" action=\"admin_showmodrecord.php\">
<p><strong>Select a Product:</strong><br>
<select name=\"sel_record\">
<option value=\"\"> -- Select an Item -- </option>";
while ($row = mysql_fetch_array($sql_result)) {
$id = $row["ID"];
$isbn = $row["ISBN"];
$title = $row["TITLE"];
echo "<option value=\"$id\">$title (ISBN: $isbn)</option>";
}
echo "
</select>
<P align=center><INPUT type=\"submit\" value=\"Modify this Product\"></p>
</FORM>
</BODY>
</HTML>";
}
?>
admin_showrecord.php // this page works correct also I think...
<?
$conn = mysql_connect("127.0.0.1","edittedout","edittedout") or die(mysql_error());
$db = mysql_select_db("edittedout", $conn) or die(mysql_error());
$sql = "SELECT * FROM MASTER_PRODUCTS WHERE ID = '$_POST[sel_record]'";
$sql_result = mysql_query($sql) or die (mysql_error());
if (!$sql_result) {
echo "Something has gone wrong!";
} else {
values
while ($record = mysql_fetch_array($sql_result)) {
$id = $record['ID'];
$isbn = stripslashes($record['ISBN']);
$title = stripslashes($record['TITLE']);
$author = stripslashes($record['AUTHOR']);
$publisher = $record['PUBLISHER'];
$category = $record['CATEGORY'];
$type = $record['TYPE'];
$info_blurb = stripslashes($record['INFO_BLURB']);
$page_num = stripslashes($record['PAGE_NUM']);
$price = stripslashes($record['PRICE']);
}
echo "<HTML>
<HEAD>
<TITLE>XYZ Company: Modify a Product</TITLE>
</HEAD>
<BODY>
<h1>Modify this product from the XYZ Company Catalog</h1>
<FORM method=\"POST\" action=\"admin_domodrecord.php\">
<INPUT TYPE=\"hidden\" name=\"id\" value=\"$id\">
<P><strong>ISBN:</strong>
<INPUT type=\"text\" name=\"isbn\" value=\"$isbn\"
size=35 maxlength=25>
<P><strong>Title:</strong>
<INPUT type=\"text\" name=\"title\" value=\"$title\" size=35 maxlength=150>
<P><strong>Author:</strong> <INPUT type=\"text\" name=\"author\" value=\"$author\" size=35 maxlength=75>
<P><strong>Publisher:</strong>
<SELECT name=\"publisher\">
<OPTION value=\"\">-- Select One --</OPTION>";
$pub_array = array("Premier Press", "Course Technology");
foreach ($pub_array as $pub) {
if ($pub == "$publisher") {
echo "<OPTION value=\"$pub\" selected>$pub</OPTION>";
} else {
echo "<OPTION value=\"$pub\">$pub</OPTION>";
}
}
echo "</SELECT>
<strong>Category:</strong>
<SELECT name=\"category\">
<OPTION value=\"\">-- Select One --</OPTION>";
$cat_array = array("Applications", "Operating Systems", "Programming");
foreach ($cat_array as $cat) {
if ($cat == "$category") {
echo "<OPTION value=\"$cat\" selected>$cat</OPTION>";
} else {
echo "<OPTION value=\"$cat\">$cat</OPTION>";
}
}
echo "</SELECT>
<strong>Type:</strong>
<SELECT name=\"type\">
<OPTION value=\"\">-- Select One --</OPTION>";
$type_array = array("hardcover", "paperback");
foreach ($type_array as $book_type) {
if ($type_array == "$type") {
echo "<OPTION value=\"$book_type\" selected>$book_type</OPTION>";
} else {
echo "<OPTION value=\"$book_type\">$book_type</OPTION>";
}
}
echo "</SELECT>
<P><strong>Description:</strong><br>
<TEXTAREA name=\"info_blurb\" cols=35 rows=3>$info_blurb</TEXTAREA>
<P><strong>Page Count:</strong> <INPUT type=\"text\" name=\"page_num\" value=\"$page_num\" size=5 maxlength=5>
<P><strong>Price:</strong> <INPUT type=\"text\" name=\"price\" value=\"$price\" size=5 maxlength=5><br>
<p align=center><INPUT type=\"submit\" value=\"Modify Product\"></p>
</FORM>
</BODY>
</HTML>";
}
?>
When i move to this next page i get these errors.
Notice: Use of undefined constant isbn - assumed 'isbn' in /html/www/automail/admin_domodrecord.php on line 17
Notice: Use of undefined constant title - assumed 'title' in /html/www/automail/admin_domodrecord.php on line 18
Notice: Use of undefined constant author - assumed 'author' in /html/www/automail/admin_domodrecord.php on line 19
Notice: Use of undefined constant publisher - assumed 'publisher' in /html/www/automail/admin_domodrecord.php on line 20
Notice: Use of undefined constant category - assumed 'category' in /html/www/automail/admin_domodrecord.php on line 21
Notice: Use of undefined constant type - assumed 'type' in /html/www/automail/admin_domodrecord.php on line 22
Notice: Use of undefined constant info_blurb - assumed 'info_blurb' in /html/www/automail/admin_domodrecord.php on line 24
Notice: Use of undefined constant page_num - assumed 'page_num' in /html/www/automail/admin_domodrecord.php on line 25
Notice: Use of undefined constant price - assumed 'price' in /html/www/automail/admin_domodrecord.php on line 26
<?
$conn = mysql_connect("127.0.0.1","edittedout","edittedout") or die(mysql_error());
$db = mysql_select_db("edittedout", $conn) or die(mysql_error());
$sql = "UPDATE MASTER_PRODUCTS SET ISBN = '$_POST[isbn]', TITLE = '$_POST[title]', AUTHOR = '$_POST[author]', PUBLISHER = '$_POST[publisher]', CATEGORY = '$_POST[category]', TYPE = '$_POST[type]', INFO_BLURB = '$_POST[info_blurb]', PAGE_NUM = '$_POST[page_num]', PRICE = '$_POST[price]' WHERE ID = '$_POST[id]'";
$result = mysql_query($sql) or die (mysql_error());
if (isset($result)) {
echo "<HTML>
<HEAD>
<TITLE>XYZ Company: Modify a Product</TITLE>
</HEAD>
<BODY>
<h1>The new record looks like this:</h1>
<P><strong>ISBN:</strong> ".stripslashes($_POST[isbn])."
<P><strong>Title:</strong> ".stripslashes($_POST[title])."
<P><strong>Author:</strong> ".stripslashes($_POST[author])."
<P><strong>Publisher:</strong> ".stripslashes($_POST[publisher])."
<strong>Category:</strong> ".stripslashes($_POST[category])."
<strong>Type:</strong> ".stripslashes($_POST[type])."
<P><strong>Description:</strong><br> ".stripslashes($_POST[info_blurb])."
<P><strong>Page Count:</strong> ".stripslashes($_POST[page_num])."
<P><strong>Price:</strong> ".stripslashes($_POST[price])."
<P align=center><a href=\"admin_menu.php\">Return to Menu</a></p>
</BODY>
</HTML>";
} else {
echo "Some sort of error has occurred!</p>";
}
?>
How do I define these. I don't understand.
Please help.
Thanks in advance!