0

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?>

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by honos1
0

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>";

Edited by Ezzaral: Fixed broken code tag.

0

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...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.