Php 使用数据库中的选定条目在我的网页中创建下拉列表
我正在创建一个网页,其中有人输入一个名称,并在下拉列表中显示以该名称注册的市场。 这是我的部分代码Php 使用数据库中的选定条目在我的网页中创建下拉列表,php,mysql,database,drop-down-menu,command-line,Php,Mysql,Database,Drop Down Menu,Command Line,我正在创建一个网页,其中有人输入一个名称,并在下拉列表中显示以该名称注册的市场。 这是我的部分代码 <form name="login" action="index_submit" method="get" accept-charset="utf-8"> <ul> <li> <label for="seller">Seller Name/ID</l
<form name="login" action="index_submit" method="get" accept-charset="utf-8">
<ul>
<li>
<label for="seller">Seller Name/ID</label>
<input type="text" id="username" placeholder="Seller Username/ID" required>
</li>
<?php
?>
<li>
<label for="marketplace">Choose a marketplace</label>
<select name="url" onchange="menu_goto(this.form)">
<?php
include ('config.php');
$username = $_POST['username'];
$query = "SELECT Marketplace FROM Details WHERE Seller_name='$username' OR Seller_ID='$username'";
$result = mysql_query($dbcon, $query) or die('error getting data');
while ($row = mysql_fetch_array($result)){
echo "<option value="marketplace1">" . $row['Marketplace'] . "</option>";
}
?>
</select>
</li>
-
卖方名称/身份证
-
选择一个市场
在您的文档中,您应该得到如下内容:
Parse error: syntax error, unexpected 'marketplace1' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\testing\index.php on line 2
假设您已使用@yaso建议的HTML格式
这样更改代码时,应将错误设置为显示在浏览器窗口上
我还假设你是用一个类似
example.com/myscript.php?username=OneThatExists
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include ('config.php');
$username = $_POST['username'];
$query = "SELECT Marketplace FROM Details WHERE Seller_name='$username' OR Seller_ID='$username'";
$result = mysql_query($query,$dbcon) or die('error getting data');
while ($row = mysql_fetch_array($result)){
echo "<option value="marketplace1">" . $row['Marketplace'] . "</option>";
}
?>
首先,你把mysql\u query()的参数搞错了,请执行$result=mysql\u query($query,$dbcon)
,或者你使用的是MYSQLI\u扩展,它只是一个输入错误,应该是MYSQLI\u query($dbcon,$query)
弃用的mysql*它们不再维护,正式弃用。使用mysqli或PDOsearch有关错误报告的信息查看此信息,以了解t'internet@RiggsFolly,我正在使用mysql和Internet更改$dbcon和$query,但没有任何帮助。结果仍然是一样的,我不确定错误报告(E_ALL)做了什么,尽管在我的php脚本中添加它并没有什么不同。我是否需要为我的php代码添加submit以读取查看器输入的用户名的市场?如果您在服务器设置中测试此问题,请查看php错误日志,因为实时错误可能不会显示在浏览器上,但可能会记录到错误日志中
<?php
include ('config.php');
$username = $_POST['username'];
$query = "SELECT Marketplace FROM Details WHERE Seller_name='$username' OR Seller_ID='$username'";
$result = mysql_query($dbcon, $query) or die('error getting data');
$res='';
while ($row = mysql_fetch_array($result)){
$res .='<option value="marketplace1">' . $row['Marketplace'] . '</option>';
}
echo $res;
?>
echo "<option value="marketplace1">" . $row['Marketplace'] . "</option>";
^ ^ ---------> Not escaped
echo "<option value=\"marketplace1\">" . $row['Marketplace'] . "</option>";
echo '<option value="marketplace1">' . $row['Marketplace'] . '</option>';
error_reporting(E_ALL);
Parse error: syntax error, unexpected 'marketplace1' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\testing\index.php on line 2
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include ('config.php');
$username = $_POST['username'];
$query = "SELECT Marketplace FROM Details WHERE Seller_name='$username' OR Seller_ID='$username'";
$result = mysql_query($query,$dbcon) or die('error getting data');
while ($row = mysql_fetch_array($result)){
echo "<option value="marketplace1">" . $row['Marketplace'] . "</option>";
}
?>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include ('config.php');
if ( isset($_POST['username']) ) {
$_POST['username'] = sanityCheck($_POST['username']);
$query = "SELECT Marketplace
FROM Details
WHERE Seller_name='{$_POST['username']'
OR Seller_ID='{$_POST['username']}'";
$result = mysql_query($query, $dbcon) or die('error getting data');
while ($row = mysql_fetch_array($result)){
echo "<option value="marketplace1">" . $row['Marketplace'] . "</option>";
}
} else {
// do whatever you want to do if no parameter was entered
}
?>