Skip to content

Instantly share code, notes, and snippets.

Created Sep 20, 2012
What would you like to do?
PHP Form code
/* Create database connection */
$connection = mysql_connect("localhost", "db", "pw");
if (!$connection) {
die("Database connection failed: ");
/* Select a database */
$db_select = mysql_select_db("szecetl_crimetest",$connection);
if (!$db_select) {
die("Database selection failed: ");
/* Insert data from form submission */
$sql="INSERT INTO crimeuserinput (firstname, lastname, state, date, crime, verdict, sentence)
VALUES ('".$fname."', '".$lname."', '".$state."', '".$date."', '".$crime."', '".$verdict."', '".$sentence."')";
mysql_query($sql) or die("Error: " . mysql_error());
echo "1 record added";
/* Close connection */

This comment has been minimized.

Copy link

@technosmarter technosmarter commented Aug 21, 2018

Great solution for Sign up /insert data into the database. Here a small and complete solution with a demo ,
<?php $cser=mysqli_connect("localhost","root","","test"); if(isset($_POST['submit'])) { $name = $_POST['name']; $gender = $_POST['ab']; $dob = $_POST['dob']; $email = $_POST['email']; $number = $_POST['number']; $password = $_POST['password']; $result = mysqli_query($cser,"insert into student values('','$name','$gender','$dob','$email','$number','$password')"); if($result) { echo "Registration Successfully"; } else{ echo "failed:"; } } ?>

Insert/Signup Demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment