Unstoppable Domains

Php help

Spacemail by SpaceshipSpacemail by Spaceship
Watch

abcde

Established Member
Impact
16
help with serialize & unserialize

Please help me to find error and fix this php file. I'm a php newbie.

This is a php file allowed me to edit the database. I was able to pull it form the database, but when I submit it... the clues field got empty..

I know there's something wrong with the code, but dont know how to fix it... :'(

Please help ..
Thanks


PHP:
<?
if($_REQUEST['action'] == "edit")
{
   if (!isset($_POST["submit"]))
   {
      $id = $_REQUEST["id"];
      $sql = "SELECT * FROM taboo WHERE id=$id";
      $result = mysql_query($sql);  
      $r = mysql_fetch_array($result);
      list($c1, $c2, $c3, $c4, $c5) = unserialize($r['clues']);
      ?>
	  
      <form action="index.php" method="post">
      <input type=hidden name="id" value="<?php echo $r["id"] ?>">
Link: <input type="text" name="word" style="font-size: 10pt; font-weight: bold" size="41" VALUE="<? echo $r["word"] ?>"  autocomplete="off" /><br /><br />
Clue 1: <input type="text" name="clues" style="font-size: 10pt; font-weight: bold" size="41" VALUE="<? echo $c1 ?>"  autocomplete="off" /><br /><br />
Clue 1: <input type="text" name="clues" style="font-size: 10pt; font-weight: bold" size="41" VALUE="<? echo $c2 ?>"  autocomplete="off" /><br /><br />
Clue 1: <input type="text" name="clues" style="font-size: 10pt; font-weight: bold" size="41" VALUE="<? echo $c3 ?>"  autocomplete="off" /><br /><br />
Clue 1: <input type="text" name="clues" style="font-size: 10pt; font-weight: bold" size="41" VALUE="<? echo $c4 ?>"  autocomplete="off" /><br /><br />
Clue 1: <input type="text" name="clues" style="font-size: 10pt; font-weight: bold" size="41" VALUE="<? echo $c5 ?>"  autocomplete="off" /><br /><br />
Live: <input type="text" name="live" style="font-size: 10pt; font-weight: bold" size="41" VALUE="<? echo $r["live"] ?>"  autocomplete="off" /><br />
      <input type="hidden" name="action" value="edit">
      <input type="submit" name="submit" value="submit">
      </form>
   

<? } 
   if ($_POST["submit"])
   {
	  $word = $_POST["word"];
	  $clues = $_POST["clues"];
	  $live = $_POST["live"];
	  $id = $_POST["id"];
	  list($c1, $c2, $c3, $c4, $c5) = unserialize($r['clues']);
      //replace links with your table name above
	  $result = mysql_query("UPDATE taboo SET word='$word', clues='$clues', live='$live' WHERE id=$id")or die(mysql_error());
	  //header("location: index.php");
	  echo "Thank you! Information updated.";
	}
}
?>

I know there's something wrong with this code below, but Don't know how to fix it... :'(
PHP:
<? } 
   if ($_POST["submit"])
   {
	  $word = $_POST["word"];
	  $clues = $_POST["clues"];
	  $live = $_POST["live"];
	  $id = $_POST["id"];
	  list($c1, $c2, $c3, $c4, $c5) = unserialize($r['clues']);
      //replace links with your table name above
	  $result = mysql_query("UPDATE taboo SET word='$word', clues='$clues', live='$live' WHERE id=$id")or die(mysql_error());
	  //header("location: index.php");
	  echo "Thank you! Information updated.";
	}
}
?>
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
At first glance

you have 5 fields with the name clues maybe rename each one and repost the values

When your doing $_POST you are posting the name="clued" so it's trying to post all 5 even though the values are different. You may need to do a foreach or just rename them clue1, clue2 etc
 
0
•••
In PHP, if you have an array of fields you need to add brackets like this:
<input type="text" name="clues[]">
 
0
•••
Hi abcde,
if (!isset($_POST["submit"])) then $id = $_REQUEST["id"] will be empty, so $result will be empty too, so you can not have value of the clues , that is why the clues field got empty when you try to submit.
 
Last edited:
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Appraise.net
Unstoppable Domains
Domain Recover
NameMaxi - Your Domain Has Buyers
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back