diff options
Diffstat (limited to 'Lab03/insert.php')
-rw-r--r-- | Lab03/insert.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Lab03/insert.php b/Lab03/insert.php new file mode 100644 index 0000000..a7efb70 --- /dev/null +++ b/Lab03/insert.php @@ -0,0 +1,42 @@ +<?php + +$servername = "localhost"; +$username = "db_user"; +$password = "password123"; +$dbname = "regform"; + +// Create connection +$conn = new mysqli($servername, + $username, $password, $dbname); + +// Check connection +if ($conn->connect_error) { + die("Connection failed: " + . $conn->connect_error); +} + +$fname = $_REQUEST['fname']; +$lname = $_REQUEST['lname']; +$gender = $_REQUEST['gender']; +$regno = $_REQUEST['regno']; +$phone = $_REQUEST['phone']; +$email = $_REQUEST['email']; +$department = $_REQUEST['department']; + +$sql = "INSERT INTO $dbname VALUES ('$fname','$lname','$gender','$regno','$email',$department)"; + +if(mysqli_query($conn, $sql)){ + echo "<h3>data stored in a database successfully." + . " Please browse your localhost php my admin" + . " to view the updated data</h3>"; + + echo nl2br("\n$first_name\n $last_name\n " + . "$gender\n $address\n $email"); +} else{ + echo "ERROR: Could not insert the data values $sql. " + . mysqli_error($conn); +} + +// Close connection +mysqli_close($conn); +?>
\ No newline at end of file |