Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

help with script

Codes here !

Moderators: macek, egami, gesf

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
http://pastebin.com/zbggBcN9


These are the errors I'm getting
Code: Select all
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\blues\inc\functions.inc.php on line 29

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

Thanks in advance for any help
safety
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Sep 18, 2012 9:00 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
NigelRen
php-forum Active User
php-forum Active User
 
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am


Return to mySQL & php coding

Who is online

Users browsing this forum: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.