Web Hosting Talk







View Full Version : PHP/MySQL Problem


ckpeter
01-29-2002, 01:22 AM
I am installing a php program(webcp), and I ran into a problem. Whenever I access a page, it gives an error:

Warning: Supplied argument is not a valid MySQL result resource in /home/ admin/cp/template.inc.php on line 15
// web.cp

I then emptied that php file, and the login page display. But whenever I try to login, it gives this error,

Warning: Supplied argument is not a valid MySQL result resource in /home/ admin/cp/login.php on line 9

Warning: Cannot add header information - headers already sent by (output started at /home/admin/cp/login.php:9) in /home/ admin/cp/login.php on line 10

Looking at the source code and the two instances of error, I am suspecting that it has something to do with the php function mysql_query() and mysql_fetch_array(). However, as I am not a PHP programmer, I could not figure how it works.

I have the same code on another server, which works, but that server is using PHP 4.0.6. I am using PHP 4.0.4pl1 and MySql 3.23.36 for this server.

Could someone tell me why such error may arise and what to do to correct them?

Thanks,

Peter

iVersit
01-29-2002, 03:26 AM
Look at the specified line and disect the query, make sure the tables being queried exist and contain relevant data.

insiderhosting
01-29-2002, 04:21 AM
Warning: Cannot add header information - headers already sent by (output started at /home/admin/cp/login.php:9) in /home/ admin/cp/login.php on line 10
Open up login.php in a text editor and search for any whitespace before and after the
<php> tags. Usually it is the whitespace after the closing php ?>tag that is the problem.

zupanm
01-29-2002, 10:13 AM
what insiderhosting will clear up the header error you are getting if not all of your errors.

Noldar
01-29-2002, 11:20 AM
This error:

Warning: Supplied argument is not a valid MySQL result resource in /home/ admin/cp/login.php on line 9

Sounds like the mysql_query() failed. The code generally would look something like this:

$sql_code = "Select something from somewhere";
$result = mysql_query($sql_code,$connection);

Then when it tried to fetch a row:

$row = mysql_fetch_array($result);

$result is null so you get an error. You can try adding the following to your query to get more information on why it failed.

$result = mysql_query($sql_code,$connection) or
die("Couldn't execute query: " . mysql_error());

The error:

Warning: Cannot add header information - headers already sent by (output started at /home/admin/cp/login.php:9) in /home/ admin/cp/login.php on line 10

happens when you try to use a header() function and something has already been sent to the browser. In this case, probably because of the first error message already being sent.

Richard

Ectoman
01-29-2002, 06:12 PM
Yeah,
You can't have it like this:

<?php
stuff
?>

<?php
include('something');
?>

And then in the include file... something causes an error.. but I doubt that is the problem..

ckpeter
01-29-2002, 10:26 PM
Thanks guys for the help and the PHP education. I discovered that I need to set the right password for MySQL. (How silly was it for me to forget...)

Thanks,

Peter