Page 1 of 1
i have a prob
Posted: Mon Feb 03, 2003 10:37 am
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
Posted: Mon Feb 03, 2003 11:25 am
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.
Posted: Mon Feb 03, 2003 11:37 am
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.
Posted: Mon Feb 03, 2003 4:32 pm
by bionicdonkey
get rid of MYSQL_ASSOC
Posted: Tue Feb 04, 2003 2:10 am
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:
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
Posted: Tue Feb 04, 2003 4:46 am
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:
should still get rid of it...doesn't look very nice. (my opinion only)