i have 2 programs welcome.php and form.jsp. i am tyring to insert values into SQL database using odbc through user form. i have created a userform using form.jsp. inserting rows using welcome.php. while insertion am not inserting duplicate values so that am checking conditions in while loop. when the if statements are working, it’s completely come out from the program due to exit() statement. after execution of exit am getting blank page. but i need to stayback to the user form or the control should go to form.jsp so that again i should get the user form to enter the details without giving blank page.how can i do this?
$query1="select * from company";
$result1 = odbc_exec($connect, $query1);
while(odbc_fetch_row($result1)){
$compname[$index] = odbc_result($result1, 1);
$empname[$index] = odbc_result($result1, 2);
if($compname[$index]==$_POST['cname'])
{
echo "<script> alert(\"compname Exists\") </script>";
exit();
//exit("<script> alert(\"compname Exists\") </script>");
}
if($empname[$index]==$_POST['ename'])
{
echo "<script> alert(\"empname Exists\") </script>";
exit();
}
}
$query=("INSERT INTO dbo.urllink(cname,ename) VALUES ('$_POST[cname]','$_POST[ename]') ");
$result = odbc_exec($connect, $query);
echo "<script> alert(\"Row Inserted\") </script>";
?>
Using
exit()stops the processing of the program. To send the user to another page from PHP, you can use theheader()function, with the ‘Location: ‘ parameter:Note that you cannot output information (using
echofor example) and then use theheaderfunction. All output will need to be done by the page your sending them to.If you want to pass information, like a submitted field exists, you can send it using a query string parameter, for example:
Your JSP page would then display an error depending on what
abcmeant.Alternatively, you can use sessions to pass more complex information to another page.
You can find more info on sessions here.