Eggzorcist Posted August 19, 2009 Share Posted August 19, 2009 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. Link to comment https://forums.phpfreaks.com/topic/171010-solved-problem-with-sql-with-get-and-user/ Share on other sites More sharing options...
TeNDoLLA Posted August 19, 2009 Share Posted August 19, 2009 This part should be probably $eid = $_GET['ID']; $euser = $_SESSION['USER']; You could also echo $query; to see if the query string is correct.. Link to comment https://forums.phpfreaks.com/topic/171010-solved-problem-with-sql-with-get-and-user/#findComment-901919 Share on other sites More sharing options...
Eggzorcist Posted August 19, 2009 Author Share Posted August 19, 2009 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... Link to comment https://forums.phpfreaks.com/topic/171010-solved-problem-with-sql-with-get-and-user/#findComment-901926 Share on other sites More sharing options...
TeNDoLLA Posted August 19, 2009 Share Posted August 19, 2009 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}'"; Link to comment https://forums.phpfreaks.com/topic/171010-solved-problem-with-sql-with-get-and-user/#findComment-901930 Share on other sites More sharing options...
mikesta707 Posted August 19, 2009 Share Posted August 19, 2009 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. Link to comment https://forums.phpfreaks.com/topic/171010-solved-problem-with-sql-with-get-and-user/#findComment-901932 Share on other sites More sharing options...
Eggzorcist Posted August 19, 2009 Author Share Posted August 19, 2009 I'm not getting the error anymore, but it still doesn't pass when it's suppose to... Link to comment https://forums.phpfreaks.com/topic/171010-solved-problem-with-sql-with-get-and-user/#findComment-901967 Share on other sites More sharing options...
Eggzorcist Posted August 19, 2009 Author Share Posted August 19, 2009 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, Link to comment https://forums.phpfreaks.com/topic/171010-solved-problem-with-sql-with-get-and-user/#findComment-901984 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.