Tina
Tina

Reputation: 312

php page not redirecting

In the code below i am able to update the database,but it not redirecting the to page given in header location,its refreshing and showing the same page itself,i copied the code from other which was working well in updating the db and redirecting

  <?php

if (isset($_POST['submit']))
 { 
 // get form data, making sure it is valid
 $firstname = mysql_real_escape_string(htmlspecialchars($_POST['firstname']));

 $link = mysql_connect('www.xxxxxxx.co.uk', 'xxxxxx', 'axxxxxd');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

mysql_select_db("web39-sdasdasd", $link);
mysql_query("INSERT learning_outcome SET topic='$firstname'")
 or die(mysql_error()); 

 header('Location: http://www.xxxxxx.co.uk/NottTest/viewlearnpc.php?succmsg=UPDATE SUCCESSFULL'); 
 }

 else

 echo "";

 ?>

Upvotes: 0

Views: 287

Answers (3)

ksealey
ksealey

Reputation: 1738

Remove all blank lines and indentation spaces in the php script.

Upvotes: 0

Idrees Khan
Idrees Khan

Reputation: 7752

Quesry is INSERT INTO learning_outcome(col1, col2) VALUES ("value1", "value2") not INSERT learning_outcome

$result = mysql_query("INSERT INTO learning_outcome SET topic='$firstname'") 

first, check if query is executed sucessfully then redirect;

if($result)
{
   header('Location: http://www.xxxxxx.co.uk/NottTest/viewlearnpc.php?succmsg=UPDATE SUCCESSFULL');
}
else
{
   die("query isn't executed, error");
}

You can use set col1 = value only for updating.

Upvotes: 0

user1467418
user1467418

Reputation:

Remove space/indentation from:

  <?php

You should make sure that you do not echo or output anything before header command.

Upvotes: 3

Related Questions