General discussion
Thread display: Collapse - |
All Comments
Start or search
Create a new discussion
If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.
PHP Help for Newbie
I am reading the book "PHP Essentials" an cannot get any of the code to work. For instance, I have a very simple MySQL database with a table that contains 9 fields of information about books. I am attempting to add records to the db via a form.
Here is part of the code I am using:
<?php
if ((!$isbn) || (!$title) || (!$price)) {
header("Location: http://myurl/admin_addrecord1.php");
exit;
}
$sql = "INSERT INTO MASTER_PRODUCTS VALUES (\"$isbn\", \"$title\",
\"$author\", \"$publisher\",\"$category\", \"$type\", \"$info_blurb\",
\"$page_num\", \"$price\")";
$connection = mysql_connect("localhost", "myusername", "mypassword") or die
("could not connect ot db");
$db = mysql_select_db("mydatabasename", $connection) or die
("could not select db");
$sql_result = mysql_query($sql, $connection) or die
("could not do query");
if (!$sql_result) {
echo "could not add record";
So, when I run the html form that calls this script, I get the error: could not do query
So, it looks like I am connecting to the db and selecting the db, but I can't query. Can anyone explain what might be causing this. I've tried a couple of other scripts from the book...some that seem really short and simple, but nothing is working.
Thanks!!!