Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中使用html表单中的数据_Php_Html_Mysql - Fatal编程技术网

在php中使用html表单中的数据

在php中使用html表单中的数据,php,html,mysql,Php,Html,Mysql,因此,当我尝试使用此方法进行搜索时,我没有得到任何结果 您把selects结束标记放错了:我想您也记得关闭表单了吧 $submit = $_POST['submit']; if($submit) { $search = $_POST['search']; $catval = $_POST['Category']; echo $catval ; $searchval = mysql_query("select * from item where iname lik

因此,当我尝试使用此方法进行搜索时,我没有得到任何结果

您把selects结束标记放错了:我想您也记得关闭表单了吧

$submit = $_POST['submit'];

if($submit)
{
    $search = $_POST['search'];
    $catval = $_POST['Category'];
    echo $catval ;
    $searchval = mysql_query("select * from item where iname like '%$search%'and cId in (select cId from category where cName = '$catval')");
    while($info = mysql_fetch_array($searchval))
    {
        echo "Item Name: " . $info['iName'];
    }
}
这应该能奏效。你的位置错了


同时,您可以不使用mysql,因为mysql已贬值,即不再使用它,而且不安全。

您不应该查询所有字段,不使用*运算符并限制结果数。不要处理原始的用户输入,而是将其取消扫描,或者更好的是,使用PDO准备好的语句使SQL注入变得不可能。SQL注入是一个严重的安全问题。请。它们不再得到维护,而是在使用。请注意,我的意思是逃避,而不是逃避。不幸的是,我的评论无法再编辑。当我回显$catval时,我仍然一无所获。您已经关闭了表单,对吗?我的意思是,您在输入的最后有一个名称?请参阅我的更新答案,您忘记从第一个查询中获取类别,您只获取了cName
$submit = $_POST['submit'];

if($submit)
{
    $search = $_POST['search'];
    $catval = $_POST['Category'];
    echo $catval ;
    $searchval = mysql_query("select * from item where iname like '%$search%'and cId in (select cId from category where cName = '$catval')");
    while($info = mysql_fetch_array($searchval))
    {
        echo "Item Name: " . $info['iName'];
    }
}
<form action='main.php' method='POST'>
<select name="Category" class='listbox'>
<?php $cat = mysql_query("select cName, Category from category");
while($drop = mysql_fetch_array($cat))
{
    echo '<option value="' . $drop['Category'] . '">' . $drop['cName'] .'</option>';
}
?>
</select>
<input type='text' name='search' class='namebox'>
<input type='submit' name='submit' value='Search' class='submitbox'> 
</form>
<form action='main.php' method='POST'>
<select name="Category" class='listbox'>
<?php $cat = mysql_query("select cName from category");
while($drop = mysql_fetch_array($cat))
{
    echo '<option value="' . $drop['Category'] . '">' . $drop['cName'] .         
'</option>';
}
?>
</select>
<input type='text' name='search' class='namebox'>
<input type='submit' name='submit' value='Search' class='submitbox'>
</form>