herghost Posted July 16, 2011 Share Posted July 16, 2011 Hi all, This is starting to pi** me off! Basically here is my code <?php include('scripts/connect.php'); $oid = $_GET['oid']; //insert if does not exist $test1 = mysql_query("SELECT id FROM user WHERE oid = '$oid'"); if(mysql_num_rows($test1) == 0) { $test2 = mysql_query("INSERT INTO user (oid) VALUES ('$oid')"); $step2 ='http://50dollargigs.com/step2.php?oid='.$oid; header('Location: '.$step2); } //if exist set cookie and redirect else { $result = $mysql_query("SELECT id FROM user WHERE oid = '$oid'"); $row = mysql_fetch_array($result); $id = $row['$id']; setcookie("log",$id,time()+3600); echo $_COOKIE["log"]; } ?> If a user has never signed in before, then it works correctly, the oid is entered into the database as expected and the user is redirected. If however, the oid exist in the database then I get a error 500 I have no .htaccess so I am at a total loss of whats causing it! Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/242157-500-error-no-good-reason/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 16, 2011 Share Posted July 16, 2011 You are getting a fatal php runtime error because of the $ on the mysql_query() function call. $result = $mysql_query("SELECT id FROM user WHERE oid = '$oid'"); If you were developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON, you would not need anyone to point out problems in your code like this one, because php would call your attention to the line with the error in it. Quote Link to comment https://forums.phpfreaks.com/topic/242157-500-error-no-good-reason/#findComment-1243591 Share on other sites More sharing options...
herghost Posted July 16, 2011 Author Share Posted July 16, 2011 damn it, I thought dreamweaver would have picked that up to be honest I take the hint though, and thanks for the spot PFMaBiSmAd Cheers Quote Link to comment https://forums.phpfreaks.com/topic/242157-500-error-no-good-reason/#findComment-1243592 Share on other sites More sharing options...
gizmola Posted July 16, 2011 Share Posted July 16, 2011 A 500 error indicates an internal problem. Check your error logs for apache and see if there is anything helpful in there. What data type is the oid column? Also, I wouldn't expect this code to work the way you think it will: setcookie("log",$id,time()+3600); echo $_COOKIE["log"]; The cookie may be set correctly but you will not be able to read it from $_COOKIE in the same page. Quote Link to comment https://forums.phpfreaks.com/topic/242157-500-error-no-good-reason/#findComment-1243594 Share on other sites More sharing options...
gizmola Posted July 16, 2011 Share Posted July 16, 2011 Nice pickup as usual by PFMaBiSmAd. Quote Link to comment https://forums.phpfreaks.com/topic/242157-500-error-no-good-reason/#findComment-1243595 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.