php - $result mysql_query() 困难

标签 php html mysql

<分区>

我正在尝试从我的数据库中提取信息,使用选项列表并根据选择选择行。

table: sales

columns: year, q1, q2, q3, q4

values: 2011, 127.24, 106.54, 88.04, 120.89

尝试从我的数据库返回 $result 查询时。它返回两个警告:

mysql_query() expects parameter 1 to be string

mysql_error() expects parameter 1 to be resource

这是我的代码:

<?php

$mysqli = mysqli_connect("localhost","admin","admin","testDB");

$year= $_POST['year'];

$taryear= filter_input(INPUT_POST, 'year');
$yearsql= "SELECT year FROM sales WHERE year = '".$taryear."'";
$result= mysql_query($mysqli, $yearsql) or die(mysql_error($mysqli));


?>

<html>
<body>
    <form action = "salespie.php" method = "POST">
        <select name = "year">
            <option value = "2011">2011</option>
            <option value = "2012">2012</option>
            <option value = "2013">2013</option>
        </select>
        <input type = "submit" value = "Submit">
    </form>
</body>
</html>

我试图回显 $year 本身,它返回 2011。

我还回显了 $yearsql,结果为:SELECT year FROM sales WHERE year = '2011'

我不太明白我做错了什么来获得这两个警告。

任何指导/帮助将不胜感激!

谢谢,

最佳答案

正如 Fred 在评论中提到的,您正在混合使用 mysql_*mysqli_* 函数。
They are not the same thing.

鉴于您要传递连接链接,您可能打算使用 mysqli_query相反。

关于php - $result mysql_query() 困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26639984/

相关文章:

php - 如何在空格后分割内容

php - Wordpress Customizer (functions.php) - 网站崩溃 (500)

php - http ://localhost/myphpadmin/index. php 只显示代码

mysql - CHAR(0) 允许在 mysql 中插入所有长度的值

javascript - 如何使标题在 wordpress 中保持粘性

mysql - 使用外文和英文字符获得相同的 MySQL 搜索结果

javascript - 允许在文本区域中输入 HTML

php - SQLSTATE[42S02] : Base table or view not found - cant find the typo Laravel

php - 用 PHP 或 HTML 绘制图表

javascript - 将不同 View 模型的属性相互绑定(bind)