Member Avatar for Pityu

Hey.
I have the next problem:
I've created a joomla-like administrator page to a site I just have to make.
You can add, edit and delete products and categories.

Now, my problem is:
No matter which product or category u try to edit (it is listed in a table with picture of it, title and so, and generated a link like http://localhost/site/admin/admin.php?option=products&module=products&action=edit&id=191e3689-5a7d-11df-883f-cddef017a2e5 ) and when I edit the last added product it gets from mysql the data of it as well... Any other (not the last) product's editing page is empty.
I used

if($_GET['action']==edit)
{
  if($GET['id']==$r_id)
  { 
    Where $r_id => $row['id']
    // And here is the edit form
  }
}

________________

But when I try to edit the categorys, no matter what id has the $_GET, it will edit the last added...

I used mysql_fetch_array in all two cases.
I don't get it. I tried, but fail... Can't repair it...

So I have to ask you. Maybe the problem is @ the retrieving part.
Or somebody had problem like this...
Or ... Could lookup my codings...

Please?

Thanks for reading and for the help _ I assume _

Byezz

The small piece of code you gave, has some pretty strange coding:

Line 1 - edit is a constant???
Line 5 - Where, is this even a keyword or function ?????

Anyway, you can use the id retrieved from the GET and use that in the query that updates:

$id = $_GET['id'];
$query = "UPDATE table SET someval='$someval' WHERE id='$id'";

Also perhaps add a line that echoes what the value of $_GET is to see wheter the id is properly passed.

Explain your problem more clearly.

~G

Member Avatar for deleted1234

You are quite right. It might not be getting the correct id from your previous page. Try echoing your $_GET first to see if it's passing the value correctly.

Secondly, I don't understand the line 'Where $r_id => $row.' I think what you're trying to do is this:

$txtID = $_GET['id'];
if($_GET['action']=='edit'){
   $sql = "SELECT * FROM yourTable WHERE id='$txtID'";
   $result = mysql_query($sql);
   while($row = mysql_fetch_array($result)){
      //Your edit form
   }
}
Member Avatar for Pityu

Okay. So here is the full code...

if($_GET['action']==editeaza)
  {
	$retrieve = mysql_query("SELECT * FROM content WHERE sectiune='produse'");	
	$row = mysql_fetch_assoc( $retrieve );
	/* Retrieved info? */
	$r_id = $row['ID'];
	$r_title_ro = $row['title_ro'];
	$r_title_hu = $row['title_hu'];
	$r_keywords_ro = $row['keywords_ro'];
	$r_keywords_hu = $row['keywords_hu'];
	$r_description_ro = $row['description_ro'];
	$r_description_hu = $row['description_hu'];
	$r_class = $row['class'];
	$r_sectiune = $row['sectiune'];
	$r_descriere_ro = $row['descriere_ro'];
	$r_descriere_hu = $row['descriere_hu'];
	$r_categorie_ro = $row['categorie_ro'];
	$r_categorie_hu = $row['categorie_hu'];
	$r_poza = $row['poza'];
	$r_noutate = $row['noutate'];
	
	
	
	if($_GET['id']==$r_id)
	{
		
		$action = $_POST['action'];
		if($action == editeaza)
		{ 
		  /* Inserting data into MySQL */
		  $id = "UUID()";
		  $title_ro = $_POST['title_ro'];
		  $title_hu = $_POST['title_hu'];
		  $keywords_ro = $_POST['keywords_ro'];
		  $keywords_hu = $_POST['keywords_hu'];
		  $description_ro = $_POST['description_ro'];
		  $description_hu = $_POST['description_hu'];
		  $class = $_POST['class'];
		  $sectiune = "produse";
		  $descriere_ro = $_POST['descriere_ro'];
		  $descriere_hu = $_POST['descriere_hu'];
		  $categorie_ro = $_POST['categorie_ro'];
		  $categorie_hu = $_POST['categorie_hu'];
		  $noutate = $_POST['noutate'];
		  
			  
		  echo "<p class=\"note\">";
		  
		  switch ($title_ro) 
		  {
			  case "":
				  echo "Nem adtál meg román címet!<br>";
				  break;
		  }
		  
		  switch ($title_hu)
		  {
			  case "":
				  echo "Nem adtál meg magyar címet!<br>";
				  break;
		  }
		  
		  switch ($keywords_ro)
		  {
			  case "":
				  echo "Nem adtál meg román címkét!<br>";
				  break;
		  }
		  
		  switch ($keywords_hu)
		  {
			  case "":
				  echo "Nem adtál meg magyar címet!<br>";
				  break;
		  }
		  
		  switch ($description_ro)
		  {
			  case "":
				  echo "Nem adtál meg román kereső leírást!<br>";
				  break;
		  }
		  
		  switch ($description_hu)
		  {
			  case "":
				  echo "Nem adtál meg magyar kereső leírást!<br>";
				  break;
		  }
		  
		  switch ($class)
		  {
			  case "":
				  echo "Nem választottál színt!<br>";
				  break;
		  }
		  
		  switch ($descriere_ro)
		  {
			  case "":
				  echo "Nem írtál román leírást!<br>";
				  break;
		  }
		  
		  switch ($descriere_hu)
		  {
			  case "":
				  echo "Nem írtál magyar leírást!<br>";
				  break;
		  }
		  
		  switch ($categorie_ro)
		  {
			  case "":
		  
				  echo "Nem adtál meg román kategóriát!<br>";
				  break;
		  }
		  
		  switch ($categorie_hu)
		  {
			  case "":
				  echo "Nem adtál meg magyar kategóriát!<br>";
				  break;
		  }
		  
		  
		  
		  
		  if($title_ro !="" && $title_hu !="" && $keywords_ro != "" && $keywords_hu != "" && $description_ro != "" && $description_hu != "" && $class !="" && $descriere_ro !="" && $descriere_hu !="" && $categorie_ro !="" && $categorie_hu)
		  {
		  echo "Sikeresen módosítva!<br>";	
		  $update ="UPDATE content SET title_ro='$title_ro', title_hu='$title_hu', keywords_ro='$keywords_ro', keywords_hu='$keywords_hu', description_ro='$description_ro', description_hu='$description_hu', class='$class', descriere_ro='$descriere_ro', descriere_hu='$descriere_hu', categorie_ro='$categorie_ro', categorie_hu='$categorie_hu', noutate='$noutate', lastedit=SYSDATE() WHERE ID='$r_id'";
		  mysql_query($update);
		  }
		  else
		  {
			  die("<p class=\"error\">Nem töltötted ki a fentebb feltüntetett mezőket.<br>Ezt az ablakot ne zárd be, ha nem szeretnéd elveszteni az adatokat!<br><a href=\"javascript:history.go(-1)\">Klikk ide, ha vissza szeretnél menni az adatokhoz!</a></p>");
		  }
		
		}
	echo "<table border=\"0\" align=\"right\"><tr>";
	echo "<td align=\"center\">";
	echo "<a href=\"?optiune=produse&module=category\"><img src=\"style/images/notice/category.png\">";
	echo "<br>Categorie</a>";
	echo "</td><td align=\"center\">";
	echo "<a href=\"?optiune=produse&module=produse&action=sterge\"><img src=\"style/images/notice/sterge.png\">";
	echo "<br>Sterge</a>";
	echo "</td><td align=\"center\">";
	echo "<a href=\"../help.html#produse\" target=\"_blank\"><img src=\"style/images/notice/help.png\">";
	echo "<br>Ajutor</a>";
	echo "</td></tr></table><br>";
			
		echo "<form action=\"$PHP_SELF\" method=\"POST\" enctype=\"multipart/form-data\">";
		echo "<input type=\"hidden\" name=\"action\" value=\"editeaza\">\n" ;
		echo "<table border=\"0\">";
		echo "<tr>";
		echo "<td colspan=\"2\"><p>Termék ID-je / ID-ul produsului:<b><i>";  echo $r_id;  echo "</i></b></p></td>";
		echo "</tr>";
		echo "<tr>";
		echo "<td><p>Titlu Produs:</p></td>";
		echo "<td><input type=\"text\" name=\"title_ro\" value=\""; echo $r_title_ro; echo "\"></td>";
		echo "</tr>";
		
		echo "<tr>";
		echo "<td><p>Termék Címe:</p></td>";
		echo "<td><input type=\"text\" name=\"title_hu\" value=\""; echo $r_title_hu; echo "\"></td>";
		echo "</tr>";
		
		echo "<tr>";
		echo "<td><p>Keywords:</p></td>";
		echo "<td><textarea name=\"keywords_ro\">"; echo $r_keywords_ro; echo"</textarea></td>";
		echo "</tr>";
		echo "<tr>";
		echo "<td><p>Kulcsszavak:</p></td>";
		echo "<td><textarea name=\"keywords_hu\">"; echo $r_keywords_hu; echo"</textarea></td>";
		echo "</tr>";
		   
		echo "<tr>";
		echo "<td><p>Meta Descriere:</p></td>";
		echo "<td><textarea name=\"description_ro\">"; echo $r_description_ro; echo"</textarea></td>";
		echo "</tr>";
		echo "<tr>";
		echo "<td><p>Meta Leírás:</p></td>";
		echo "<td><textarea name=\"description_hu\">"; echo $r_description_hu; echo"</textarea></td>";
		echo "</tr>";
		
		echo "<tr>";
		echo "<td><p>Szín:</p></td>";
		echo "<td>";
		echo "<select style=\"text-align: center;\" name=\"class\" ><option value=''>Selecteaza Culoriile</option>
		<option value=\""; echo $r_class; echo "\" SELECTED>Selectat:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; echo $r_class; echo "</option>
		<option value='' style=\"font-weight: bold;\">----------------------------</option>
		<option value='red' style=\"font-weight: bold;\">Rosu</option>
		<option value='blue' style=\"font-weight: bold;\">Albastru</option>
		<option value='green' style=\"font-weight: bold;\">Verde</option>
		"; 
		echo "</select>";
		echo "</td>";
		echo "</tr>";
		
		echo "<tr>";
		echo "<td><p>Ujdonság:</p></td>";
		echo "<td>";
		echo "<select style=\"text-align: center;\" name=\"noutate\" >
		<option"; if($r_noutate==yes){ echo " SELECTED "; } echo "value='yes' style=\"font-weight: bold;\">Igen</option>
		<option"; if($r_noutate==no){ echo " SELECTED "; } echo "value='no' style=\"font-weight: bold;\">Nem</option>
		"; 
		echo "</select>";
		echo "</td>";
		echo "</tr>";
		
		echo "<tr>";
		echo "<td colspan='2' align='left'><p>Descriere:</p></td>";
		echo "</tr>";
		echo "<tr>";
		echo "<td colspan='2' align='left'><textarea name=\"descriere_ro\"  id=\"elm1\" style=\"width: 10%;\">"; echo $r_descriere_ro; echo "</textarea></td>";
		echo "</tr>";
		
		echo "<tr>";
		echo "<td colspan='2' align='left'><p>Leírás:</p></td>";
		echo "</tr>";
		echo "<tr>";
		echo "<td colspan='2' align='left'><textarea name=\"descriere_hu\"  id=\"elm2\" style=\"width: 10%;\">"; echo $r_descriere_hu; echo "</textarea></td>";
		echo "</tr>";
		
		
		echo "<tr>";
		echo "<td align='left'><p>Poza produsului / A termék képe:</p></td><td>";
		echo "<img src=\"../uploads/pics/thumbs/"; echo $r_poza; echo "\" alt=\""; echo $r_poza; echo "\"></td>" ;
		echo "</tr>";
		
		echo "<tr>";
		echo "<td><p>Categorie:</p></td>";
		echo "<td>";
		echo "<select style=\"text-align: center;\" name=\"categorie_ro\">
		<option value=\""; echo $r_categorie_ro; echo "\" SELECTED>Selectat:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		
		$selected = mysql_query("SELECT * FROM category WHERE ID='$r_categorie_ro'");	
		while($row = mysql_fetch_array( $selected  )){ echo $row['nume_ro'];}
		
		  echo "</option>";
		echo "<option value='' style=\"font-weight: bold;\">----------------------------</option>"; 
		$categorie = mysql_query("SELECT * FROM category");	
		while($row = mysql_fetch_array( $categorie )){	echo "<option value=\"".$row['ID']."\">".$row['nume_ro']."\n  ";}
		echo "</select>";
		echo "</td>";
		echo "</tr>";
		
		echo "<tr>";
		echo "<td><p>Kategória:</p></td>";
		echo "<td>";
		echo "<select style=\"text-align: center;\" name=\"categorie_hu\">
		<option value=\""; echo $r_categorie_hu; echo "\" SELECTED>Kiválasztva:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		
		$selected = mysql_query("SELECT * FROM category WHERE ID='$r_categorie_hu'");	
		while($row = mysql_fetch_array( $selected  )){ echo $row['nume_hu'];}
		
		  echo "</option>";
		echo "<option value='' style=\"font-weight: bold;\">----------------------------</option>"; 
		$categorie = mysql_query("SELECT * FROM category");	
		while($row = mysql_fetch_array( $categorie )){	echo "<option  value=\"".$row['ID']."\">".$row['nume_hu']."\n  ";}
		echo "</select>";
		echo "</td>";
		echo "</tr>";
		
		echo "<tr>";
		echo "<td colspan=\"2\" align=\"center\"><input type='submit' value='Megváltoztatom'><br><br></td>";
		echo "</tr>";
		
		echo "</table>";
		echo "</form>";
	}
  }
Member Avatar for diafol

I can't wade through all of that, but it seems that you are using a mixture of $_GET and $_POST. While you're able to send forms with querystrings, it's usually the case where these bits of data are included in a hidden input. POST variables are no more secure than querystring (GET) variables though.

Your first query only searches for the first result - i.e. it will always get this result, no matter what the querystring data.

"SELECT * FROM content WHERE sectiune='produse'"

You then make a comparison:

if($_GET['id']==$r_id)

I have to admit that this is very confusing. I don't really understand what you're trying to do with this first bit.

If you will print out the sql update string line, you may be able to find what you are looking for.

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.