Php help

SpaceshipSpaceship
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
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
Close
In PHP, if you have an array of fields you need to add brackets like this:
<input type="text" name="clues[]">
 
0
Close
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
Close
DomainEasy: white label portfolios are live. Enable yours.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Filters for activity feeds
Your news feed, Latest activity, and the activity tab on profiles now have filter buttons: All, Posts, Quick replies, and Other. Your...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back