| | |
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 |
Tag cloud for PHP
.htaccess access ajax apache api array autosuggest beginner binary broken cakephp checkbox class cms code cron curl data database date directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link links login loop mail md5 menu mlm mod_rewrite multiple mysql mysql_real_escape_string oop parse paypal pdf php problem query radio random recursion regex remote replace script search searchbox server session sessions sms soap source space sql structure syntax system table tutorial update upload url validation validator variable video votedown web website xml youtube






