phpnewbie123 phpnewbie123 - 27 days ago 8
PHP Question

Click the button, save the data and go to next php page

I don't know what is the problem. After i click the button, it only the data into database but will not go to next php page. Help me find out what is problems. Thank you.

if(isset($_POST['btnSubmit'])){
$AddMCQ = "INSERT INTO tblmc(Name,FromDate,ToDate,Reason) VALUES('".strtoupper($_POST['txtName'])."','".$_POST['txtFrom']."','".$_POST['txtTo']."','".strtoupper($_POST['txtReason'])."')";
$AddMCResult = mysql_query($AddMCQ,$link);
header('Location: mcreport.php');

if($AddMCResult)
echo "<script>alert('Record Added.');</script>";

}
//button
<input type="submit" name="btnSubmit" id="btnSubmit" value="Submit"/>

Answer

Try this

<?php
     if(isset($_POST['btnSubmit']))
{

        $txtName=$_POST['txtName'];
        $txtFrom=$_POST['txtFrom'];
        $txtTo=$_POST['txtTo'];
        $txtReason=$_POST['txtReason'];
        $AddMCQ = "INSERT INTO tblmc(Name,FromDate,ToDate,Reason) VALUES('$txtName','$txtFrom','$txtTo','$txtReason')";
        $AddMCResult = mysql_query($AddMCQ,$link);
        if($AddMCResult)
        {
               echo "<script language=\"JavaScript\">\n";
        echo "alert('Record Added.');\n";
        echo "window.location='mcreport.php'";
        echo "</script>";
        }
        }
?>