Page Stats
Visitor: 333
PHP MySql Insert
In PHP, we can execute a insert MySql statement to insert new record in the database table. First we need to create a MySql connection, write the sql insert query, execute the query to insert the record.
Example 1: Create a MySql connection, execute the query and insert new record in the MySql table.
<form action="" method=""> Address <input type="text" name="address" ><br> Name <input type="text" name="name" ><br> <input name="submit" type="submit" value="insert"> </form> <?php if(isset($_GET['submit'])) { $uid = mysqli_real_escape_string($conn, $_GET['address']); $conn = mysqli_connect("localhost", "root" , "", "student"); if($conn === false){ die("ERROR: Could not connect to database."); } $sql = "insert into student.add (Address, Name) values('".$uid."', '".$uname."')"; $result = mysqli_query($conn, $sql); if($result==1) echo "Record inserted"; else echo "Unable to insert record"; mysqli_close($conn); } ?>
Advertisement