mysql_query():提供的参数不是有效的 MySQL-Link 资源
我一直在尝试从表单中插入样本数据,但执行 $result 时总是出现语法错误。
来自index.php的相关部分:
<form method="post" action="form.php">
<ul >
<li>
<label for="accession_number">Accession Number</label>
<input id="accession_number" name="accession_number" type="text" maxlength="6" value=""/>
</li>
</ul>
</form>
和来自form.php的部分:
<?php
$connection = mysql_connect($server, $username, $password) or die('Could not connect'.mysql_error());
mysql_select_db($database, $connection) or die("Cannot select db.");
$accession_number = $_POST['accession_number'];
$query = "INSERT INTO top (accession_number) ".
"VALUES ($accession_number)";
var_dump($query);
mysql_error();
$result = mysql_query($$query, connection) or die('Error querying database.');
mysql_close($connection);
?>
我不知道我做错了什么。
I have been trying to insert a sample piece of data from my form, but I always get a syntax error executing $result.
The relevant part from index.php:
<form method="post" action="form.php">
<ul >
<li>
<label for="accession_number">Accession Number</label>
<input id="accession_number" name="accession_number" type="text" maxlength="6" value=""/>
</li>
</ul>
</form>
and parts from form.php:
<?php
$connection = mysql_connect($server, $username, $password) or die('Could not connect'.mysql_error());
mysql_select_db($database, $connection) or die("Cannot select db.");
$accession_number = $_POST['accession_number'];
$query = "INSERT INTO top (accession_number) ".
"VALUES ($accession_number)";
var_dump($query);
mysql_error();
$result = mysql_query($query, connection) or die('Error querying database.');
mysql_close($connection);
?>
I don't know what I'm doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
mysql_query()
参数顺序错误。这
应该是
http://php.net/manual/en/function.mysql-查询.php
更新
当我说使用 mysql_error() 时,我的意思是仅当存在明显错误时。尝试这样的事情,
我强烈建议完全放弃 MySQL 库并转向 PDO。写上面的代码让我感觉很肮脏。
Your parameters for
mysql_query()
are in the wrong order.This
should be
http://php.net/manual/en/function.mysql-query.php
Update
When I said use
mysql_error()
, I meant only if there was an apparent error. Try something like thisI highly recommend ditching the MySQL library entirely and moving to PDO. Writing the above code makes me feel dirty.