Jump to content

[SOLVED] mysql error I dont understand why?


garethhall

Recommended Posts

Hello please help me out

 

I am getting this error " mysql_query(): supplied argument is not a valid MySQL-Link resource in"

I don't understand why my query is good I have tested it in phpMyAdmin and runs fine so why am I getting this error

 

// Protect Variables from SQL injection
function checkVars($value){
// Stripslashes
if (get_magic_quotes_gpc()){
 	$value = stripslashes($value);
}
// Quote if not a number
if (!is_numeric($value)){
	$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
};

// set Variables
$clientID = checkVars($_GET['clientID']);

mysql_select_db($database_admin , $admin);


function photoCount($saleState, $clientID){
$SQL_countPhotos = "SELECT COUNT(photos.photoID), photos.saleState, photos.clientId FROM photos WHERE photos.saleState = '$saleState' AND photos.clientId = '$clientID'";
$rs_countPhotos= mysql_query($SQL_countPhotos, $admin);
$row_countPhotos = mysql_fetch_assoc($rs_countPhotos);
//echo $SQL_countPhotos;
echo $row_countPhotos['COUNT(photos.photoID)'];
}

This is easier on the eyes.

<?php
// Protect Variables from SQL injection
function checkVars($value){
// Stripslashes
if (get_magic_quotes_gpc()){
	$value = stripslashes($value);
}
// Quote if not a number
if (!is_numeric($value)){
	$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
};

// set Variables
$clientID = checkVars($_GET['clientID']);

mysql_select_db($database_admin , $admin);


function photoCount($saleState, $clientID){
$SQL_countPhotos = "SELECT COUNT(photos.photoID), photos.saleState, photos.clientId FROM photos WHERE photos.saleState = '$saleState' AND photos.clientId = '$clientID'";
$rs_countPhotos= mysql_query($SQL_countPhotos, $admin);
$row_countPhotos = mysql_fetch_assoc($rs_countPhotos);
//echo $SQL_countPhotos;
echo $row_countPhotos['COUNT(photos.photoID)'];
}
?>

Okay.. i'll let you work it out,

but first think about these two questions

#1 what is $admin.

and

#2 What does the error say is invalid ?

 

and i assume this works when they are not in their own functions

 

idea..

global $admin;

 

EDIT: awww Ken2k7!! lol

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.