-1

My php script directs to a url depending on which submit button was pressed. However, when I run the test I'm getting an error saying line 4 contains an unexpected ":" but my line 4 is my header script with the url?

I'm confused because I have other scripts similar to this and they don't give me that error. Can anyone tell me what I'm missing, might be simple, I have been caught being simple before.

<?php
if ($_REQUEST['Dish1'] == 'Dish1')
{
header(“Location: http://blahblah”.urlencode($_POST[‘uid’]));
}
else if ($_REQUEST['Dish1'] == 'Dish2')
{
header(“Location: http://blahblah2”.urlencode($_POST[‘uid’]));
}
else if ($_REQUEST['Dish1'] == 'Dish3')
{
header(“Location: http://blahblah3”.urlencode($_POST[‘uid’]));
}
etc.....
?>

4 Answers 4

4

You are using curly quotes.

Replace all the “ ” and ‘ ’ to " and ' respectively.

4
  • +1 - I was just about to edit them in the question when I noticed that!
    – andrewsi
    Sep 5, 2012 at 20:34
  • told you I could be simple sometimes think the quotes changed when I copied something over from notepad and didn't remember to change them before copying again. Thank you all Sep 5, 2012 at 20:52
  • can anyone please explain why microsoft uses these wonky characters????? Nov 14, 2015 at 0:22
  • @ScottScooterWeidenkopf Probably because they think they "look nice". I mean from a purely aesthetic look, it is more obvious that starts a quote and ends it. This is probably one big reason why you don't use microsoft office to code in. They don't produce syntacticly correct text. Nov 14, 2015 at 1:00
2

You are using the wrong quotes... use "" instead of “”. Refer to Wikipedia, you must use typewriter quotes, not curly or inverted commas.

PD: Also PHP Parse error: syntax error, unexpected '.' on line 15 ; )

0

Replace you code with following

<?php

if ($_REQUEST['Dish1'] == 'Dish1')
{
header("Location: http://blahblah.urlencode".($_POST['uid']));
}
else if ($_REQUEST['Dish1'] == 'Dish2')
{
header("Location: http://blahblah2".urlencode($_POST['uid']));
}
else if ($_REQUEST['Dish1'] == 'Dish3')
{
header("Location: http://blahblah3".urlencode($_POST['uid']));
}

?>
0

Is it not much easier to write:

$lookup = array('Dish1' = > 'http://blba1', 'Dish2' = > 'http://blba2');

if( isset($lookup[$_REQUEST['Dish1']]))
  header("Location: " . $lookup[$_REQUEST['Dish1']]);

Not the answer you're looking for? Browse other questions tagged or ask your own question.