3v4l.org

run code in 300+ PHP versions simultaneously
<!DOCTYPE html> <html> <head> <style> body{ border:10px solid black; border-style:groove; padding:10px; margin-left:300px; margin-right:300px; } .error{color:red} </style> </head> <body> <?php $fnameerr = $lnameerr = $mailerr = $passerr = $cpasserr = $gendererr = ""; $fname = $lname = $mail = $pass = $cpass = $gender = $file = $add = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if(empty($_POST["fname"])){ $fnameerr = "Please enter your first name";} else{ $fname = test($_POST["fname"]); if(!preg_match("/^[a-zA-Z ]*$/",$fname)) $fnameerr = "Only letters and white spaces are allowed"; } if(empty($_POST["lname"])){ $lnameerr = "Please enter your last name";} else{ $lname = test($_POST["lname"]); if(!preg_match("/^[a-zA-Z ]*$/",$lname)) $lnameerr = "Only letters and white spaces are allowed"; } if(empty($_POST["mail"])){ $mailerr = "Please enter your mail id";} else{ $mail = test($_POST["mail"]); if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$mail)) $mailerr = "Please enter a valid mail id"; } if(empty($_POST["pass"])){ $passerr = "Please enter your password";} if(empty($_POST["cpass"])){ $cpasserr = "Please confirm your password";} else{ if($_POST["pass"] != $_POST["cpass"]){ $passerr = "Please enter your password"; $cpasserr="Password is not matching";} } if(empty($_POST["add"])){ $add = "";} else{ $add = test($_POST["add"]);} if (empty($_POST["gender"])) { $gendererr = "Please choose your gender";} else { $gender = test($_POST["gender"]);} } function test($data) { $data = trim($data); $data = stripslashes($data); return $data; } ?> <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <h3><center><u>User Registration Page</u><center></h3> <h5 class="error">* Required fields...</h5> First Name: <input type="text" name="fname"> <span class="error">*<?php echo $fnameerr; ?></span> <br> <br> Last Nmae: <input type="text" name="lname"> <span class="error">*<?php echo $lnameerr; ?></span> <br> <br> E-mail: <input type="text" name="mail"> <span class="error">*<?php echo $mailerr; ?></span> <br> <br> Password: <input type="password" name="pass"> <span class="error">*<?php echo $passerr; ?></span> <br> <br> Confirm password: <input type="password" name="cpass"> <span class="error">*<?php echo $cpasserr; ?></span> <br> <br> Address: <textarea class="xyz" name="add" rows="10" cols="50"></textarea> <br> <br> Gender: <input type="radio" name="gender" value="Male">Male <input type="radio" name="gender" value="Female">Female <span class="error">*<?php echo $gendererr; ?></span> <br> <br> <center><input type="submit" name="sub" value="Submit"></center> <br> </form> <?php if(isset($_POST['sub'])) { $con = mysqli_connect("localhost","root","","phptask"); if(mysqli_connect_errno()){ echo "Failed to connect to MySql: ".mysqli_connect_error(); } $fname = mysqli_real_escape_string($con,$_POST['fname']); $lname = mysqli_real_escape_string($con,$_POST['lname']); $mail = mysqli_real_escape_string($con,$_POST['mail']); $pass = mysqli_real_escape_string($con,$_POST['pass']); $add = mysqli_real_escape_string($con,$_POST['add']); $gender = mysqli_real_escape_string($con,$_POST['gender']); $sql = "INSERT INTO USER_DETAIL(firstname,lastname,email,password,address,gender)VALUES('$fname','$lname','$mail','$pass','$add','$gender')"; if(!mysqli_query($con,$sql)){ die("Error: ".mysqli_error($con)); } echo "Thank you for your registration.<br>"; echo "Your data has been submitted.<br>"; } ?> </body> </html>
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
<!DOCTYPE html> <html> <head> <style> body{ border:10px solid black; border-style:groove; padding:10px; margin-left:300px; margin-right:300px; } .error{color:red} </style> </head> <body> Warning: Undefined array key "REQUEST_METHOD" in /in/boufl on line 22 <form method="POST" action="/in/boufl"> <h3><center><u>User Registration Page</u><center></h3> <h5 class="error">* Required fields...</h5> First Name: <input type="text" name="fname"> <span class="error">*</span> <br> <br> Last Nmae: <input type="text" name="lname"> <span class="error">*</span> <br> <br> E-mail: <input type="text" name="mail"> <span class="error">*</span> <br> <br> Password: <input type="password" name="pass"> <span class="error">*</span> <br> <br> Confirm password: <input type="password" name="cpass"> <span class="error">*</span> <br> <br> Address: <textarea class="xyz" name="add" rows="10" cols="50"></textarea> <br> <br> Gender: <input type="radio" name="gender" value="Male">Male <input type="radio" name="gender" value="Female">Female <span class="error">*</span> <br> <br> <center><input type="submit" name="sub" value="Submit"></center> <br> </form> </body> </html>
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
<!DOCTYPE html> <html> <head> <style> body{ border:10px solid black; border-style:groove; padding:10px; margin-left:300px; margin-right:300px; } .error{color:red} </style> </head> <body> Notice: Undefined index: REQUEST_METHOD in /in/boufl on line 22 <form method="POST" action="/in/boufl"> <h3><center><u>User Registration Page</u><center></h3> <h5 class="error">* Required fields...</h5> First Name: <input type="text" name="fname"> <span class="error">*</span> <br> <br> Last Nmae: <input type="text" name="lname"> <span class="error">*</span> <br> <br> E-mail: <input type="text" name="mail"> <span class="error">*</span> <br> <br> Password: <input type="password" name="pass"> <span class="error">*</span> <br> <br> Confirm password: <input type="password" name="cpass"> <span class="error">*</span> <br> <br> Address: <textarea class="xyz" name="add" rows="10" cols="50"></textarea> <br> <br> Gender: <input type="radio" name="gender" value="Male">Male <input type="radio" name="gender" value="Female">Female <span class="error">*</span> <br> <br> <center><input type="submit" name="sub" value="Submit"></center> <br> </form> </body> </html>
Output for 7.3.32 - 7.3.33
<!DOCTYPE html> <html> <head> <style> body{ border:10px solid black; border-style:groove; padding:10px; margin-left:300px; margin-right:300px; } .error{color:red} </style> </head> <body> <form method="POST" action="/in/boufl"> <h3><center><u>User Registration Page</u><center></h3> <h5 class="error">* Required fields...</h5> First Name: <input type="text" name="fname"> <span class="error">*</span> <br> <br> Last Nmae: <input type="text" name="lname"> <span class="error">*</span> <br> <br> E-mail: <input type="text" name="mail"> <span class="error">*</span> <br> <br> Password: <input type="password" name="pass"> <span class="error">*</span> <br> <br> Confirm password: <input type="password" name="cpass"> <span class="error">*</span> <br> <br> Address: <textarea class="xyz" name="add" rows="10" cols="50"></textarea> <br> <br> Gender: <input type="radio" name="gender" value="Male">Male <input type="radio" name="gender" value="Female">Female <span class="error">*</span> <br> <br> <center><input type="submit" name="sub" value="Submit"></center> <br> </form> </body> </html>
Output for 5.2.3 - 5.2.17
<!DOCTYPE html> <html> <head> <style> body{ border:10px solid black; border-style:groove; padding:10px; margin-left:300px; margin-right:300px; } .error{color:red} </style> </head> <body> Notice: Undefined index: REQUEST_METHOD in /in/boufl on line 22 <form method="POST" action="/in/boufl"> <h3><center><u>User Registration Page</u><center></h3> <h5 class="error">* Required fields...</h5> First Name: <input type="text" name="fname"> <span class="error">*</span> <br> <br> Last Nmae: <input type="text" name="lname"> <span class="error">*</span> <br> <br> E-mail: <input type="text" name="mail"> <span class="error">*</span> <br> <br> Password: <input type="password" name="pass"> <span class="error">*</span> <br> <br> Confirm password: <input type="password" name="cpass"> <span class="error">*</span> <br> <br> Address: <textarea class="xyz" name="add" rows="10" cols="50"></textarea> <br> <br> Gender: <input type="radio" name="gender" value="Male">Male <input type="radio" name="gender" value="Female">Female <span class="error">*</span> <br> <br> <center><input type="submit" name="sub" value="Submit"></center> <br> </form> </body> </html>
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.2
<!DOCTYPE html> <html> <head> <style> body{ border:10px solid black; border-style:groove; padding:10px; margin-left:300px; margin-right:300px; } .error{color:red} </style> </head> <body> Notice: Undefined index: REQUEST_METHOD in /in/boufl on line 22 <form method="POST" action=""> <h3><center><u>User Registration Page</u><center></h3> <h5 class="error">* Required fields...</h5> First Name: <input type="text" name="fname"> <span class="error">*</span> <br> <br> Last Nmae: <input type="text" name="lname"> <span class="error">*</span> <br> <br> E-mail: <input type="text" name="mail"> <span class="error">*</span> <br> <br> Password: <input type="password" name="pass"> <span class="error">*</span> <br> <br> Confirm password: <input type="password" name="cpass"> <span class="error">*</span> <br> <br> Address: <textarea class="xyz" name="add" rows="10" cols="50"></textarea> <br> <br> Gender: <input type="radio" name="gender" value="Male">Male <input type="radio" name="gender" value="Female">Female <span class="error">*</span> <br> <br> <center><input type="submit" name="sub" value="Submit"></center> <br> </form> </body> </html>

preferences:
344.08 ms | 405 KiB | 459 Q