3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<!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 ($_SERVER["REQUEST_METHOD"] == "POST") { echo "Thank you for your registration...<br>"; echo "Your First Name: ".$fname."<br>"; echo "Your Last Name: ".$lname."<br>"; echo "Your E-mail: ".$mail."<br>"; echo "Your address: ".$add."<br>"; echo "Gender: ".$gender."<br>"; } ?>--> <?php /*if ($_SERVER["REQUEST_METHOD"] == "POST")*/ 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 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
<!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/5cJDM on line 22 <form method="POST" action="/in/5cJDM"> <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> <!-- Notice: Undefined index: REQUEST_METHOD in /in/5cJDM on line 129 --> </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/5cJDM on line 22 <form method="POST" action="/in/5cJDM"> <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> <!-- Notice: Undefined index: REQUEST_METHOD in /in/5cJDM on line 129 --> </body> </html>
Output for 4.3.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/5cJDM 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> <!-- Notice: Undefined index: REQUEST_METHOD in /in/5cJDM on line 129 --> </body> </html>