Add record to my_database/my_table
<html>
<body>
<?php
$self = $_SERVER['PHP_SELF'];
$id = $_POST['id'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
?>
<form action="<?php echo( $self ); ?>" method="post">
ID: <input type="text" name="id" size="3">
First Name: <input type="text" name="fname" size="8">
Last Name: <input type="text" name="lname" size="8"><br>
<input type="submit" value="Submit">
</form>
<?php
if( $id and $fname and $lname){
$conn=@mysql_connect( "localhost", "userName", "password" ) or die( "Err:Conn" );
$rs = @mysql_select_db( "my_database", $conn) or die( "Err:Db" );
$sql = "insert into my_table ( id, first_name, last_name ) values ( $id, \"$fname\", \"$lname\" )";
$rs = mysql_query( $sql, $conn );
if( $rs ){
echo( "Record added:$id $fname $lname" );
}
}
?>
</body></html>
Related examples in the same category