updating mySQL table from form - stopped working
Posted: Fri Jul 18, 2008 2:29 pm
Hi. I've been learning PHP for a couple months. I made a form to let me add books from my library into a mySQL table. It worked for a while. =) Then I made another page to let me update what page I was on, and when I got that working the book entry form stopped. I don't remember making any changes to it, but then I suppose anything's possible. What happens is I get the "Book successfully added." output, but it doesn't actually add anything. Here's the page that does the processing for the book entry form:
And, just for kicks, here's the page updater:
Any thoughts?
Code: Select all
<?php
#-----------------------#
# Functions #
#-----------------------#
function check_input ($form_array) {
if ($form_array['isbn'] && $form_array['title'] && $form_array['author']) {
return 1;
}
else return 0;
}
#-----------------------#
# User Variables #
#-----------------------#
$host = "********";
$user = "********";
$pw = ********";
$database = "********";
$table_name = "********";
$pin = "****";
#-----------------------#
# Main Body #
#-----------------------#
if ($_POST['pin']==$pin){
if (check_input($_POST)) {
$db = mysql_connect($host, $user, $pw)
or die("Cannot connect to mySQL.");
mysql_select_db($database, $db)
or die("Cannot connect to database.");
$add_book = "insert into $table_name values('".addslashes($_POST['isbn'])."','".addslashes($_POST['title'])."','".addslashes($_POST['author'])."','".addslashes($_POST['genre'])."','".addslashes($_POST['page_on'])."','".addslashes($_POST['review'])."','".addslashes($_POST['where_got'])."');";
mysql_query($add_book);
print "Book successfully added.<br />";
mysql_close($db);
}
else { print "ISBN, Title & Author are all mandatory. Please try again.<br />"; }
}
else { print "Wrong PIN, bucko...<br />";}
?>
Code: Select all
<?php
#-----------------------#
# Functions #
#-----------------------#
function check_input ($form_array) {
if ($form_array['title'] && $form_array['page']) {
return 1;
}
else return 0;
}
#-----------------------#
# User Variables #
#-----------------------#
$host = "********";
$user = "********";
$pw = "********";
$database = "********";
$table_name = "********";
#-----------------------#
# Main Body #
#-----------------------#
if (check_input($_POST)) {
$db = mysql_connect($host, $user, $pw)
or die("Cannot connect to mySQL.");
mysql_select_db($database, $db)
or die("Cannot connect to database.");
$update_pages = "update $table_name set page_on = '$_POST[page]' where title like('$_POST[title]%');";
mysql_query($update_pages)
or die(mysql_error());
print "Page successfully updated.<br />";
print "<a href=http://jhoward1.userworld.com/pages.php>Return to Pages...</a>";
mysql_close($db);
}
else { print "Data was NOT entered due to errors.<br />"; }
?>