PHP Redirect Problem
Posted: Mon Apr 21, 2008 12:43 pm
Hi Everyone,
I am a PHP newbie and am doing something that looks really easy, but it won't work and I am stumped.
I have a MySQL database with fields named mid and mlink.
mid is a numeric value that is unique to each record.
mlink is a url associated with the record and is also a unique value.
Below is the script I am trying to use. What I am trying to accomplish is to write a URL like http://www.mydomain.com/out.php?id=4 and have that redirect the user to the URL that is present in the URL field in the db. I know I have the db and the table defined properly, but when I try to make the link to fire the redirection, I get this message. (I am running php5)
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''xxxx')' at line 1
Thank you in advance for any help you can offer.
Scott
I am a PHP newbie and am doing something that looks really easy, but it won't work and I am stumped.
I have a MySQL database with fields named mid and mlink.
mid is a numeric value that is unique to each record.
mlink is a url associated with the record and is also a unique value.
Below is the script I am trying to use. What I am trying to accomplish is to write a URL like http://www.mydomain.com/out.php?id=4 and have that redirect the user to the URL that is present in the URL field in the db. I know I have the db and the table defined properly, but when I try to make the link to fire the redirection, I get this message. (I am running php5)
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''xxxx')' at line 1
Code: Select all
<?php
require("myconfigurationscript.php");
dbinit();
$sitecode="xxxx";
$linkid=$_GET['mid'];
$visitorip= $_SERVER['REMOTE_ADDR'];
$visitorurl= $_SERVER['HTTP_REFERER'];
$visitorbrowser= $_SERVER['HTTP_USER_AGENT'];
$visitorpage=$_SERVER['REQUEST_URI'];
$sqlredir="SELECT * FROM tablename WHERE mid=$linkid";
$rdresult=mysql_query($sqlredir) or die(mysql_error());
$row=mysql_fetch_assoc($rdresult) or die(mysql_error());
$rdurl="Location: ".$row['mlink'];
header($rdurl);
mysql_free_result($rdresult);
mysql_free_result($result);
$goodbye=mysql_close($conn);
?>Scott