•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 455,968 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,739 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1034 | Replies: 11
![]() |
•
•
Join Date: Nov 2007
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Can someone please help, I have this code below and every time i execute it i get this error:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/dbconnect1.php on line 14
I can work out what i am doin wrong.
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpassword= "spewguts";
$dbdatabase - "productsdb";
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($database, $db);
$sql = "SELECT * FROM products;";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
echo $row['product'];
}
?>
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/dbconnect1.php on line 14
I can work out what i am doin wrong.
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpassword= "spewguts";
$dbdatabase - "productsdb";
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($database, $db);
$sql = "SELECT * FROM products;";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
echo $row['product'];
}
?>
•
•
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation:
Rep Power: 3
Solved Threads: 68
this is your error dude:
change that one to this one:
$sql = "SELECT * FROM products;";
change that one to this one:
$sql = "SELECT * FROM products";
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
http://ryantetek.wordpress.com
if i may ask why is using a semi colon at the end of an SQL statement a problem ? this is valid sql markup
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
•
•
Join Date: Nov 2007
Location: Baton Rouge, LA
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
Last edited by TheZert : Nov 23rd, 2007 at 3:17 am.
One of the problems the internet has introduced is that in the electronic village all the village-idiots have internet access. -Peter Nelson
i realise there is a semi colon inside the sql statement and after which is correct syntax for sql string then he appends the php line with a semi colon ?
does this affect the way php reads it?
if so then i have learned something new today.
does this affect the way php reads it?
if so then i have learned something new today.
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 636
Reputation:
Rep Power: 3
Solved Threads: 71
•
•
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation:
Rep Power: 3
Solved Threads: 68
yeah,this one:
should be:
$dbdatabase - "productsdb";
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($database, $db);
should be:
$dbdatabase = "productsdb";
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
http://ryantetek.wordpress.com
•
•
Join Date: Nov 2007
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
No i still have the same problem.
I have made some changes but sill the same error.
Any suggestions would be great.
I have made some changes but sill the same error.
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpassword= "spewguts";
$dbdatabase = "productsdb";
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($database, $db);
$sql = "SELECT * FROM products";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
echo $row['product'];
}
?>Any suggestions would be great.
•
•
Join Date: Aug 2007
Posts: 128
Reputation:
Rep Power: 2
Solved Threads: 13
use mysql_error()...
oh, and you named your vars wrong....
see if it works now
oh, and you named your vars wrong....

see if it works now
php Syntax (Toggle Plain Text)
<?php $dbhost = "localhost"; $dbuser = "root"; $dbpassword = "spewguts"; $dbdatabase = "productsdb"; $db = mysql_connect($dbhost, $dbuser, $dbpassword) or die("Error: ".mysql_error()); mysql_select_db($dbdatabase, $db); $sql = "SELECT * FROM products"; $result = mysql_query($sql) or die("Error: ".mysql_error()); while ($row = mysql_fetch_assoc($result)) { echo $row['product']; } ?>
Last edited by hacker9801 : Dec 8th, 2007 at 8:13 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Questions about building a system (was: newbie) (Troubleshooting Dead Machines)
- As a newbie, where i should start from in linux? (Getting Started and Choosing a Distro)
- Best free C/C++ compiler for a newbie? (C++)
- help newbie alert needs help with login page (ASP.NET)
- newbie needs help, basic mfc stuff (C++)
- Hello, newbie here... (Geeks' Lounge)
- Book For Newbie (C++)
- Newbie - how do I start C++ programming? (C++)
- PHP newbie, project feasibility (PHP)
- How to network two Win98 machines (Networking Hardware Configuration)
Other Threads in the PHP Forum
- Previous Thread: dynamic graphs in php
- Next Thread: attach file


Linear Mode