使用 PHP 将文本框中的多值插入 MySQL 数据库
我的 PHP 和 MySQL 项目有问题。我想将多列值插入数据库,但事实是,我已经对代码感到困惑了。如果您想看一下,就像这样:
if(!empty($_POST['brando'])){ $A="brand = '$brando'";} else{ $A=" ";} if(!empty($_POST['prnameo'])){ $B="product_name = '$prnameo'";} else{ $B=" ";} if(!empty($_POST['prido'])){ $C="product_id = '$prido'";} else{ $C=" ";} if(!empty($_POST['prcolo'])){ $D="color = '$prcolo'";} else{ $D=" ";} if(!empty($_POST['priceo'])){ $E="price = '$priceo'";} else{ $E=" ";} $sqlq="UPDATE $tbl_name2 SET $A $B $C $D $E where id='$id'"; mysql_query($sqlq);
我注意到在数据库中查询多值命令需要逗号,例如:
mysql_query("UPDATE $tablename SET collumn1='value', collum2='value' where id='value'");
现在我不能在任何这些代码中放置任何逗号或“,”,从而使 PHP 页面无法发送其他变量值传入服务器。
即使我将编码更改为:
$sqlq="UPDATE $tbl_name2 SET $A , $B , $C , $D , $E where id='$id'";
它还会产生除了该死的错误之外的其他内容。
所以如果你知道我在说什么的话我想寻求帮助。我知道,听起来编码给我带来了压力。
哦,这个代码也是,我忘了把它放在这些上。
for ($help_given=1, $help_given++) { echo "Thanks"; }
I'm having a problem with my PHP and MySQL project . I wanted to insert multi collumn value into the database but the truth is, im already confused by the codes. it's like this if you would like to take a look:
if(!empty($_POST['brando'])){ $A="brand = '$brando'";} else{ $A=" ";} if(!empty($_POST['prnameo'])){ $B="product_name = '$prnameo'";} else{ $B=" ";} if(!empty($_POST['prido'])){ $C="product_id = '$prido'";} else{ $C=" ";} if(!empty($_POST['prcolo'])){ $D="color = '$prcolo'";} else{ $D=" ";} if(!empty($_POST['priceo'])){ $E="price = '$priceo'";} else{ $E=" ";} $sqlq="UPDATE $tbl_name2 SET $A $B $C $D $E where id='$id'"; mysql_query($sqlq);
I noticed that querying multivalue command into a database requires comma such as:
mysql_query("UPDATE $tablename SET collumn1='value', collum2='value' where id='value'");
and now i cant put any comma or "," in any of those codes, making the PHP page unable to send other variable values into the server.
even if i change the coding to this:
$sqlq="UPDATE $tbl_name2 SET $A , $B , $C , $D , $E where id='$id'";
it'll produce what else but damn errors.
so i would like to ask for help if you know what i'm talking about. i know, it sounds like i've been stressed out by the codings.
ooh, this code too, i forgot to put it for these.
for ($help_given=1, $help_given++) { echo "Thanks"; }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试用“,”来implode()一个数组,如下所示:
然后,你最好使用“mysql_escape_string”或“PDO::prepare”方法来防止SQL注入。
Try to implode() an array with "," ,like this:
Then, you'd better to use "mysql_escape_string" or "PDO::prepare" method to prevent SQL injection.
只需将值放在我注释为 // 的位置即可设置...
Just put values where I have commented as //to set...