Jump to content

what seams to be wrong here?


oops73

Recommended Posts

Hi all!

 

Can anyone take a look at this code and explain to me why i get this error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in i:\easyphp1-8\www\project.php on line 36

 

I have tried and tried... nothing works. Please take a look. Thanks!

 

	// Check If UNIQUE // 
$db = mysql_connect($host, $login, $password) or die ('Erreur connection');
mysql_select_db($base, $db) or die ('Erreur select database');

$result = mysql_query("SELECT * FROM users WHERE unique_id='$unique_id'");
$num_rows = mysql_num_rows($result); // LINE 36  <---

$num_rows > 0 ? $unique = FALSE : $unique = TRUE;
mysql_close();

if (FALSE == $unique){
	$error['unique_id'] = "Already send to the database!";
} else if (TRUE == $unique) {

Link to comment
https://forums.phpfreaks.com/topic/51566-what-seams-to-be-wrong-here/
Share on other sites

ok, Here is an overview of the code so it´s easier to help me.

 

 

// variables //
$listVar = array('IDcode', 'unique_id', 'Fname', 'Lname', 'Region', 'Depart', 'Email');
$noEmptyCheck = array('unique_id');

// Collect variables FORM // 
foreach ($listVar as $value) {
if ($value !== 'IDcode' || $value !== 'unique_id') {
	isset($_SESSION[$value]) ? $$value = htmlentities(trim($_SESSION[$value]), ENT_QUOTES) : $$value = NULL;
}
}
isset($_POST['IDcode']) ? 	$IDcode = $_POST['IDcode'] :	$IDcode = NULL;

////////// WORK now /////////
if (isset($_POST['action']) && ('add' == $_POST['action'])) {
////////// ACTION /////////
// Collect variables ACTION // 
foreach ($listVar as $value) {
	isset($_POST[$value]) ? $$value = htmlentities(trim($_POST[$value]), ENT_QUOTES) : $$value = NULL;
}
// Check If UNIQUE // 
$db = mysql_connect($host, $login, $password) or die ('Erreur connection');
mysql_select_db($base, $db) or die ('Erreur select database');

echo "ID: ".$unique_id;
$result = mysql_query("SELECT * FROM users WHERE unique_id='$unique_id'"); 
$num_rows = mysql_num_rows($result);

$num_rows > 0 ? $unique = FALSE : $unique = TRUE;
mysql_close();

if (FALSE == $unique){
	$error['unique_id'] = "Already send to the database!";
} else if (TRUE == $unique) {

The error is telling you exactly what is wrong. There is no column or field named "unique_id" in the table named "users".

 

Ken

 

Hi Ken, please take a look at the code agian. I have set "IDcode" as "unique_id" in the database.

If i add a "unique_id" field in the table i got my premade errormessage saying that there is an error adding to database.

any ideas?

 

/Joel

Hi Ken, please take a look at the code agian. I have set "IDcode" as "unique_id" in the database.

If i add a "unique_id" field in the table i got my premade errormessage saying that there is an error adding to database.

any ideas?

 

So, then shouldn't you be using:

 

$result = mysql_query("SELECT * FROM users WHERE IDcode='$unique_id'");

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.