Want to click on an image from a list and simply set that filename in a field in a mysql database. I read the tutorials and have tried several different ways to pass the variable on the url and then update with a second php page.

Hi my second question here in 2 months last answers I really appreciated.

I am reading through a simple table with 1 field. Crest (its a filename). I am generating a list of the pictures and when the user clicks on his or her crest I want it to simply update into a field called Crest in a user main profile.

It really doesnt like me generating hrefs inside the while loop apparently but I dont see a way to do it more efficiently. I have 2 php pages 1 called selectcrest and the other called updatecrest.

The code for selectcrest so far if I try anythign else in the href trying to get a link off the image I get an error... Perhaps I should be using javascript to do this? or can I efficiently do it the way I am thinking. Sorry this is probably another simple one like my last question but I have beat my head against the walls for 2 days now not seeing it:

<?php
 echo "<tr>";
 
$result		= $db->query("SELECT Crest FROM Crests ORDER BY Crest ");
$rowcount = -2;
	  while($images	= $db->fetch($result)){
                  $crestdisplay =  $images['Crest'];
		  $rowcount = $rowcount + 1;
		  if($rowcount >10){echo"<TR></TR>"; $rowcount = 0;}
                  if($crestdisplay<>""){
                  echo "<a href=\"$crestdisplay\">";
                  echo "<td><image src=/images/$crestdisplay  border=\"0\"width=50 height=50 alt="."></a> </td>";
		  }
	
  
	  }
echo "</tr>";
?>

The php I intend to update the field once the link works is:

<?php
$isadmin="*";
include("../includes/inc-header.php");
		$NewCrest = $_GET['Crest'];
	?>
	<table width="100%" border="0" align="center">
	  <tr>
		<td colspan="2" class="bodycell3">Account</td>
	  </tr>
	  <tr>
		<td class="bodycell4" align="center">
			<?
$db->query("UPDATE users SET crest=$NewCrest uID='" . $user['uID'] . "'");
						
			?>
			<br><br>
                        <meta http-equiv="refresh" content="0; URL=<?=$incloc2?>index.php">">
			<a href="<?=$incloc2?>index.php"BACK</a>
			</td>
	  </tr>
	</table>

<?php?>

i hope as i understand your prob... this will help u...
Your Link Tag not closed in write Position....

echo "<tr>";
$result	 = $db->query("SELECT Crest FROM Crests ORDER BY Crest ");
$rowcount = -2;
while($images	= $db->fetch($result)){
$crestdisplay = $images['Crest'];
$rowcount = $rowcount + 1;
if($rowcount >10){echo"<TR></TR>"; $rowcount = 0;}
if($crestdisplay<>""){
echo "<td><a href=\"$crestdisplay\"><image src=images/$crestdisplay border=\"0\"width=50 height=50 alt="."></a> </td>";
}
}
echo "</tr>";
?>

if u want to access that image name onwhich user click so access that by Get method replace lines

echo "<td><a href=\"$crestdisplay\"><image src=images/$crestdisplay border=\"0\"width=50 height=50 alt="."></a> </td>";

with

echo "<td><a href=\"$crestdisplay?imagename=$crestdisplay\"><image src=images/$crestdisplay border=\"0\" width=50 height=50 alt="."></a> </td>";

Many thanks I did end up just busting out of php long enough to send an html href link using the url passing and Get function in the php setcrest. Since security wasnt needed you were right it was the simplest thing to do. Many thanks...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.