0

Hi

Im having a go at this, but not good on the php thing, thats why im hoping you can help.

I am trying to set up a jump script from one I have used for 1 or 2 urls, now I have a database of around 500000 lines, each one has an id field and a link field to jump to. I can send the info for the function but cant get it to add the field from the database. This is the code I have got so far.

<?php
$con = mysql_connect("localhost","blar","blar");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("blar", $con);
$m = $_GET['m'];
ob_start();
$query = "SELECT `ID`, 'Link' FROM TABLE where `ID` ='$m' LIMIT 1"; 
$result = mysql_query($query) or die(mysql_error());
if ($m == "['ID']"){$link = "['Link']";}
   echo "sending to page now";
header("Location: $link");
ob_flush();
die();
?>

the page is sending the m=id and the page "sending to page now comes" up but no redirect occurs?
Hope someone can help
Thanks in advance

2
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by mpc123
0

After line 12 you need to $row = mysql_fetch_array($result); If $row is false then no record is found, else you can use $row['Link']. Note that you cannot output anything if you want to use header. (Remove line 17.)

0

Hi

Thanks for you quick reply, I have added that line and added the $row yet I get this error
unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

Can you help?

0
<?php
$con = mysql_connect("localhost","blar","blar");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("blar", $con);
$m = $_GET['m'];
ob_start();
$query = "SELECT `ID`, 'Link' FROM TABLE where `ID` ='$m' LIMIT 1"; 
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
if ($m == "$row['ID']"){$link = "$row['Link']";}
   echo "sending you to new page";
header("Location: $link");
ob_flush();
?>
0

Line 11, single quotes around Link should be backticks. Line 14, remove all double quotes. But what line do you get your error? Always paste the full error message with the problematic code snippet.

Edited by pritaeas

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.