Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Apr 2006
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    making an image a link

    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>
    Then to send the information to the next page I was using this when the user clicked on the button to update

    Code:
    <form action="admin_delete.php?login=true&shopName=<?php echo $shopName; ?>" method="post">
    So I want to be able to do the same thing but by clicking on the image rather than entering an id number and clicking on the update button
    Last edited by ciaracous; 08-23-2006 at 02:50 PM.

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    235
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How about something like..
    PHP Code:
    <input type="image" name="<? echo $row['prodId'?>" alt="Send" value="Send" src="<? $row['image']?>">
    ?

    Crowds
    PHP magpie | And President Of The Marmalade Atkins Fan Club | Crowds Design

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I would just use Javascript and make your image a link with an onclick event that sets the value of a hidden input field and then submits your form. You'll have to give your form a name, add a hidden input field, and imbed the product ID.

    PHP Code:
    <a href="#" onclick="submitIt(\'$productID\');"><img src="http://snet.wit.ie/~ciaracousins/clothes/' . $row['image'] . '"></a>

    .
    .
    .

    <
    script type="text/Javascript">
    function 
    submitIt(id) {
        
    document.form1.hiddenID.value id;
        
    document.form1.submit();
    }
    </script> 

  • #4
    New Coder
    Join Date
    Apr 2006
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks, ok I got it working using

    Code:
    <td align="center"><a href="admin_update.php?login=true&shopName='.$row['shopName'].'&prodId='.$row['prodId'].'"><img src="http://snet.wit.ie/~ciaracousins/clothes/' . $row['image'] . '"></a>
    But what is happening now is that when I get to my admin_update.php the table isnt showing up. What is being passed through is the exact same as what was passed when i used the update button, but its not working when I do it this way. Should the same code not work for this since its the same values being passed in??

    Here is the code I am using for my admin_update page:

    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>Price</b></td>
    <td align="left"><input type="text" name="price" size="50" maxlength="50" value="'.$row['price'].'"/></td>
    
    
    
    </tr>';
    }
    		echo'
    
    				
    			<tr><td><center><input type="submit" name="submit" value="UPDATE"/>
    			<input type="reset" value="CLEAR FORM"></p></center>
    
    			
    			<input type="hidden" name="prodId" value='.$prodId.'>
    			<input type="hidden" name="shopName" value='.$sName.'>
    		
    
    				
    			<input type="hidden" name="submittedUpdate" value="TRUE"/></form></td></tr>
    			
    			</table>
    
    		';
    		}
    
    }
    
    	if(isset($_POST['submitted'])){
    
    		$prodId = trim($_POST['prodId']);
    		$shopName= $_GET['shopName'];
    		
    	
    		
    
    		
    		$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>Price</b></td>
    <td align="left"><input type="text" name="price" size="50" maxlength="50" value="'.$row['price'].'"/></td>
    
    
    
    
    
    </tr>';
    }
    		echo'
    
    				
    			<tr><td><center><input type="submit" name="submit" value="UPDATE"/>
    			<!--<input type="reset" value="CLEAR FORM"></p></center>-->
    			<tr><td><center>
    			
    
    			
    			<input type="hidden" name="prodId" value='.$prodId.'>
    			<input type="hidden" name="shopName" value='.$shopName.'>
    		
    
    				
    			<input type="hidden" name="submittedUpdate" value="TRUE"/></form></td></tr>
    
    			</table>
    			';
    			
    	}
    	
    	else{
    		echo'<h1> System Error </h1> table ';
    		exit();
    	}
    	
    	}
    	mysql_close();
    
    ?>
    
    			
    			
    </body>
    </html>

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    PHP Code:
    if(isset($_POST['submittedUpdate'])){ 
    Therein lies your problem. The $_POST variable does not get set if you arrive at the page from a regular normal standard link. Your $_GET variables are there, because you've loaded those into your url, but you have to submit the form to load up $_POST. That's why I suggested the method I did; your form gets submitted and your link emulates your submit button.

    However, that value $_POST['submittedUpdate'] is probably your submit button, so you'll have to reproduce that variable using a hidden input field. Either that or change your update code.

  • #6
    New Coder
    Join Date
    Apr 2006
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Fumigator,

    I hadn't seen your 1st post. I am trying to use that method now. Is the code that you wrote underneath all I need

    Code:
    <script type="text/Javascript"> 
    function submitIt(id) { 
        document.form1.hiddenID.value = id; 
        document.form1.submit(); 
    } 
    </script>
    Or do I still need to write more. I'm not really familiar with javascript (or php for that matter) so you'll have to forgive me. I just put the script code underneath where I had the table created, inside the php, and I changed the # to admin_update.php. Is that right??


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •