Jump to content


Photo

making an image a link


  • Please log in to reply
3 replies to this topic

#1 kikilahooch

kikilahooch
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 23 August 2006 - 01:40 PM

Hi,

I'm just wondering how I can make an image into a link. I have a page which displays all the details on all of the products I have stored in my database and I have an image of each product beside them. What I am doing at the moment is typing the name product id in and clicking on a button to update it which sends all the details on the product to a new page where they can be updated. What I want to do is just click on the image and have it send all the details to the next page, rather than having to type in a product id everytime so as to cut down on human error.

I have the table with the details displayed as follows: 

<td align="center"><img src="http://snet.wit.ie/~ciaracousins/clothes/' . $row['image'] . '">
<td align="center">'.$row['prodId'].'</td>
<td align="center">'.$row['shopName'].'</td>
<td align="center">'.$row['prodName'].'</td>
<td align="center">'.$row['dept'].'</td>
<td align="center">'.$row['brand'].'</td>
<td align="center">'.$row['type'].'</td>                                                   
<td align="center">'.$row['image'].'</td>
<td align="center">'.$row['price'].'</td>

Then to send the information to the next page I was using

<form action="admin_delete.php?login=true&shopName=<?php echo $shopName; ?>" method="post">


#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 23 August 2006 - 02:00 PM

Ummm, put an anchor tag around it....

<a href="nextpage.php"><img src="image.png" border="0" /></a>


#3 lessthanthree

lessthanthree
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts
  • LocationUK

Posted 23 August 2006 - 02:07 PM

As above, but obviously to pass any data you'll need to pass some stuff in the URL so you can access it on the next page via $_GET.

print "<a href='nextpage.php?shopname=".$row["shopname"]."&type=".$row["type"]."'><img src='blah.jpg' /></a>";

Don't forget to clean and check that the values you access on the next page via $_GET are what you want them to be, else you're asking for security problems with people passing mallicious stuff to the page via the URL.
call me a safe bet, i'm betting i'm not

#4 kikilahooch

kikilahooch
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 23 August 2006 - 02:52 PM

Thanks!

Ok now the values are being passed to my admin_update.php page but it is not displaying the table like it did when I used the update button, even though what is being passed in through the url is the exact same. I am only new to php and wrote the code for the update page months ago and havent been near it since, so I have forgotten a lot of it. Here is the code that I used anyway:

<?php
	include "db.php";

$prodId = $_GET['prodId'];
$shopName = $_GET['shopName'];

$query="select shopId from shops where shopName=$shopName";


$sql= "select * from product where prodId=$prodId";



	
	if(isset($_POST['submittedUpdate'])){
		

		
		
		$prodId= trim($_POST['prodId']);
		$sName = trim($_POST['shopName']);
		$prodName= trim($_POST['prodName']);
		$dept = trim($_POST['dept']);
		$brand = trim($_POST['brand']);
        	             $type = trim($_POST['type']);
		$image = trim($_POST['image']);
		$price = trim($_POST['price']);

	
	
			

		
		$query2 = "UPDATE product SET prodName='$prodName', dept='$dept', brand='$brand', type='$type', image='$image', price='$price' WHERE prodId ='$prodId' and shopName='$shopName'";
		

		
		$result = @mysql_query($query2);
			if($result){
				echo'<p align=center><font color="#333333"><b>UPDATED SUCCESSFULLY</b></font></p>';
			}
	
			else{
				echo'<h1> System Error </h1>';
			}
		

		
		$query = "SELECT * FROM product WHERE prodId = '$prodId' and shopName='$shopName'";

		
		$result = @mysql_query($query);
		if($result){
					echo'

					
					<form action="admin_update.php" method="post">
					

					
					<center>
					<table align="center" cellspacing="0" cellpadding="5" bgcolor="#ffffff" border=1 bordercolor="#2696b8">';

					while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
					echo'


<tr><td align="left" bgcolor="#2696b8"><center><font color="black"><b>Product Id </b></center></td>
<td align="left">'.$row['prodId'].'</td>




<tr><td align="left" bgcolor="#2696b8"><center><font color="black"><b>Shop Name</b></td>
<td align="left">'.$row['shopName'].'</td>

<tr><td align="left" bgcolor="#2696b8"><center><font color="black"><b>Product Name</b></td>
<td align="left"><input type="text" name="prodName" size="30" maxlength="30" value="'.$row['prodName'].'"/></td>

.
.
.
.
.

Would be really grateful if you could point out what other changes need to be mage




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users