Skip to content

Instantly share code, notes, and snippets.

@erinbush
Created Sep 20, 2012
Embed
What would you like to do?
PHP Form code
<?php
/* 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: ");
}
?>
<?php
/* Insert data from form submission */
$fname=$_POST['firstname'];
$lname=$_POST['lastname'];
$state=$_POST['state'];
$date=$_POST['date'];
$crime=$_POST['crime'];
$verdict=$_POST['verdict'];
$sentence=$_POST['sentence'];
$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";
?>
<?php
/* Close connection */
mysql_close($connection);
?>
@technosmarter

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