我已经坚持这个问题大约3天了。我将非常感谢能解决这个问题的任何帮助,请您解释我在哪里以及如何出错,因为我想学习和理解!
基本上我想要实现的目标如下。
一个下拉菜单,它将显示我数据库中所选列的结果。
我的数据库有3列“project_name”,“stage”和“project_details”
如果用户选择“舞台”,则必须仅在屏幕上的“舞台”栏中显示/回显结果。
以下代码是我到目前为止的代码!我知道我受到SQL注入,但我试图让过滤器先工作,然后我会解决它。
目前我一直在第42和第56行收到错误,我将非常感谢任何人的帮助或输入!
<form action='filter2.php' method='post' name='value' >
<select name="value">
<option value="project_name">project_name</option>
<option value="stage">stage</option>
<option value="project_details">project_details</option>
</select>
<br />
<input type='submit' value = 'Filter'>
</form>
<?php
// Authentication Variables
$servername = "localhost";
$username = "basic";
$password = "redrobinX123";
$dbname = "basic_forms1";
// Make connection
$con = mysql_connect($servername, $username, $password, $dbname);
// If error connecting
if (!$con) {
die(mysql_error("could not connect"));
}
// If post value isset
if(isset($_POST['value'])) {
$column = $_POST['value']; // Set Column
$query = "SELECT". $column . "FROM photo"; // Create Query
$sql = mysql_query($query); // Run Query
// Loop through results
while ($row = mysql_fetch_array ($sql)){
echo "<br>". $row[$column] . "<br>";
}
// Close connection
mysql_close($con);
}
?>
答案 0 :(得分:0)
像这样设置......
// Authentication Variables
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Make connection
$con = mysqli_connect($servername, $username, $password, $dbname);
// If error connecting
if (!$con) {
die(mysqli_error("could not connect"));
}
// If post value isset
if(isset($_POST['value'])) {
$column = $_POST['value']; // Set Column
$query = "SELECT $column FROM photo"; // Create Query
$sql = mysqli_query($con, $query); // Run Query
// Loop through results
while ($row = mysqli_fetch_array($sql, MYSQLI_ASSOC)){
echo "<br>". $row[$column] . "<br>";
}
// Close connection
mysqli_close($con);
}
答案 1 :(得分:0)
我认为你混合了mysql和mysqli的功能。试试这个
constexpr sDummyStruct array[]=
{
{dummy0, 3},
{dummy1, 5},
{dummy2, 6}
};
constexpr bool checkArray(int index) {
return (index >= sizeof(array)/sizeof(array[0])) ||
(array[index].name == index && checkArray(index + 1));
}
static_assert(checkArray(0), "bad array");