Jump to content

help with serialize & unserialize


abitshort

Recommended Posts

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 don't know how to fix it... :'(

 

Please help ..

Thanks

 

   <?
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.";
    }
}
?> 

 

 

Link to comment
https://forums.phpfreaks.com/topic/181445-help-with-serialize-unserialize/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.