PHP HTML warning field on successful registration

I have a registration form in html and php code that connects to the database. Now, if the registration was successful and added to the database, how can I warn the user that he is successful with a pop-up window?

The html code is just simple form codes, so the php code is:

<?php if(isset($_POST['submit'])){ $fname = $_POST['firstname']; $lname = $_POST['lastname']; $mname = $_POST['middlename']; $birthday = $_POST['year'] . '/' . $_POST['month'] . '/' . $_POST['day']; $sex = $_POST['sex']; $age = $_POST['age']; $address = $_POST['address']; $telephone = $_POST['telephone']; $occupation = $_POST['occupation']; $telephone = $_POST['telephone']; $cfname = $_POST['contactfirstname']; $clname = $_POST['contactlastname']; mysql_connect('localhost', 'root', ''); mysql_select_db('HMIS'); $query = "INSERT INTO `patientrecords` VALUES('','$lname','$fname','$mname','$birthday','$sex','$address','$telephone','$occupation','$clname','$cfname')"; if(mysql_query($query)){ echo "Registered"; }else{ echo "Error!". mysql_error(); } } ?> 

I can make a javascript warning window only when I click on a specific button. But in PHP code you don’t need a button .. so .. how do you do it?

0
source share
5 answers

Try it, it should work

 if(success) { echo "<script type=\"text/javascript\">". "alert('success');". "</script>"; } 
+8
source

try this, it will help and redirect to another page:

 if($result){ echo ("<SCRIPT LANGUAGE='JavaScript'> window.alert('Succesfully Registered') window.location.href='../index.php'; </SCRIPT>"); } 
+1
source

You cannot directly launch a pop-up device with PHP, as it is a server language.

However, you can respond to the html containing javascript to display the popup, but this is a pretty hacky solution.

Instead, you should take a look at using ajax for something like this.

Also, as @itachi said, do not use msql_ * instead, use PDO and make sure you bind your parameters, as you can have serious security consequences without doing this.

0
source
 if(mysql_query($query)){ $redirectUrl = 'YOUR URL'; echo '<script type="application/javascript">alert("Registered"); window.location.href = "'.$redirectUrl.'";</script>'; }else{ echo "Error!". mysql_error(); //Remove Below comment if you want to also popup an alert on error /**echo '<script type="application/javascript">alert("Error! '.mysql_error().'");</script>';*/ } 
0
source

Try this, you will see a pop-up window with your success message, click Edit on the form page.

 <form method=post action="whatever.php" onsubmit="window.open('','my_form_target', 'width=300,height=200', true); this.target='my_form_target';"> 
0
source

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


All Articles