The control should switch to another program when exiting in if using the php expression

I have 2 welcome.php and form.jsp programs. I am using tyring to insert values ​​into an SQL database using odbc through a custom form. I created a custom form using form.jsp. insert rows using welcome.php. while insertion does not insert duplicate values, so I check the conditions during the loop. when if statements work, they exit the program completely due to the exit () statement. after execution exit am becomes an empty page. but I need to stop in the user form or the control should go to form.jsp so that I get the user form again to enter data without specifying a 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>"; ?> 
+4
source share
3 answers

Using exit() stops processing the program. To send a user to another page with PHP, you can use the header() function with the "Location:" parameter:

 header('Location: form.jsp'); 

Note that you cannot output information (for example, using echo ), and then use the header function. All conclusion must be made on the page to which you submit them.

If you want to transmit information, for example, the send field, you can send it using the query string parameter, for example:

 header('Location: form.jsp?error=abc'); 

Your JSP page will display an error depending on what abc meant.

Alternatively, you can use sessions to transfer more complex information to another page. You can find more information about the sessions here .

+1
source

You can use output buffering and a header function.

 ob_start(); ... many lines of code ... header("Location: reload.php"); 
+1
source

You can also use javascript for this.

 window.location = "your location path where you want to redirect"; OR window.location.href = "your location path where you want to redirect"; 

I think this may also help you.

Thanks.

0
source

Source: https://habr.com/ru/post/1385277/


All Articles