Web Development

General discussion


PHP Help for Newbie

By ldyne ·
Okay, I'm trying to learn PHP and am having some trouble. What I really want to focus on is using HTML forms with PHP to manage MySQL databases...simple, huh?

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:

if ((!$isbn) || (!$title) || (!$price)) {

header("Location: http://myurl/admin_addrecord1.php");



$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.


This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

seen phpMyAdmin?

by Jay Eckles In reply to PHP Help for Newbie

Have you looked at a script called phpMyAdmin? (http://phpmyadmin.sourceforge.net)

It's a web-based administration program for MySQL written in PHP. I enjoy using it quite a bit. For you, it can either serve as the web-based administration you're looking for, or if you just want to write your own for educational purposes, the code in phpMyAdmin could certainly help you get past the trouble you're experiencing.

Good luck.


Collapse -


by ldyne In reply to seen phpMyAdmin?

Thanks, Jay. I am using phpMyAdmim now to manage my database, but I do want to learn how to use HTML forms with PHP to do it as well. I will take a look at the phpMyAdmim code, though, and see if that helps.


Related Discussions

Related Forums