Jump to content

Archived

This topic is now archived and is closed to further replies.

kikilahooch

making an image a link

Recommended Posts

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: 

[code]
<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>
[/code]

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

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

Share this post


Link to post
Share on other sites
Ummm, put an anchor tag around it....

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

Share this post


Link to post
Share on other sites
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.

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

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.

Share this post


Link to post
Share on other sites
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:

[code]
<?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>

.
.
.
.
.[/code]

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.