查看: 743|回复: 19
|
PHP problem
[复制链接]
|
|
why the update function cannot work...
can anyone help me check ..
------------------------------------------------------------------------
.
.
.
echo"<form method=post action=new0.php>";
echo"<table width=70% border=1>";
echo"<tr><td><font color=#006600>BookName</font><td><font color=#006600>BookID</font><td><font color=#006600>Price per Item</font><td><font color=#006600>Amount</font></tr>";
while(list($b0,$b1,$b2,$b3)=mysql_fetch_row($dd)){
echo"
<tr>
<td>$b0</td>
<td><input type=text name=c0 value=$b1></td>
<td>RM$b2</td>
<td><input type=text name=c1 value=$b3></td>
</tr>
";
}
echo"</table>";
echo"<input type=submit value=update>";
echo"</form>";
--------------------------------------------------------------------------
<?php
mysql_connect("localhost","root","1234");
mysql_select_db("spm");
$c1 = $_GET['c1'];
$c0 = $_GET['c0'];
$aa="update book set
quantity=quantity - '".$c1."'
where bookid = '".$c0."'";
$dd=mysql_query($aa);
?>
[ 本帖最后由 html 于 10-9-2006 10:24 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 10-9-2006 06:52 PM
|
显示全部楼层
echo"<form method=post action=new0.php>";
可以知道一下为何是new().php
还有
$c1 = $_GET['c1'];
$c0 = $_GET['c0'];
$_GET是拿url address的
你因该用$_POST才对 |
|
|
|
|
|
|
|
楼主 |
发表于 10-9-2006 10:23 PM
|
显示全部楼层
原帖由 红发 于 10-9-2006 06:52 PM 发表
echo"<form method=post action=new0.php>";
可以知道一下为何是new().php
还有
$c1 = $_GET;
$c0 = $_GET;
$_GET是拿url address的
你因该用$_POST才对
action=new0.php // not new().php
$GET , I HAD CHANGED TO POST...
actually this code no problem ... but not want i wanted ( my problem is this code only take the last value of $b3 and update into database.. if have more than one value of $b3 .. the pervious was not update)
anyone can help me change the code ... thk |
|
|
|
|
|
|
|
发表于 12-9-2006 03:13 PM
|
显示全部楼层
cos u only pass the final value of $b3 to next page.
cos browser will only pass 1 value with to next page if all the data share the same name.
<input name=aa value=a>
<input name=aa value=b>
<input name=aa value=c>
<input name=aa value=d>
browerser only pass name=aa value=d to next page only.
maybe array can fix the problem, but i never try it b4.
ps,firefox canot type chinese,sorry
[ 本帖最后由 XxX_hunter 于 12-9-2006 03:15 PM 编辑 ] |
|
|
|
|
|
|
|
楼主 |
发表于 12-9-2006 05:14 PM
|
显示全部楼层
原帖由 XxX_hunter 于 12-9-2006 03:13 PM 发表
cos u only pass the final value of $b3 to next page.
cos browser will only pass 1 value with to next page if all the data share the same name.
<input name=aa value=a>
<input name=aa ...
ya i know.. array can fix this problem but how to write the coding
i had try many time still cannot.
anyone can help me .... (this is the final problem in my system)
pls......... |
|
|
|
|
|
|
|
发表于 12-9-2006 06:00 PM
|
显示全部楼层
try this
-------test1.php------------------------
<form action="test2.php" method="post">
<tr>
<td><input type=text name="c1[]" value="1"></td>
<td><input type=text name="c1[]" value="2"></td>
<td><input type=text name="c1[]" value="3"></td>
</tr>
<input type="submit">
</form>
----------test2.php-----------
<?
echo $_POST['c1'][0];
echo $_POST['c1'][1];
echo $_POST['c1'][2];
?>
------------------------------------------
get the idea?
then turn to loop |
|
|
|
|
|
|
|
楼主 |
发表于 12-9-2006 07:33 PM
|
显示全部楼层
原帖由 XxX_hunter 于 12-9-2006 06:00 PM 发表
try this
-------test1.php------------------------
<form action="test2.php" method="post">
<tr>
<td><input type=text name="c1[]& ...
that is the problem dunno how to turn to loop... (blur ....) |
|
|
|
|
|
|
|
楼主 |
发表于 12-9-2006 07:38 PM
|
显示全部楼层
my problem is here (i think)
$c1 = $_POST['c1']['a'];
$c0 = $_POST['c0'];
for($a=0;$a<=$c1;$a++)
{
$aa="update book set
quantity=quantity - '".$c1."'
where bookid = '".$c0."'";
$dd=mysql_query($aa);}
?>
i oso dunno what i was coding |
|
|
|
|
|
|
|
楼主 |
发表于 12-9-2006 10:58 PM
|
显示全部楼层
i had change to like this (still cannot fix the problem)
$num=count($c1);
$c1[] = $_POST['c1'];
$c0 = $_POST['c0'];
for($i=0;$i<=$num;$i++)
{
$aa="update book set
quantity=quantity - '".$c1[$i]."'
where bookid = '".$c0."'";
mysql_query($aa);
}
?>
[ 本帖最后由 html 于 12-9-2006 11:01 PM 编辑 ] |
|
|
|
|
|
|
|
发表于 13-9-2006 02:38 AM
|
显示全部楼层
no sure work or not
for ($i=0;$i<sizeof($c1)-1;$i++)
{
$aa="update book set quantity=quantity-'".$_post['$c1'] where bookid= '". $_post['$c0'] "'";
mysql_query($aa);
} |
|
|
|
|
|
|
|
楼主 |
发表于 13-9-2006 07:40 AM
|
显示全部楼层
yeh.. i slove the problem edi lah
The code like this
$numrows = count($c1);
for($i=0;$i<$numrows;$i++)
{
$aa="update book set
quantity=quantity - '".$c1[$i]."'
where bookid = '".$c0[$i]."'";
mysql_query($aa);
}
thanks XxX hunter
[ 本帖最后由 html 于 13-9-2006 07:43 AM 编辑 ] |
|
|
|
|
|
|
|
楼主 |
发表于 13-9-2006 07:42 AM
|
显示全部楼层
I more question how to change the form input type.. if i want it apper as a display only field (mean user cannot edit)..
<input type=text name=c0 value=$b1> |
|
|
|
|
|
|
|
发表于 13-9-2006 03:56 PM
|
显示全部楼层
<input type="Text" readonly="readonly" /> |
|
|
|
|
|
|
|
楼主 |
发表于 13-9-2006 07:35 PM
|
显示全部楼层
原帖由 XxX_hunter 于 13-9-2006 03:56 PM 发表
<input type="Text" readonly="readonly" />
Thanks a lot ... i hv one more question , did we hv any way to delete the text box (i mean , i want the value appear but dunno want to show the rectangular box) can it be possible ?? |
|
|
|
|
|
|
|
发表于 13-9-2006 07:51 PM
|
显示全部楼层
then use nomal text display |
|
|
|
|
|
|
|
发表于 14-9-2006 12:16 AM
|
显示全部楼层
原帖由 8years 于 13-9-2006 07:51 PM 发表
then use nomal text display
如果我输入资料时用textarea,
ex:
abc
bca
abc
我要display出来时也要看到
abc
bca
abc
如果我用textarea display 会看到框。但是用text, 看到的就是一整行。
要怎样呢? |
|
|
|
|
|
|
|
发表于 14-9-2006 02:42 PM
|
显示全部楼层
原帖由 确认密码 于 14-9-2006 12:16 AM 发表
如果我输入资料时用textarea,
ex:
abc
bca
abc
我要display出来时也要看到
abc
bca
abc
如果我用textarea display 会看到框。但是用text, 看到的就是一整行。
要怎样呢?
他的意思是直接显示字符(不懂有没有会错意)。 |
|
|
|
|
|
|
|
发表于 14-9-2006 11:29 PM
|
显示全部楼层
原帖由 jinn 于 14-9-2006 02:42 PM 发表
他的意思是直接显示字符(不懂有没有会错意)。
是直接显示字 |
|
|
|
|
|
|
|
发表于 14-9-2006 11:54 PM
|
显示全部楼层
if php use nl2br function, or replace \n to <br> to show out the text without textbox |
|
|
|
|
|
|
|
发表于 15-9-2006 02:05 PM
|
显示全部楼层
原帖由 8years 于 14-9-2006 11:54 PM 发表
if php use nl2br function, or replace \n to <br> to show out the text without textbox
非常感谢!!
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|