help with script

Codes here !

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Tue Sep 18, 2012 9:00 am

help with script

Postby safety » Tue Sep 18, 2012 9:16 am

Hello. First I'd like to say that I'm a beginner with php and mySQL. I've been learning from scratch with the help of a book called "PHP for absolute beginners". I've made good progress up until now I'm stuck on a chapter because I'm getting errors.

I'm trying to make a fairly basic (not for me) way to display information stored in the SQL database. Here's the code, followed by a few of the errors I'm getting. I'd really appreciate some help as I'm at a dead end.

Code: Select all

These are the errors I'm getting

Code: Select all

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\blues\inc\ on line 29

Notice: Undefined variable: e in C:\xampp\htdocs\blues\inc\ on line 42

Thanks in advance for any help

php-forum Fan User
php-forum Fan User
Posts: 577
Joined: Fri Aug 05, 2011 9:53 am

Re: help with script

Postby NigelRen » Wed Sep 19, 2012 11:08 pm

You should always check that a query has executed successfully before you try and use the return value. So depending on what your $db database type is, you may need to check if $db->query($sql) returns false as this may indicate a problem with the query.

Note that this depends entirely on what $db is and you will have to work it out from any information you have, but the main idea is:
Execute some SQL
Did this fail?
Report error and exit
// Must have worked so...
foreach Result Set
Do something with each row

Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 3 guests