...

View Full Version : PHP error?



nobackseat88
12-26-2007, 05:55 PM
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource


Does ^ this mean I have to upgrade my php version?

Iszak
12-26-2007, 05:59 PM
It generally means that the link resources that was put in was wrong.

eg.

$sql = "SELECT * FROM table LIMIT 1";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);

The $result could be a bad query would would be related to the SQL, or that the actual database isn't connected.

Inigoesdr
12-26-2007, 09:35 PM
Does ^ this mean I have to upgrade my php version?

It means you tried to use mysql_fetch_array() on a variable that wasn't a valid mysql result and/or your query failed to execute due to a sytax error. Iszak's code above shows an example of how it should be used. To see the reason why it failed change your query line to this:

$result = mysql_query($sql) or die(mysql_error());

hammer65
12-26-2007, 10:05 PM
When connecting to and using a database, you are connecting to an external application. All kinds of things can go wrong between connecting to the database and closing the connection. That includes a query failing due to a syntax error or other condition.

Never assume that a database connection is going to succeed or that selection of a database to use is going to succeed, or that a query will execute.

All of the MySQL functions return a value that evaluates to false if there is a problem. Use that to provide proper flow to your application. Each step along the way should be checked and control the flow of your code accordingly. Provide friendly but not technically revealing messages to the user that indicates that something went wrong.

nobackseat88
12-26-2007, 11:55 PM
Thanks guys! Another one tho:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING




?????

Inigoesdr
12-27-2007, 12:21 AM
You're probably missing a quote or colon on or before the line it tells you. Post the code if you can't figure it out. If you use the
tags you'll often be able to tell just by looking at the syntax highlighting. Also, if you use an editor with syntax highlighting/error checking you can usually avoid this problem altogether.

nobackseat88
12-27-2007, 12:35 AM
The red line indicates the line the error pointed out, I believe. Okay, code:


<?php
$mysite_username = $HTTP_COOKIE_VARS["mysite_username"];
$con = mysql_connect("localhost","database","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("database", $con);
mysql_query("UPDATE users SET profile = '$_REQUEST['pcoding']'");
echo "Success!";
?>

Inigoesdr
12-27-2007, 12:39 AM
Change your mysql_query line to this:
mysql_query("UPDATE users SET profile = '{$_REQUEST['pcoding']}'");
You should be using mysql_real_escape_string() (http://php.net/mysql_real_escape_string) or similar on all user input, too.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum