Jump to content

500 error, no good reason?


herghost

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/242157-500-error-no-good-reason/
Share on other sites

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.

 

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.

 

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.