0

1.The Drop down list- lists the timestamp duration at which the images where put into database

  1. To view a image, user selects the timestamp displayed in the drop down list and clicks submit

  2. As soon as the submit button is pressed, "Connect.php" connects to database, makes "select" query comparing the timestamp in database to the timestamp user as selected

BUT I KEEP GETTING ERROR AS INVALID QUERY: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '19:21:43' at line 1

DATABASE TABLE HAS

1 "time_stamp" -datetime- CURRENT_TIMESTAMP

2 "name" - varchar(200)

3 "images"- longblob

kindly see the code and correct me

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].'"/>';
    }
}
?>
induraj
  • 3
  • 2
  • Please do not write new code using the mysql functions. Learn PDO or mysqli. I think the issue is that your query does not have quotes (') around the passed in time value. `$qrry= "select * from indu where time_stamp='$v1'";` Although that might still not work if you are not also passing the date. Try and get a select statement working against your database and then change your code to emit that format. – Andy Feb 06 '17 at 20:00

1 Answers1

0

You do not have value in <option value="">. You need something like this:

 $options = $options."<option value=\"$row[0]\"> $row[0] </option>";
laser
  • 570
  • 4
  • 20
  • provided that am altering this to mine index.php, how could i knew in connect.php as what option has been submitted? what goes in $_POST[' ??' ] – induraj Feb 06 '17 at 19:57
  • here is example of usage: http://stackoverflow.com/questions/17139501/using-post-to-get-select-option-value-from-html you already useing name="selected" thus on another side you need to take selected from _POST – laser Feb 06 '17 at 20:02
  • You don't have to pass a value, although it is recommended. If it is missing it will use the text between the – Andy Feb 06 '17 at 20:04
  • That helped; am not able to query "select * from indu where time_stamp=$v1"; – induraj Feb 06 '17 at 20:07
  • @AndyC ok, if that the case then the problem in quotes. – laser Feb 06 '17 at 20:07
  • @induraj just check sample query directly with DB, that is fastest way to verify if it is working. – laser Feb 06 '17 at 20:08
  • time_stamp in database has some value like this "2017-02-06 19:21:43" so while i query with "select images from indu where time_stamp=2017-02-06 19:21:43" ...it doesnt query, should i convert the time_stamp into string and make comparison? – induraj Feb 06 '17 at 20:09
  • @induraj use what AndyC wrote in comment: $qrry= "select * from indu where time_stamp='$v1'"; – laser Feb 06 '17 at 20:11
  • perfect, its working fine, but the line -- echo ''; produces lot of symbols that fills the entire page of the browser, and image icon appears without image! – induraj Feb 06 '17 at 20:17
  • @induraj that's another problem, check http://stackoverflow.com/questions/8499633/how-to-display-base64-images-in-html – laser Feb 06 '17 at 20:19
  • Also in your original code you seem to be referencing the wrong column from the results. As I mentioned above, be aware that your code is open to sql injection attack and should not be used. Look in to prepared statements, mysqli and PDO – Andy Feb 06 '17 at 20:22
  • since am not using base64 encoding, i dont think i must mention base64 in the < img src " ">.. tried using echo '';.. again the page full of symbols appears! – induraj Feb 06 '17 at 20:34
  • @laser This worked Guys, Thanks for ur support-- echo ''; – induraj Feb 06 '17 at 21:10