i have a prob

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
forgun
Forum Commoner
Posts: 61
Joined: Wed Jan 29, 2003 6:05 am
Contact:

i have a prob

Post by forgun »

Code: Select all

<?php
$id = $_POST["id"];
include("includes/dbs.php");
$lk = mysql_connect($serv,$user,$pass) or die (mysql_error());
$namd = mysql_select_db($dbname,$lk);
$qur = "select * from News where id = '" .$id . "'";
$res = mysql_query($qur);
$row = mysql_fetch_array($res,MYSQL_ASSOC); #here to line of the prob

?>
mm the error line is

Code: Select all

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site13/fst/var/www/html/staff/upch.php on line 8
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post by Rob the R »

It sounds like the call to mysql_query did not work. Try adding some error trapping to that line and see what error you get:

Code: Select all

$res = mysql_query($qur) or die('Unable to execute query: ' . mysql_error()) ;
While you're at it, you might as well add the "or die" logic to your call to mysql_select_db. Adding error trapping everywhere you can is a good habit to get into.
User avatar
bznutz
Forum Commoner
Posts: 58
Joined: Mon Dec 09, 2002 9:52 pm
Location: Here
Contact:

Post by bznutz »

Take the quotes off of id.
That error occurs when mysql considers your query to be invalid.
If id is a tinyint (as I think it may be) then there is no need to put it in quotes.
Only text and blob fields need the quotes.
bionicdonkey
Forum Contributor
Posts: 132
Joined: Fri Jan 31, 2003 2:28 am
Location: Sydney, Australia
Contact:

Post by bionicdonkey »

get rid of MYSQL_ASSOC
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

bionicdonkey wrote:get rid of MYSQL_ASSOC
MYSQL_ASSOC just tells mysql_fetch_array() to return only the associative array - doing this:

Code: Select all

$row = mysql_fetch_array($res,MYSQL_ASSOC);
is the same as doing this:

Code: Select all

$row = mysql_fetch_assoc($res);
forgun - as Rob the R pointed out, you really need to get as much error handling in there as possible, so carrying on from what he said and what I said above, try this:

Code: Select all

<?php 
$id = $_POST['id']; 
include 'includes/dbs.php'; 
$lk = mysql_connect($serv,$user,$pass) or die (mysql_error()); 
@mysql_select_db($dbname,$lk) or die(mysql_error()); 
$qur = "SELECT * FROM News WHERE id = '$id'"; 
$res = mysql_query($qur) or die(mysql_error(),'<p>'.$qur.'</p>'); 
$row = mysql_fetch_assoc($res);
?>
Mac
bionicdonkey
Forum Contributor
Posts: 132
Joined: Fri Jan 31, 2003 2:28 am
Location: Sydney, Australia
Contact:

Post by bionicdonkey »

MYSQL_ASSOC just tells mysql_fetch_array() to return only the associative array - doing this:

Code: Select all

$row = mysql_fetch_array($res,MYSQL_ASSOC);
is the same as doing this:

Code: Select all

$row = mysql_fetch_assoc($res);
should still get rid of it...doesn't look very nice. (my opinion only)
Post Reply