INSERT INTO msg(title,contents,dates) VALUES ($title,$cons,now())

創(chuàng)新互聯(lián)公司成都企業(yè)網(wǎng)站建設(shè)服務(wù),提供成都做網(wǎng)站、成都網(wǎng)站制作網(wǎng)站開(kāi)發(fā),網(wǎng)站定制,建網(wǎng)站,網(wǎng)站搭建,網(wǎng)站設(shè)計(jì),響應(yīng)式網(wǎng)站設(shè)計(jì),網(wǎng)頁(yè)設(shè)計(jì)師打造企業(yè)風(fēng)格網(wǎng)站,提供周到的售前咨詢(xún)和貼心的售后服務(wù)。歡迎咨詢(xún)做網(wǎng)站需要多少錢(qián):18982081108
將字段名兩邊的單引號(hào)去掉就沒(méi)問(wèn)題了,親測(cè)成功!希望能幫到你。
親,你數(shù)據(jù)庫(kù)id設(shè)置成自動(dòng)生成,不用插入數(shù)據(jù)可了吧,我給你一段我寫(xiě)的注冊(cè),你看看,原理一樣,你改下sql語(yǔ)句插入就ok
?php
if($_POST["submit"]){
if(empty($_POST['member_user']))
echo "scriptalert('帳號(hào)不能為空');location='?tj=register';/script";
else if(empty($_POST['member_password']))
echo "scriptalert('密碼不能為空');location='?tj=register';/script";
else if($_POST['member_password']!=$_POST['pass'])
echo "scriptalert('兩次密碼不一樣');location='?tj=register';/script";
else if(!empty($_POST['member_qq'])!is_numeric($_POST['member_qq']))
echo "scriptalert('qq號(hào)必須全為數(shù)字');location='?tj=register';/script";
else if(!empty($_POST['member_phone'])!is_numeric($_POST['member_phone']))
echo "scriptalert('手機(jī)號(hào)碼必須全為數(shù)字');location='?tj=register';/script";
else if(!empty($_POST['member_email'])!ereg("([0-9a-zA-Z]+)([@])([0-9a-zA-Z]+)(.)([0-9a-zA-Z]+)",$_POST['member_email']))
echo "scriptalert('郵箱輸入不合法');location='?tj=register';/script";
else{
$_SESSION['member']=$_POST['member_user'];
$sql="insert into member values('','".$_POST['member_user']."','".$_POST['member_password']."','".$_POST['member_name']."','".$_POST['member_sex']."','".$_POST['member_qq']."','".$_POST['member_phone']."','".$_POST['member_email']."')";
$result=mysql_query($sql)or die(mysql_error());
if($result)
echo "scriptalert('恭喜你注冊(cè)成功,馬上進(jìn)入主頁(yè)面');location='member.php';/script";
else
{
echo "scriptalert('注冊(cè)失敗');location='index.php';/script";
mysql_close();
}
}
}
?
form id="theForm" name="theForm" method="post" action="" onSubmit="return chk(this)" runat="server" style="margin-bottom:0px;"
table width="350" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#B3B3B3"
tr
td colspan="2" align="center" bgcolor="#EBEBEB"會(huì)員注冊(cè) 以下打“*”為必填項(xiàng)/td
/tr
tr
td width="60" align="right" bgcolor="#FFFFFF"賬 號(hào):/td
td width="317" bgcolor="#FFFFFF"input name="member_user" type="text" id="member_user" size="20" maxlength="20" /
font color="#FF0000" */font(由數(shù)字或字母組成)/td
/tr
tr
td align="right" bgcolor="#FFFFFF"密 碼:/td
td bgcolor="#FFFFFF"input name="member_password" type="password" id="member_password" size="20" maxlength="20" /
font color="#FF0000" */font(由數(shù)字或字母組成)/td
/tr
tr
td align="right" bgcolor="#FFFFFF"確認(rèn)密碼:/td
td bgcolor="#FFFFFF"input name="pass" type="password" id="pass" size="20" /
font color="#FF0000" */font(再次輸入密碼)/td
/tr
tr
td align="right" bgcolor="#FFFFFF"真實(shí)姓名:/td
td bgcolor="#FFFFFF"input name="member_name" type="text" id="member_name" size="20" /
labelfont color="#FF0000"*/font/label/td
/tr
tr
td align="right" bgcolor="#FFFFFF"性 別:/td
td align="left" bgcolor="#FFFFFF"
input name="member_sex" type="radio" id="0" value="男" checked="checked" /
男
input type="radio" name="member_sex" value="女" id="1" /
女 /label/td
/tr
tr
td align="right" bgcolor="#FFFFFF"Q Q:/td
td bgcolor="#FFFFFF"input name="member_qq" type="text" id="member_qq" size="20"http://td
/tr
tr
td align="right" bgcolor="#FFFFFF"聯(lián)系方式:/td
td bgcolor="#FFFFFF"input name="member_phone" type="text" id="member_phone" size="20"http://td
/tr
tr
td align="right" bgcolor="#FFFFFF"電子郵箱:/td
td bgcolor="#FFFFFF"input name="member_email" type="text" id="member_email" size="20"http://td
/tr
tr
td colspan="2" align="center" bgcolor="#FFFFFF"input type="reset" name="button" id="button" value="重置表單" /
input type="submit" name="submit" id="submit" value="確定注冊(cè)" //td
/tr
/table
/form
$sql="INSERT
INTO
news(`id`,`title`,`dates`,`contents`)
VALUES
('','{$title}',now(),'{$con}')";
你的SQL語(yǔ)句有點(diǎn)問(wèn)題。還有SQL不分大小寫(xiě),但這樣寫(xiě)更清楚一些。
先確認(rèn)數(shù)據(jù)庫(kù)連接是正常的,然后echo
$sql
看看,數(shù)據(jù)是否正常,然后再寫(xiě)入庫(kù)。
出問(wèn)題了調(diào)試要步步試下來(lái),就知道問(wèn)題出在哪里了。
網(wǎng)站名稱(chēng):php插入數(shù)據(jù)庫(kù)不能用 php向數(shù)據(jù)庫(kù)添加數(shù)據(jù)失敗
文章位置:http://www.yijiale78.com/article18/ddocdgp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、品牌網(wǎng)站設(shè)計(jì)、移動(dòng)網(wǎng)站建設(shè)、網(wǎng)站策劃、定制開(kāi)發(fā)、軟件開(kāi)發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)