-3

我是 mysql 新手,我在我的 godaddy 帐户中使用 phpmyadmin 创建了一个表,但我无法通过 php 添加任何内容。代码是:

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';

mysql_query($conn,"INSERT INTO entries (business) VALUES ('Test biz')");

我连接成功,但出现错误“mysql_query() 期望参数 1 为字符串,资源给定”在线

mysql_query($conn,"INSERT INTO entries (business) VALUES ('Test biz')");

关于为什么会这样的任何想法?谢谢!

4

3 回答 3

0

需要从

mysql_query($conn,"INSERT INTO entries (business) VALUES ('Test biz')");

mysql_query("INSERT INTO `entries` ( `business` ) VALUES ('Test biz')");

这里是手册

于 2013-08-26T18:10:41.727 回答
0

解决方案

没有必要在你的 mysql 查询中传递 $conn,试试没有那个,

有关语法的更多信息,请参阅此页面:http: //php.net/manual/en/function.mysql-query.php

于 2013-08-26T18:13:49.057 回答
0

你需要调用 mysql_select_db($conn,'');

$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';

mysql_query($conn,"INSERT INTO entries (business) VALUES ('Test biz')");

$conn = mysql_connect($dbhost, $dbuser, $dbpass);

if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db('<your db name here>',$conn);

mysql_query("INSERT INTO entries (business) VALUES ('Test biz')");

您不需要将 $conn 传递给 mysql_query();

谢谢

于 2013-08-26T18:19:52.423 回答