Jump to content

[SOLVED] problem with sql with get and user.


Eggzorcist

Recommended Posts

It seems like my sql command isn't correct as it's not obtaining the correct information. As it always outputs the else command when it should show the if statement.

$_GET['ID'] = $eid;
$_SESSION['USER'] = $euser;

$query = mysql_query("SELECT * FROM events WHERE id = '{$eid}' and user = '{$euser}'");


if (mysql_num_rows($query) >= 1){

$editinfo = mysql_fetch_assoc($query);

}

else {

echo "You cannot edit that particular event, you may only edit events you've created.";
}

 

 

Any idea of syntax or problematic things in this code?

 

Any help will be greatly appreciated.

 

Now I'm getting the

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Users/JPFoster/Sites/Event_Profiler/editevent.php on line 16

 

I'm having trouble with this argument, sometimes this occurs and other time it doesn't... I'm really not sure I'm getting that warning...

That means ur query has failed...

 

try this and see what error it gives

$query = mysql_query("SELECT * FROM events WHERE id = '{$eid}' and user = '{$euser}'") or die(mysql_error());

 

You should probably also echo the query string you are trying to run and see how it looks like.. before you run the query

echo "SELECT * FROM events WHERE id = '{$eid}' and user = '{$euser}'";

well first off, you don't need to wrap your variables in curly brackets unless they are arrays I think.

 

also change your query to

 

$query = mysql_query("SELECT * FROM events WHERE id = '{$eid}' and user = '{$euser}'"); or die(mysql_error());

 

there is obviously an error occuring, that will show what it is.

So this is the current updated code. I'm not getting any sql error, but it hops to else statement when it really should pass the if statement...

 

any ideas?

 

$eid = $_GET['ID'];
$euser = $_SESSION['USER'];

$query = mysql_query("SELECT * FROM events WHERE id = '$eid' and user = '$euser'") or die(mysql_error());


if (mysql_num_rows($query) == 1){

$editinfo = mysql_fetch_assoc($query);

}

else {

echo "You cannot edit that particular event, you may only edit events you've created.";
}

 

thanks,

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.