| | |
Newbie
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2007
Posts: 4
Reputation:
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'];
}
?>
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";
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
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
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);
•
•
Join Date: Nov 2007
Posts: 4
Reputation:
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 Syntax (Toggle Plain Text)
<?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: 129
Reputation:
Solved Threads: 15
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.
![]() |
Similar Threads
- As a newbie, where i should start from in linux? (Getting Started and Choosing a Distro)
- Questions about building a system (was: newbie) (Troubleshooting Dead Machines)
- 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
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube






