佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1016|回复: 12

请个位帮帮忙 PHP and Mysql 问题

[复制链接]
发表于 21-9-2006 06:58 PM | 显示全部楼层 |阅读模式
为什么没有update 去database ?? 想了大半天都想不到
请个位帮帮忙
here the code

--------------------------------------------------------------------------

<?php
    mysql_connect("localhost","root","1234");
    mysql_select_db("xxx");

    $dt = $_POST['dt'];
   
    $str="select bookname,author,publisher,isbn,price,buyprice,quantity
     from book
     where bookid='".$dt."'
     ";   
    $result=mysql_query($str);
    $num=mysql_numrows($result);
    mysql_close();
   
     $i=0;
     while ($i < $num) {
     $a3=mysql_result($result,$i,"bookname");
     $a4=mysql_result($result,$i,"author");
     $a5=mysql_result($result,$i,"publisher");
     $a6=mysql_result($result,$i,"isbn");
     $a7=mysql_result($result,$i,"price");
     $a9=mysql_result($result,$i,"buyprice");
     $a10=mysql_result($result,$i,"quantity");?>
      
     <form action="7.php" method=post>
     <input type="hidden" name="dt" value="<? echo "$dt"; ?>">
     Book Name: <input type="text" name="a3" value="<? echo "$a3"?>"><br>
     Author: <input type="text" name="a4" value="<? echo "$a4"?>"><br>
     Publisher: <input type="text" name="a5" value="<? echo "$a5"?>"><br>
     ISBN: <input type="text" name="a6" value="<? echo "$a6"?>"><br>
     Selling Price: <input type="text" name="a7" value="<? echo "$a7"?>"><br>
     Buying Price: <input type="text" name="a9" value="<? echo "$a9"?>"><br>
     Quantity: <input type="text" name="a10" value="<? echo "$a10"?>"><br>
     <input type="Submit" value="Update">
     </form>
<? ++$i;
}
?>

--------------------------------------------------------------------------

<?php

mysql_connect("localhost","root","1234");
mysql_select_db("xxx");

$a3=$_POST['a3'];
$a4=$_POST['a4'];
$a5=$_POST['a5'];
$a6=$_POST['a6'];
$a7=$_POST['a7'];
$a9=$_POST['a9'];
$a10=$_POST['a10'];
$dt=$_POST['dt'];

$aa="
             UPDATE book set
             bookname='".$a3."',
            author='".$a4."',
            publisher='".$a5."',
            isbn='".$a6."',
            price='".$a7."',
            buyprice='".$a9."',
            quantity='".$a10."',       
            where bookid='".$dt."'";

mysql_query($aa);
echo "Record Updated";
mysql_close();


?>

--------------------------------------------------------------------------
回复

使用道具 举报


ADVERTISEMENT

发表于 21-9-2006 08:33 PM | 显示全部楼层
你的 error message?
为什么你的 form 会在 while loop 里面?
回复

使用道具 举报

 楼主| 发表于 21-9-2006 09:09 PM | 显示全部楼层
原帖由 goatstudio 于 21-9-2006 08:33 PM 发表
你的 error message?
为什么你的 form 会在 while loop 里面?



No error ...

why while loop ? 这是我在一本书看到的,本来的 code is like this

list($a3,$a4,$a5,$a6,$a7,$a9,$a10)=mysql_fetch_row($result);



问题是when i click submit it post to 7.php and display Record Updated. but when i check back the databases it didn't update ...

why????????????????????
回复

使用道具 举报

发表于 21-9-2006 09:33 PM | 显示全部楼层
我相信你误解书里的例子了.

这样的 while loop, 会导致你相同的 form 和 form element 重复好几次,
这样的话, php 是无法执行你的 sql, 因为根本拿不到 value -> 重复好几次, 该拿那一个?
回复

使用道具 举报

发表于 21-9-2006 11:01 PM | 显示全部楼层
UPDATE book set
             bookname='$a3',
            author='$a4',
            publisher='$a5',
            isbn='$a6',
            price='$a7',
            buyprice='$a9',
            quantity='$a10',        
            where bookid='$dt'";

不知道这样可以吗???
还有就是make sure的$dt的value是对的
回复

使用道具 举报

 楼主| 发表于 21-9-2006 11:40 PM | 显示全部楼层
原帖由 红发 于 21-9-2006 11:01 PM 发表
UPDATE book set
             bookname='$a3',
            author='$a4',
            publisher='$a5',
            isbn='$a6',
            price='$a7',
            buyprice='$a9',
            q ...




我以经try过了but still cannot update...
回复

使用道具 举报

Follow Us
 楼主| 发表于 21-9-2006 11:48 PM | 显示全部楼层
原帖由 goatstudio 于 21-9-2006 09:33 PM 发表
我相信你误解书里的例子了.

这样的 while loop, 会导致你相同的 form 和 form element 重复好几次,
这样的话, php 是无法执行你的 sql, 因为根本拿不到 value -> 重复好几次, 该拿那一个?





我本来是用this code de

   list($a3,$a4,$a5,$a6,$a7,$a9,$a10)=mysql_fetch_row($result);

but cannot update the value , so i changed it to while loop.  不论是用while loop or
mysql_fetch_row.. 都updated 不到...
回复

使用道具 举报

发表于 22-9-2006 01:03 PM | 显示全部楼层
原帖由 html 于 21-9-2006 11:48 PM 发表





我本来是用this code de

   list($a3,$a4,$a5,$a6,$a7,$a9,$a10)=mysql_fetch_row($result);

but cannot update the value , so i changed it to while loop.  不论是用while loop or
mysql_fet ...


可以说说你要做什么吗? 为什么会有 while loop 把全部资料显示?
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 22-9-2006 01:55 PM | 显示全部楼层
我有三张page..(let said a.php,b.php,c.php)

let said (a.php) , a.php 会把所有的bookid store in database display 出来(i put in into form <select>).当user click submit button this page will post to b.php.

b.php will display all the information base on the bookid user had selected and user can change the value (update) (这个code no problem) 其实也不是一定要用while loop 用 其它method 也可以(i had change to mysql_fetch_row).当user click submit button this page will post to c.php

c.php will perform the update operation.问题就出在这里(it didn't display any error message but the value i had changed on b.php didn't update into databse)
回复

使用道具 举报

小嘴唇 该用户已被删除
发表于 23-9-2006 12:57 PM | 显示全部楼层

回复 #9 html 的帖子

为什么你不试 just pass in one value first, and try to update it first leh?

If it can run liao, then baru do for other value ma.

Actually you know what are u coding ar?


u still cant debug urself, u had to do it as simple as u can first, not directly put all the coding once to run la.
回复

使用道具 举报

发表于 24-9-2006 01:49 AM | 显示全部楼层
我觉得你应该试一下 把你要update 的code 全部都放在

if(isset($_POST['submit']){

    //这里
}

试看看好了 ==
回复

使用道具 举报

发表于 13-11-2006 05:20 PM | 显示全部楼层
改成下面这样吧。


$conn=mysql_connect("localhost","root","1234");
mysql_select_db("xxx",$conn);
回复

使用道具 举报

发表于 5-8-2007 01:38 AM | 显示全部楼层

回复 #1 html 的帖子

<?php
    mysql_connect("localhost","root","1234");
    mysql_select_db("xxx");

    $dt = $_POST['dt'];
   
    $str="select bookname,author,publisher,isbn,price,buyprice,quantity,dt
     from book
     where bookid='$dt'
     ";   
    $result=mysql_query($str);
    $num=mysql_numrows($result);
        
     $i=0;
     while ($i < $num) {
     $a3=mysql_result($result,$i,"bookname");
     $a4=mysql_result($result,$i,"author");
     $a5=mysql_result($result,$i,"publisher");
     $a6=mysql_result($result,$i,"isbn");
     $a7=mysql_result($result,$i,"price");
     $a9=mysql_result($result,$i,"buyprice");
     $a10=mysql_result($result,$i,"quantity");
     $dt=mysql_result($result,$i,"dt");
$i++;
}
mysql_close();

?>
      
     <form action="7.php" method=post>
     <input type="hidden" name="dt" value="<? echo "$dt"; ?>">
     Book Name: <input type="text" name="a3" value="<? echo "$a3"?>"><br>
     Author: <input type="text" name="a4" value="<? echo "$a4"?>"><br>
     Publisher: <input type="text" name="a5" value="<? echo "$a5"?>"><br>
     ISBN: <input type="text" name="a6" value="<? echo "$a6"?>"><br>
     Selling Price: <input type="text" name="a7" value="<? echo "$a7"?>"><br>
     Buying Price: <input type="text" name="a9" value="<? echo "$a9"?>"><br>
     Quantity: <input type="text" name="a10" value="<? echo "$a10"?>"><br>
     <input type="Submit" value="Update">
     </form>

--------------------------------------------------------------------------

<?php

mysql_connect("localhost","root","1234");
mysql_select_db("xxx");

$a3=$_POST['a3'];
$a4=$_POST['a4'];
$a5=$_POST['a5'];
$a6=$_POST['a6'];
$a7=$_POST['a7'];
$a9=$_POST['a9'];
$a10=$_POST['a10'];
$dt=$_POST['dt'];

$aa="
             UPDATE book set
             bookname='$a3',
            author='$a4',
            publisher='$a5',
            isbn='$a6',
            price='$a7',
            buyprice='$a9',
            quantity='$a10',        
            where bookid='$dt'";

mysql_query($aa);
echo "Record Updated";
mysql_close();


?>
改成这样吧。
回复

使用道具 举报

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

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


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

GMT+8, 15-9-2025 11:52 PM , Processed in 0.156747 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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