[請益] Insert資料進入資料庫 Insert到空值
想請教版上的大大
小弟寫的php可以insert資料進入資料庫中
但每次重整網頁或第一次進入網頁
都會新增一筆全是空值的資料
想請問怎麼解決
以下是小弟寫的php
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("db_client", $con);
$sql="INSERT INTO tbl_client (name ,username, password)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
<html>
<body>
<form action="<?PHP $_PHP_SELF ?>" method="post">
Firstname: <input type="text" name="firstname" /><br/>
Lastname: <input type="text" name="lastname" /><br/>
Age: <input type="text" name="age" /><br/>
<input type="submit" name="btnSubmit" value="Insert" />
</form>
</body>
</html>
以上
拜託各位了
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.243.130.240
※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1454930196.A.375.html
推
02/08 19:54, , 1F
02/08 19:54, 1F
→
02/08 19:56, , 2F
02/08 19:56, 2F
→
02/08 19:57, , 3F
02/08 19:57, 3F
那該怎麼讓他判斷呢? 不好意思 小弟新手這方面不太懂
※ 編輯: daniel098962 (111.243.130.240), 02/08/2016 20:29:29
推
02/08 22:29, , 4F
02/08 22:29, 4F
推
02/09 00:03, , 5F
02/09 00:03, 5F
推
02/09 10:10, , 6F
02/09 10:10, 6F
推
02/09 16:56, , 7F
02/09 16:56, 7F
感謝,因為小弟這是第一次碰php 所以很多地方的意思還是不太了解
請問Din大 這句是加在$_POST["firstname"]這邊就好嗎?
※ 編輯: daniel098962 (39.12.150.23), 02/09/2016 22:36:44
推
02/10 00:14, , 8F
02/10 00:14, 8F
→
02/10 00:14, , 9F
02/10 00:14, 9F
G大,真的很感謝你,說明也很詳細,謝謝(飆淚)~
※ 編輯: daniel098962 (27.245.158.67), 02/10/2016 13:31:25