简体   繁体   English

为什么不用我的php脚本查询mysql?

[英]Why won't mysql query with my php script?

I'm trying to make this information insert into my table in mysql database with this script I wrote. 我正在尝试使用我编写的这个脚本将此信息插入到mysql数据库的表中。

<?php
require("../includes/db.php");
$nme = $_POST["nme"];
$email = $_POST["email"];
$address = $_POST["address"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$phone = $_POST["phone"];
$options = implode($_POST["options"],", ");
$query = mysql_query("insert into peeps (name, email, address, city, zip, phone, type) values ('$nme','$email','$address','$city','$state','$zip','$phone','$options')");
if($query)
    print "yes";
else
    print "no";

?> ?>

The output of this code is no. 此代码的输出为no。

If mysql_query() returns false, it means the query failed. 如果mysql_query()返回false,则表示查询失败。

Try this: 尝试这个:

if (false === $query)  // make sure it's actually boolean false
  print mysql_error(); // print a nice plain-english description of the problem.
else
  print "Yes";

This should give you a good idea of where the problem is. 这应该可以让您了解问题所在。

If you modify this part of your code you can see the exact error you get. 如果修改代码的这一部分,您可以看到确切的错误。

if($query)
{
    print "yes";
}
else
{
    print mysql_error(); ;
}

However the way you have written may generate errors if you do not have enabled Magic Quotes. 但是,如果您没有启用Magic Quotes,您编写的方式可能会产生错误。 If you have that kind of error you better use mysql_escape_string 如果你有这种错误,最好使用mysql_escape_string

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM