查看: 899|回复: 10
|
php & mysql (insert problem)
[复制链接]
|
|
为什么我的data没有自动insert去databases ???
anyone one know wht wrong??
here the coding
thks........
--------------------------------------------------------------------------
newadd.html
<html>
<head>
<title>New Page 1</title>
</head>
<body>
<form method="POST" action="bookadd.php">
<p> </p>
<p> <font color="#009933"> Category ID :</font> <select name="D1">
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=6>6
<option value=7>7
<option value=8>8
</select></p>
<p> <font color="#009933">Book ID :
<input type="text" name="T2" size="20"></font></p>
<p><font color="#009933"> Book Name :
<input type="text" name="T1" size="50"></font></p>
<p><font color="#009933"> Author :
<input type="text" name="T3" size="30"></font></p>
<p><font color="#009933"> Publisher:
<input type="text" name="T4" size="30"></font></p>
<p><font color="#009933"> ISBN :
<input type="text" name="T5" size="30"></font></p>
<p><font color="#009933"> Price (RM) : </font>
<input type="text" name="T6" size="30"></p>
<p> </p>
<p><input type="submit" value="Submit" name="B1"> <input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>
--------------------------------------------------------------------------
bookadd.php
<?php
mysql_connect("localhost", "root","1234");
mysql_select_db("spm");
$aa="
insert into book values (
null,'$D1','$T2','$T3','$T4','$T5','$T6','NULL','Unknown')";
mysql_query($aa);
header("location:..\admin.php");
?>
--------------------------------------------------------------------------
This is my database : book
book
(psn int auto_increment primary key,
categoryID int not null,
bookname char(50),
bookid char(8),
author char(30),
price int,
checked int,
description text);
[ 本帖最后由 html 于 26-8-2006 06:32 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 26-8-2006 06:23 PM
|
显示全部楼层
这是旧的 php... 几年前的方法...
现在... 你应该在 bookadd.php 里, 加上索取前一页 form variable 的 code.
$D1 = $_POST["D1"]; |
|
|
|
|
|
|
|
楼主 |
发表于 26-8-2006 06:41 PM
|
显示全部楼层
原帖由 goatstudio 于 26-8-2006 06:23 PM 发表
这是旧的 php... 几年前的方法...
现在... 你应该在 bookadd.php 里, 加上索取前一页 form variable 的 code.
$D1 = $_POST;
i change the code like below but still hv error........
Parse error: parse error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\program files\easyphp1-7\www\spm_projects\admin\add\bookadd.php on line 8
________________________________________________________________________
<?php
mysql_connect("localhost", "root","1234");
mysql_select_db("spm");
$aa="
insert into book values (
null,
$D1 = $_POST["D1"],
$T2 = $_POST["T2"],
$T3 = $_POST["T3"],
$T4 = $_POST["T4"],
$T5 = $_POST["T5"],
$T6 = $_POST["T6"],
'NULL','Unknown')";
mysql_query($aa);
header("location:..\admin.php");
?>
-------------------------------------------------------------------------
i using EasyPHP |
|
|
|
|
|
|
|
发表于 26-8-2006 09:27 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 26-8-2006 09:35 PM
|
显示全部楼层
error very clear
$aa="
insert into book values (
null,
$D1 = $_POST["D1"],
you had specify aa then again "D1" sure it will like that.
should change sample
null," . $_POST["D1"] . ", |
|
|
|
|
|
|
|
楼主 |
发表于 26-8-2006 10:21 PM
|
显示全部楼层
thanks... i really blur edi............. |
|
|
|
|
|
|
|
发表于 27-8-2006 02:19 AM
|
显示全部楼层
原帖由 html 于 26-8-2006 06:41 PM 发表
i change the code like below but still hv error........
Parse error: parse error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\program files\easyphp1-7\www ...
完全错误...
你不能 copy and paste, 要先了解呀...
<?php
mysql_connect("localhost", "root","1234");
mysql_select_db("spm");
$D1 = $_POST["D1"];
$T2 = $_POST["T2"];
$T3 = $_POST["T3"];
$T4 = $_POST["T4"];
$T5 = $_POST["T5"];
$T6 = $_POST["T6"];
$aa="
insert into book values (
null,'$D1','$T2','$T3','$T4','$T5','$T6','NULL','Unknown')";
mysql_query($aa);
header("location:..\admin.php");
?> |
|
|
|
|
|
|
|
楼主 |
发表于 27-8-2006 12:24 PM
|
显示全部楼层
原帖由 goatstudio 于 27-8-2006 02:19 AM 发表
完全错误...
你不能 copy and paste, 要先了解呀...
<?php
mysql_connect("localhost", "root","1234");
mysql_select_db("spm");
...
i already correct it and change it like below
however thanks very much
-------------------------------------------------------------------------
<?php
if(isset($D1) and isset($T1) and isset($T2) and isset($T3) and
isset($T4) and isset($T5) and isset($T6)){
$link_id = mysql_connect("localhost", "root","1234");
mysql_select_db("spm");
$str="
insert into book values (
'',
'$D1',
'$T1',
'$T2',
'$T3',
'$T4',
'$T5',
'$T6',
'NULL',
'Unknown')";
mysql_query($str,$link_id);
mysql_close($link_id);
}; |
|
|
|
|
|
|
|
发表于 28-8-2006 09:24 AM
|
显示全部楼层
原帖由 html 于 27-8-2006 12:24 PM 发表
i already correct it and change it like below
however thanks very much
-------------------------------------------------------------------------
<?php
if(isset($D1) and isset($T1 ...
这样是不够的...
你需要用类似 $_POST["D1"] 来索取资料. |
|
|
|
|
|
|
|
发表于 28-8-2006 09:33 AM
|
显示全部楼层
$d1 = $_POST["D1"];
先说说$D1。
D1是你的 textbox 的 name
like :
<INPUT size="25"name="D1">
然后呢是$d1
............
要如何说呢?
因该说 d1 等于 D1 把
[ 本帖最后由 红发 于 28-8-2006 09:34 AM 编辑 ] |
|
|
|
|
|
|
|
发表于 29-8-2006 01:26 AM
|
显示全部楼层
有点个人意见想分享。。
我个人认为还是把以下的stmt
$aa="insert into book values (
null,'$D1','$T2','$T3','$T4','$T5','$T6','NULL','Unknown')";
改成这样
$aa="insert into book(categoryID,bookname,bookid,author,price,checked,description)
values ('$D1','$T2','$T3','$T4','$T5','$T6','NULL','Unknown')";
这样的话。。。应该会好点吧。。 |
|
|
|
|
|
|
| |
本周最热论坛帖子
|