| | |
mysql php problems
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2006
Posts: 2
Reputation:
Solved Threads: 0
Hi everyone. I've only really just started using php and I've been trying to use it in conjunction with mysql. I keep getting an error though when trying to access the result set returned by performing a query on the database. I've performed queries on the database outwith php, and it correctly returned the correct details. Here's the code for it:
<?php
$dbh=mysql_connect ("localhost", "myusername", "mypassword") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("ababoc_filmlistings");
$sql = 'SELECT DISTINCT title FROM Listing LIMIT 0, 30 ';
$rs = mysql_query($sql);
$row = mysql_fetch_row($rs); // line 24
echo $row[0];
?>
but I end up with the error:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/ababoc/public_html/test/index.php on line 24
I'm really not sure what I could be doing wrong here. Any help would be much appreciated.
<?php
$dbh=mysql_connect ("localhost", "myusername", "mypassword") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("ababoc_filmlistings");
$sql = 'SELECT DISTINCT title FROM Listing LIMIT 0, 30 ';
$rs = mysql_query($sql);
$row = mysql_fetch_row($rs); // line 24
echo $row[0];
?>
but I end up with the error:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/ababoc/public_html/test/index.php on line 24
I'm really not sure what I could be doing wrong here. Any help would be much appreciated.
•
•
Join Date: Mar 2006
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by ammcom
I think definitly the problem is in SQL statment , check the name of the table and its fields , try adding some debugging code
All I can do is expand on what ammcom already told you. Do something like this:
[PHP]
if (!$dbh = mysql_connect ("localhost", "myusername", "mypassword")) {
die ('I cannot connect to the database because: ' . mysql_error());
}
if (!$ret = mysql_select_db ("ababoc_filmlistings")) {
die("db selection failed: ".$mysql_error());
}
$sql = 'SELECT DISTINCT title FROM Listing LIMIT 0, 30 ';
echo "<hr />".$sql."<hr />\n";
if (!$rs = mysql_query($sql)) {
die("db query failed: ".mysql_error());
}
if (!$row = mysql_fetch_row($rs)) {
die("mysql fetch failed: ".mysql_error());
}
echo $row[0];
[/PHP]
If you get an error regarding the query failing, copy and pasted the SQL statement and run it directly against the database--making sure you choose "ababoc_filmlistings" as your db.
[PHP]
if (!$dbh = mysql_connect ("localhost", "myusername", "mypassword")) {
die ('I cannot connect to the database because: ' . mysql_error());
}
if (!$ret = mysql_select_db ("ababoc_filmlistings")) {
die("db selection failed: ".$mysql_error());
}
$sql = 'SELECT DISTINCT title FROM Listing LIMIT 0, 30 ';
echo "<hr />".$sql."<hr />\n";
if (!$rs = mysql_query($sql)) {
die("db query failed: ".mysql_error());
}
if (!$row = mysql_fetch_row($rs)) {
die("mysql fetch failed: ".mysql_error());
}
echo $row[0];
[/PHP]
If you get an error regarding the query failing, copy and pasted the SQL statement and run it directly against the database--making sure you choose "ababoc_filmlistings" as your db.
![]() |
Similar Threads
- Date Field in MySQL with PHP /add/edit/delete (PHP)
- Job wanted - mysql,php,phpbb2 expert, payed wanted (Web Development Job Offers)
- How do I install Apache, MySQL, PHP on Linux? (PHP)
- [JOB] MySQL/PHP Engineer, Los Angeles, CA (Web Development Job Offers)
- Experience the FASTEST MySQL and PHP Hosting | Starting @ $2.50 per month (Web Hosting Deals)
- FASTEST MySQL and PHP Hosting, [Seeing is Believing] 75% OFF On Any Plan (Web Hosting Deals)
- Hardware Requirements for Fedora, Apache, MySQL and PHP on one machine (*nix Hardware Configuration)
- MySQL and PHP hosting (Linux Servers and Apache)
Other Threads in the PHP Forum
- Previous Thread: "system" function
- Next Thread: phwhat?
Views: 1375 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download duplicates dynamic echo email error execution file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link links login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote replace script search select server session sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





