NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page php help

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Reply
 
LinkBack Thread Tools
Old 11-13-2009, 04:44 AM THREAD STARTER               #1 (permalink)
NamePros Regular
Join Date: Feb 2005
Posts: 578
abcde is a jewel in the roughabcde is a jewel in the roughabcde is a jewel in the rough
 



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 Code:
<?
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 />
????: NamePros.com http://www.namepros.com/programming/622795-php-help.html
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 Code:
<? 
   if (
$_POST["submit"])
   {
      
$word $_POST["word"];
      
$clues $_POST["clues"];
      
$live $_POST["live"];
      
$id $_POST["id"];
????: NamePros.com http://www.namepros.com/showthread.php?t=622795
      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 by abcde; 11-13-2009 at 05:24 AM.
abcde is offline   Reply With Quote
Old 11-13-2009, 07:08 AM   #2 (permalink)
NamePros Regular
Join Date: Jan 2008
Posts: 209
CrazyCanuck will become famous soon enoughCrazyCanuck will become famous soon enough
 



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
CrazyCanuck is offline   Reply With Quote
Old 11-13-2009, 07:50 AM   #3 (permalink)
Domains my Dominion
 
sdsinc's Avatar
Join Date: Aug 2005
Location: Web 1.0
Posts: 9,963
sdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatness
 


Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer Animal Rescue Wildlife
In PHP, if you have an array of fields you need to add brackets like this:
<input type="text" name="clues[]">
__________________
NameNewsletter.com - free lists of available domain names
ZoneFiles.net (beta) - ccTLD and gTLD droplists
sdsinc is offline   Reply With Quote
Old 11-13-2009, 03:06 PM   #4 (permalink)
NamePros Member
Join Date: Dec 2008
Posts: 60
foryounow is on a distinguished road
 



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.
__________________
Professional PHP website services: http://install-php-scripts.com
Last edited by foryounow; 01-28-2010 at 06:45 AM.
foryounow is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:33 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger