Jump to content

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.