Reputation: 13
This code works, I believe. But it doesn't echo the confirmation or error.
<?php
require 'config.php';
if($_SERVER["REQUEST_METHOD"] == "POST"){
$servername="localhost";
$username="root";
$conn= mysql_connect($servername,$username)or die(mysql_error());
mysql_select_db("web", $conn);
$mypassword=$_POST['pwd'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$address=$_POST['address'];
$location=$_POST['location'];
$sqlsel="SELECT * FROM users WHERE username='$id' AND pwd='$mypassword' ";
$result=mysql_query($sqlsel,$conn) or die(mysql_error());
$count=mysql_num_rows($result);
if($count==1){
$sql="UPDATE users " .
"SET fname = '$fname',
lname = '$lname',
address = '$address',
location = '$location'" .
"WHERE pwd = '$mypassword'";
$res = mysql_query( $sql, $conn );
//IS THIS CORRECT TO REFRESH THE PAGE???
header("Location: edit.php?id=" . $id);
//IT WON'T ECHO....
echo 'Information updated.';
}
else {
//ALSO THIS ONE...
echo print "Invalid Password.";
}
mysql_close($conn);
}
?>
It seems to work on my other form but it won't work on this edit form.
How can I resolve this?
Upvotes: 0
Views: 216
Reputation: 1573
After header location, anything won't work. what you could do is
header("Location: edit.php?id=" . $id . "&msg=1");
then on edit.php just get $_GET["msg"] like
if isset($_GET["msg"])
echo 'Information updated.';
Upvotes: 2
Reputation: 413
when header location is declared it will redirect page ONLY when its the first php/html declared
anything after wont work or display
Upvotes: 0
Reputation: 46910
You have sent redirection headers, after that browser starts to redirect and doesnt echo. Remove the header call.
Comment out this part
//header("Location: edit.php?id=" . $id);
Also
echo print "Invalid Password.";
Should be
echo "Invalid Password.";
Upvotes: 1