index.php(再新增下面語法)

<form id="form2" name="form2" method="post" action="insert.php">
name:<input type="text" name="name" id="name">
tel:<input type="text" name="tel" id="tel">
address:<input type="text" name="address" id="address">
<input type="submit" name="button" id="button" value="新增" />
</form>

 

insert.php

<?php
$hostname_restaurant = "localhost";//
$database_restaurant = "restaurant";//
$username_restaurant = "凱";//
$password_restaurant = "admin";//
$link = mysql_pconnect($hostname_restaurant, $username_restaurant, $password_restaurant) or trigger_error(mysql_error(),E_USER_ERROR);
//使用 mysql_pconnect()而不使用mysql_connect( ) 可以省下每次重新開啟資料庫連接的時間

mysql_query("set names utf8");//將資料庫設定為utf8編碼,防止中文亂碼


$sql ="INSERT INTO taipei_eat(name,tel,address) VALUES ('$_POST[name]','$_POST[tel]','$_POST[address]')";

$result = mysql_query($sql, $link) or die(mysql_error()); //執行sql語法

mysql_close($link); //關閉資料庫連結

header( "location:index.php"); //回index.php

?>

 

參考資料:http://muta1021.wordpress.com/category/php/

相关文章