這是代碼。。。。<!doctype html><html><head><meta charset="utf-8"><title>注冊</title></head><body><form action="log_in.php" method="post"> <label for="">名 字:</label> <input type="text" name="user_name" maxlength="20"/><br/><br/> <label for="">學(xué) 號:</label> <input type="text" name="user_id" maxlength="9" /><br/><br/> <label for="">電話號碼:</label> <input type="text" name="user_phone" maxlength="11"/><br/><br/> <label for="">住 址:</label> <input type="text" name="user_address" maxlength="50"/><br/><br/> <input type="submit" value="注冊"><?php header('Content-Type:text/html;charset=utf-8'); //數(shù)據(jù)庫的服務(wù)器類型是mysql $dbms='mysql'; //數(shù)據(jù)庫服務(wù)器主機(jī)名、端口號、選擇的數(shù)據(jù)庫 $host='localhost'; $port='3306'; $dbname='book'; //用戶名和密碼 $user='root'; $pwd=null; $dsn="$dbms:host=$host;port=$port;dbname=$dbname;charset=utf8"; try{ //實(shí)例化PDO創(chuàng)建數(shù)據(jù)庫服務(wù)器連接 $pdo=new PDO($dsn,$user,$pwd); if($_SERVER['REQUEST_METHOD']=='post'){ //執(zhí)行SQL語句 $sql="insert into user valuses(null,:name,:id,:phone,:address)"; //生成預(yù)處理語句 $stmt=$pdo->prepare($sql); $name=$_POST['user_name']; $id=$_POST['user_id']; $phone=$_POST['usere_phone']; $address=$_POST['user_address']; $stmt->bindParam(":sid",$sid); $stmt->bindParam(":id",$id); $stmt->bindParam(":phone",$phone); $stmt->bindParam(":address",$address); } }catch(PDOExcption $e){ echo $e->getMessage().'<br>'; }?><br/><br/></body></html>
1 回答

林逸舟丶
TA貢獻(xiàn)124條經(jīng)驗 獲得超28個贊
其實(shí)不用特別在意對數(shù)據(jù)庫的操作。
先去學(xué)學(xué)MVC思想,
然后學(xué)習(xí)一下ThinkPHP框架(因為簡單,且有中文使用文檔)。
再回過頭來,你就知道為什么我會讓你這么做了。
記得采納答案。
添加回答
舉報
0/150
提交
取消