| | |
php\sql error
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
Hi I am trying to teach myself some php and get this error (below) when I query a sql database this is just a tutorial and will never go live.
I have hilighted the area in bold where the unseen error is.
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/dbconnect1.php on line 14
[code]
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpassword= "password";
$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'];
}
?>
[code/]
please go easy on me as am a novice...
I have hilighted the area in bold where the unseen error is.
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /var/www/dbconnect1.php on line 14
[code]
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpassword= "password";
$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'];
}
?>
[code/]
please go easy on me as am a novice...
I would use mysql_fetch_array instead of mysql_fetch_assoc.
But your problem lies here:
But your problem lies here:
mysql_select_db ($dbdatabase, $db); Last edited by squid44th; Feb 23rd, 2008 at 11:50 am.
![]() |
Similar Threads
- how to do conenction between php and my sql (PHP)
- Problems using a php generator (PHP)
- Please Help! parse error, unexpected T_STRING (PHP)
- configure PHP to work with Mysql (MySQL)
- calling a SQL UDF? (PHP)
- Error with Update (MySQL)
- PHP Parse error: parse error, unexpected T_STRING (PHP)
- Php Syntax Error (PHP)
- question about connecting odbc to sql through php script (PHP)
- HELP PHP w/SQL Code HELP (PHP)
Other Threads in the PHP Forum
- Previous Thread: Too new to figure it out - Can someone help me with a complicated search parameters
- Next Thread: .htaccess mod_rewrite to php login
Views: 593 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess 5.2.10 access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email error file files folder form forms function functions google header href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple mysql mysqlquery oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap sockets source space speed sql structure syntax system table thesishelp tutorial update updates upload url validation validator variable video web xml youtube





