mercredi 4 mai 2016

PHP - Web Form submit button not working

I am creating a form to connect to a database using PHP. I have the form semi-functional but when I'm trying to test it by pressing the submit button, it says file not found on the webpage.

Here is code for default.php:

<!DOCTYPE HTML> <html> <head>

<title>PHP FORM - 08246 ACW PART 2</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://ift.tt/1RLAc2h"> <style> .error {color:
#FF0000;} </style> </head> <body>  

<ul class="w3-navbar w3-black w3">   <li><a href="default.php">Home</a></li>   <li><a href="changelocationtostaffmember.php">Change location to staff member</a></li>   <li><a href="currentlocationofallstaff.php">Current location of all staff</a></li>   <li><a href="editpersonaldetailsofstaffmember.php">Edit personal details of staff member</a></li>   <li><a href="listalllocationsandshowlistofpeopleinselectedlocation.php">List all locations and show list of people in selected location</a></li>   <li><a href="staffmemberandlistlocationsforlast24hours.php">Staff member and list locations for last24 hours</a></li> </ul>

<div class="w3-container"> <h2> Web Form </h2> </div>

<div class="w3-container">  <?php // defining the variables and setting them to empty values $first_nameErr = $SurnameErr = $usernameErr = $passwordErr = $previous_LocationErr = $current_LocationErr = $dateErr = $timeErr = $dErr = $tErr = ""; $first_name = $Surname = $username = $password = $previous_Location = $current_Location = $date = $time = $dErr = $tErr = "";

//----validation----

//first name if($_SERVER["REQUEST_METHOD"] == "POST"){ if(empty($_POST["first_name"])){ $first_nameErr = "First Name is required"; }else{ $first_name = test_input($_POST["first_name"]); //validation checking if(!preg_match("/^[a-zA-Z ]*$/",$first_name)){ $first_nameErr = "Please enter only letter and white space";  } }

//surname if($_SERVER["REQUEST_METHOD"]=="POST"){ if(empty($_POST["Surname"])){ $SurnameErr="Surname is required"; }else{ $Surname=test_input($_POST["Surname"]); //validation checking if(preg_match("/^[a-zA-Z ]*$/",$Surname)){ $SurnameErr = " Please enter only letters and white spaces"; } }

//date and time date_default_timezone_set('UTC');

$d = str_replace('/',',', '03/05/2016'); $t = str_replace(':',',', '13:38'); $date = $t.',0,'.$d; $fulldate = explode(',',$date); echo '<br>'; $h = $fulldate[0]; $i = $fulldate[1]; $s = $fulldate[2]; $m = $fulldate[3]; $d = $fulldate[4]; $y = $fulldate[5];

echo date("h-i-s-M-d-Y",mktime($h,$i,$s,$m,$d,$y))."<br>"; echo strtotime ("03/05/2016 13:38");

function test_input($data){ $data=trim($data); $data=stripslashes($data); $data=hmtlspecialchars($data); return $data; } ?>

<?php//database
#server info
#$servername = "SQL2008.net.dcs.hull.ac.uk";
#$username = "ADIR\463142";//userid
#$dbname = "rde_463132"; $servername = "SQL2008.net.dcs.hull.ac.uk"; $username = "username"; $myDB = "examples"; $myLocation = "location";

// Create connection $conn = new mysqli($servername, $username, $myLocation); // Check connection if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error); } 

// Create database $sql = "CREATE DATABASE myDB"; if ($conn->query($sql) === TRUE) {
    echo "Database created successfully";   } else {
    echo "Error creating database: " . $conn->error;    }

$conn->close(); ?>

<p><span class="error">* are required field.</span></p> <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> First Name: <input type="text" name="first_name"><br> <span class="error">* <?php echo $First_nameErr;?></span> <br> Surname: <input type="text" name="Surname"><br> <span class="error">* <?php echo $SurnameErr;?></span> <br> Username: <input type="text" name="username"><br> <span class="error">* <?php echo $username;?></span> <br> Current Location: <input type="text" name="current_Location"><br> <span class="error">* <?php echo $current_Location;?></span> <br> Date: <input type="text" name="date"><br> <span class="error">* <?php echo $date;?></span> <br> Time: <input type="text" name="time"><br> <span class="error">* <?php echo $time;?></span> <br>

<input type="submit" name="submit" value="Submit"> </form>

</div> </body> </html>

I am new to this language and still learning. Any help or advice would be greatly appreciated.

Thank you




Aucun commentaire:

Enregistrer un commentaire