Home »
tips n trik
» Inserting data into mysql
Inserting data into mysql
Syntax |
|
"INSERT INTO table_name(column_name1, column_name2)VALUES('value1, 'value2')" ; |
|
Overview |
|
|
|
|
| Create table "test_mysql" |
|
CREATE TABLE `test_mysql` (
`id` int(4) NOT NULL auto_increment,
`name` varchar(65) NOT NULL default '',
`lastname` varchar(65) NOT NULL default '',
`email` varchar(65) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=0 ; |
|
|
|
|
| Create file insert.php |
|
View In Browser
|
############### Code <table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="insert_ac.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td colspan="3"><strong>Insert Data Into mySQL Database </strong></td>
</tr>
<tr>
<td width="71">Name</td>
<td width="6">:</td>
<td width="301"><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>Lastname</td>
<td>:</td>
<td><input name="lastname" type="text" id="lastname"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</td>
</tr>
</table> |
|
|
|
|
| Create file insert_ac.php |
|
Diagram
|
############### Code
<?php
$host="localhost";
$username="";
$password="";
$db_name="test";
$tbl_name="test_mysql";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$name=$_POST['name'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$sql="INSERT INTO $tbl_name(name, lastname, email)VALUES('$name', '$lastname', '$email')";
$result=mysql_query($sql);
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
mysql_close();
?>
sumber : |
|
Recommended Posts :
0 komentar:
Posting Komentar - Back to Content