1

In my web application I have an images and each and every image has button for like as well as name of the user who uploaded it.User name is a link. But in my code both link and button not work.Both are not clickable. Here is my code

     <?php 
 // Connects to your Database 
 mysql_connect("localhost", "root", "") or die(mysql_error()) ; 
  mysql_select_db("test") or die(mysql_error()) ; 

 //Retrieves data from MySQL 
   $data1 = mysql_query("SELECT * FROM image_upload INNER JOIN user_table
ON image_upload.user_id=user_table.user_id  WHERE flag=1 ORDER BY timestamp DESC; ")     or die(mysql_error());


//Puts it into an array

 while($info = mysql_fetch_array($data1)){
  //Outputs the image and other data 
  ?>

  <div class="test" id="<?php $info['ID']?>">
  <div class="username"><a href="profile.php" class="but" title=""><?php echo     $info['user_name']?></a></div>
  <div class="imagedisplay"><img src="<?php echo     "uploads/".$info['image']?>"style="width:230px; height:auto; border:1px solid #000; border-    radius:20px;"></div>
  <div class="desc"><?php echo $info['description']?></div>
  <button type="button" id="<?php echo $info['ID']?>">Like</button>


 </div>

<?php
   }
 ?> 

Can any one help me please.

Lanka
  • 29
  • 2
  • 11
  • 1
    at your first div you missed a space between – Déjà vu Nov 13 '14 at 09:14
  • Quick tip: mysql_* is depricated. Use PDO instead ;) – Paradoxis Nov 13 '14 at 09:17
  • 1
    [Please, stop using mysql_* functions](http://stackoverflow.com/q/12859942/1238019) in new code, they are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Instead of, have a look on [prepared statements](http://dev.mysql.com/doc/refman/5.0/en/sql-syntax-prepared-statements.html), and use [Mysqli](http://php.net/manual/en/book.mysqli.php) or [PDO](http://php.net/manual/en/book.pdo.php). – zessx Nov 13 '14 at 09:17
  • hmm, it seems to work just fine for me. – Déjà vu Nov 13 '14 at 09:20
  • Add Anchor tag to Image for enable click – Amy Nov 13 '14 at 09:43

1 Answers1

0

Try this one

<?php 
 // Connects to your Database 
mysql_connect("localhost", "root", "") or die(mysql_error()) ; 
mysql_select_db("test") or die(mysql_error()) ; 

 //Retrieves data from MySQL 
$data1 = mysql_query("SELECT * FROM image_upload INNER JOIN user_table
ON image_upload.user_id=user_table.user_id  WHERE flag=1 ORDER BY timestamp DESC; ")     or die(mysql_error());


//Puts it into an array

while($info = mysql_fetch_array($data1)){
//Outputs the image and other data 
?>

  <div class="test" id="<?php echo $info['ID']?>">
  <div class="username"><a href="profile.php" class="but" title=""><?php echo $info['user_name']?></a></div>
  <div class="imagedisplay"><img src="<?php "uploads/".$info['image']?>"style="width:230px; height:auto; border:1px solid #000; border-radius:20px;"></div>
  <div class="desc"><?php echo $info['description']?></div>
  <button onclick="location.href='profile.php'" type="button" id="<?php echo $info['ID']?>">Like</button>
 </div>

<?php
}
?>

MySQL extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used.

MySQLi Solution

<?php 
 // Connects to your Database 

$con = mysqli_connect('localhost', 'root', '');
    mysqli_select_db($con, 'test') or die ('Failed to connect to MySQL: ' . mysqli_connect_error()); 


 //Retrieves data from MySQL 
$data1 = mysqli_query($con, "SELECT * FROM image_upload INNER JOIN user_table
ON image_upload.user_id=user_table.user_id  WHERE flag=1 ORDER BY timestamp DESC; ") or die(mysqli_error($con));


//Puts it into an array

while($info = mysqli_fetch_array($data1)){
//Outputs the image and other data 
?>

  <div class="test" id="<?php echo $info['ID']?>">
  <div class="username"><a href="profile.php" class="but" title=""><?php echo $info['user_name']?></a></div>
  <div class="imagedisplay"><img src="<?php "uploads/".$info['image']?>"style="width:230px; height:auto; border:1px solid #000; border-radius:20px;"></div>
  <div class="desc"><?php echo $info['description']?></div>
  <button onclick="location.href='profile.php'" type="button" id="<?php echo $info['ID']?>">Like</button>
 </div>

<?php
}
?>
DJ MHA
  • 598
  • 3
  • 18