![](/img/trans.png)
[英]Retrieving data from database with dropdown list PHP/MySQL/HTML
[英]dropdown list of timestamp- retrieving image from database (query based on timestamp where clause)-php/mysql
1.下拉列表-列出将图像放入数据库的时间戳记持续时间
要查看图像,用户选择下拉列表中显示的时间戳,然后单击提交。
按下提交按钮后,“ Connect.php”将连接到数据库,并进行“选择”查询,将数据库中的时间戳与选定的时间戳用户进行比较
但是我会继续以无效查询的方式获取错误:您的SQL语法有错误; 检查与您的MariaDB服务器版本相对应的手册,以在第1行的'19:21:43'附近使用正确的语法
数据库表已
1个“ time_stamp” -datetime- CURRENT_TIMESTAMP
2个“名称”-varchar(200)
3张“图片”-longblob
请查看代码并纠正我
的index.php
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<?php
$conn=mysql_connect("localhost","root","");
mysql_select_db("simpletest",$conn);
$qry= "select * from indu";
$result=mysql_query($qry,$conn);
$options="";
while($row=mysql_fetch_array($result))
{
$options = $options."<option> $row[0] </option>";
}
?>
</head>
<body>
<form action="connect.php" method="post">
<select name="selected">
<?php echo $options; ?>
</select>
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
connect.php
<?php
$connn=mysql_connect("localhost","root","");
mysql_select_db("simpletest",$connn);
if (isset($_POST['submit']))
{
$v1=$_POST['selected'];
echo $v1;
echo "<br/>";
$qrry= "select * from indu where 'time_stamp'=$v1";
echo $qrry;
$result1=mysql_query($qrry,$connn);
echo $result1;
if (!$result1)
{
die('Invalid query: ' . mysql_error());
}
while($row1=mysql_fetch_array($result1))
{
echo '<img height"300" width="300" src="data:image;base64,'.$row1[1].'"/>';
}
}
?>
您在<option value="">
没有值。 您需要这样的东西:
$options = $options."<option value=\"$row[0]\"> $row[0] </option>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.