求助!!mysql数据库查询问题

sxkjdxllw0406 2010-05-08 05:43:57
这是我的一段代码:
<?php

$store_poster=$_POST['poster'];
$store_title=$_POST['title'];
$store_message=$_POST['message'];
$store_parent=$_POST['parent'];(parent 是个数字,其它的都是字符串)

//check not a duplicate
$conn=mysql_connect('localhost','root','lvliangwei');

mysql_select_db('lvyou', $conn) or die ('Can\'t use lvyou : ' . mysql_error());

$query="select header.postid from header ,body where
header.postid=body.postid and
header.parent=".$store_parent." and
header.poster='".$store_poster."' and
header.title='".$store_title."' and
body.message='".$store_message."'";

$result=mysql_query($query)or die("invalid query: " . mysql_error());

if(!$result){return false;}

$num_rows=mysql_num_rows($result);

在浏览器中运行时出现入下提示:


invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server

version for the right syntax to use near 'and header.poster= and header.title= and body.message='


这是怎么回事 我的$query语句赋值有错么?







...全文
94 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sxkjdxllw0406 2010-05-10
  • 打赏
  • 举报
回复
这些值都是我从上一个页面中post过来的,<form action="***" method="post">

“将值addslashes” 是什么意思?各位能解释一下么?
sxkjdxllw0406 2010-05-10
  • 打赏
  • 举报
回复
搞定了,是我插入的字段写错了,数据库中就没有$poster 一项!!


谢谢各位!!!
nsource 2010-05-08
  • 打赏
  • 举报
回复
是不是你表单 GET过来的?
Dleno 2010-05-08
  • 打赏
  • 举报
回复
语句是没有问题,应该是你插入的值的问题。可能是没有将值addslashes。
值里有特殊字符。
z109876543210 2010-05-08
  • 打赏
  • 举报
回复
addslashes
ghostxyz0 2010-05-08
  • 打赏
  • 举报
回复
$store_poster $store_title $store_message 都是空
你把那些值給上

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧