Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions E-Commerce Full Website Using PHP/Add.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "", "student_db");

// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}

// Escape user inputs for security
$first_name = mysqli_real_escape_string($link, $_REQUEST['fname']);
$last_name = mysqli_real_escape_string($link, $_REQUEST['lname']);
$branch = mysqli_real_escape_string($link, $_REQUEST['branch']);
$year = mysqli_real_escape_string($link, $_REQUEST['year']);
// Attempt insert query execution
$sql = "INSERT INTO stud_info (fname, lname, branch,year) VALUES ('$first_name', '$last_name', '$branch','$year')";
if(mysqli_query($link, $sql)){
echo "Records added successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}

// Close connection
mysqli_close($link);
?>