Error querying database

sarahbelle

New member
Joined
Mar 24, 2009
Messages
3
Hello,

I have triple checked my code, yet cannot seem to get my form to work. I keep getting an "Error querying database" message. :confused:

I've attached the code (its an example from the book - "Headfirst PHP and MYSQL") and maybe someone can figure out where I'm going wrong? (I changed my actual info in the document to protect my info - so my password isn't really "password" etc)

Thanks for the help!

Attached - phpcode.txt (I actually have it named to be "report.php" when executing

html.txt (actually report.html) - the test file
 

Attachments

My first question would be: are you sure you have MySQL 4.1 or 5.x and therefore can use mysqli_* functions instead of mysql_*?
Then, are you sure the MySQL user has INSERT privileges for the given database?
Then again, why that [insecure for SQL injections] script uses die() without mysqli_error(), that gives the exact MySQL error as output?

With the last question, I may add that I also think that what you have in your hands is not a serious book :(
 
Re:

My first question would be: are you sure you have MySQL 4.1 or 5.x and therefore can use mysqli_* functions instead of mysql_*?
Then, are you sure the MySQL user has INSERT privileges for the given database?
Then again, why that [insecure for SQL injections] script uses die() without mysqli_error(), that gives the exact MySQL error as output?

With the last question, I may add that I also think that what you have in your hands is not a serious book :(

I doubled checked with my host and they said that I have mysqli enabled.

I am only in the 2nd chapter of the book, so I have yet to see how the scripts and code are later on :rolleyes:

I'm definately a newbie, so if you have a recommended book or resource to help out, I'd appreciate it.
 
Well, I'd suggest doing it like I did: learning by yourself, reading official documentation (http://dev.mysql.com/doc/, http://www.php.net/), modifying existing software, trying to understand how it works and replicate it... it can take months, but it's the best way to learn everything about it.

Anyway, in this case there is a simple solution: modify the line:
Code:
die('Error querying database.');
with:
Code:
die('Error querying database: ' . mysqli_error());

This way you will see exactly what's going on.
 
Back
Top