佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 734|回复: 19

PHP problem

[复制链接]
发表于 10-9-2006 06:33 PM | 显示全部楼层 |阅读模式
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 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 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
回复

使用道具 举报

Follow Us
 楼主| 发表于 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  
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 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, 看到的就是一整行。
要怎样呢?
回复

使用道具 举报


ADVERTISEMENT

发表于 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



非常感谢!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 23-9-2024 05:14 PM , Processed in 0.145637 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表