Jump to content

[SOLVED] unserialize help, getting errors


n000bie

Recommended Posts

hi all ,

I got a form with 6 fields (2 input and 4 select box), when the page loads one block is shown and through javascript all the fields can be copied multiple times so I need to store the data in array (got hint from here -> http://www.evolt.org/node/60222 ), I manage to save the data but while displaying i get lot of errors

 

Notice: unserialize() [function.unserialize]: Error at offset 0 of 1 bytes in C:\wamp\www\artus\testme.php on line 67

 

Notice: unserialize() [function.unserialize]: Error at offset 9 of 10 bytes in C:\wamp\www\artus\testme.php on line 67

 

this is my php code

 

<?php
////////////////////////////function defination///////////////////////
function showMonth()
{
$arr=array("January","February","March","April","May","June","July","August","September","October","November","December");
for($i=0;$i<count($arr);$i++)
{
	echo "<option value='".$arr[$i]."'>".$arr[$i]."</option>";
}	
}
function showYear()
{
$d=getdate();
$curYear=$d['year'];
for($i=$curYear;$i>($curYear-50);$i--)
{
	echo "<option value='".$i."'>".$i."</option>";
}	
}
// connect to database 
define("HOST","localhost");
define("USER","root");
define("PASS","");
define("DATABASE","artuscom");




$con = mysql_connect(HOST,USER,PASS);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db(DATABASE, $con);

// ends here 

// start post 


if (isset($_POST['submit']))
{
$org = serialize($_POST['curEmpName']);
$des = serialize($_POST['curEmpDesignation']);
$start_month = serialize($_POST['curEmpStartMonth']);
$start_year = serialize($_POST['curEmpStartYear']);
$end_month = serialize($_POST['curEmpEndMonth']);
$end_year = serialize($_POST['curEmpEndYear']);


$query="Insert into artus_test values('','$org','$des','$start_month','$start_year','$end_month','$end_year')";
$result=mysql_query($query);

if ($result) {
echo 'success';
} else { echo 'something failed...';}
}

// show records 
if (isset($_POST['showrecord']))
{
$query='SELECT * FROM artus_test';
$result=mysql_query($query);


	while($row = mysql_fetch_assoc($result)){
	echo "ID: ".unserialize($row['test_id']).", Organization:".unserialize($row['organ']).", Designation:".unserialize($row['design']).", Start-month:".unserialize($row['start_month']).", Start-year:".unserialize($row['start_year']).", End-month:".unserialize($row['end_month']).", End-year:".unserialize($row['end_year'])."<br/>";		
	}

}
?>

 

can anyone help please

Link to comment
https://forums.phpfreaks.com/topic/180733-solved-unserialize-help-getting-errors/
Share on other sites

I used print_r in place of unserialize and changed this code and removed unserialize from Id and now i am getting those outputs

 

a:1:{i:0;s:0:"";}a:1:{i:0;s:0:"";}a:1:{i:0;sa:1:{i:0;sa:1:{i:0;sa:1:{i:0;sID: 2, Organization:1, Designation:1, Start-month:1, Start-year:1, End-month:1, End-year:1
a:2:{i:0;s:5:"test1";i:1;s:5:"a:2:{i:0;s:5:"test1";i:1;s:5:"a:2:{i:0;sa:2:{i:0;sa:2:{i:0;sa:2:{i:0;sID: 3, Organization:1, Designation:1, Start-month:1, Start-year:1, End-month:1, End-year:1

 

while($row = mysql_fetch_assoc($result)){
	echo "ID: ".$row['test_id'].", Organization:".print_r($row['organ']).", Designation:".print_r($row['design']).", Start-month:".print_r($row['start_month']).", Start-year:".print_r($row['start_year']).", End-month:".print_r($row['end_month']).", End-year:".print_r($row['end_year'])."<br/>";		
	}

 

this is my html code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form name="form1" method="post" action="">
<div style="border:2px solid red; margin-bottom:20px;" id="copyme">
<td height="50"><em>* </em>Organization Name<br /></td>
    <td colspan="2">
      <input type="text" maxlength="64" size="35" name="curEmpName[]" class="required" title="Please enter organization name" value=""/>         </td>
    <td> </td>
  </tr>
  <tr>
    <td height="50"><em>* </em>Designation</td>
    <td colspan="2"><input type="text" maxlength="64" size="35" name="curEmpDesignation[]" class="required" title="Please enter your designation" value=""/></td>
    <td> </td>
  </tr>
  <tr>
    <td height="50"><em>* </em>Time Period: <br />    </td>
    <td ><select name="curEmpStartMonth[]" class="validate-selection" title="Please select your Time period">
      <option selected="selected" value="-1">Month </option>
      <?php showMonth();?>
    </select></td>
    <td width="75"><select name="curEmpStartYear[]" class="validate-selection" >
      <option selected="selected" value="-1">Year </option>
      <?php showYear();?>
    </select></td>
    <td>to <select name="curEmpEndMonth[]" >
      <?php $d=getdate();?>
      <option selected="selected" value="<?php echo $d['month'];?>"><?php echo $d['month'];?> </option>
    </select>
      <select name="curEmpEndYear[]"  >
        <option selected="selected" value="<?php echo $d['year'];?>"><?php echo $d['year'];?> </option>
      </select></td>
      </div>
      <div id="copyhere"></div>
      <a href="javascript: copyTrue();">Add more</a>
      <input name="submit" type="submit" value="submit" />
      <input name="showrecord" type="submit" value="Show Record" />
</form>
</body>
</html>
<script>
function copyTrue(){
var t = document.getElementById('copyme').cloneNode(true);
document.getElementById('copyhere').appendChild(t);
}
</script>

 

 

well now when i changed my column data type to MEDIUMTEXT it is not showing any errors with unserialize()

 

echo "ID: ".$row['test_id'].", Organization:".unserialize($row['organ']).", Designation:".unserialize($row['design']).", Start-month:".unserialize($row['start_month']).", Start-year:".unserialize($row['start_year']).", End-month:".unserialize($row['end_month']).", End-year:".unserialize($row['end_year'])."<br/>";		
	}

 

this code shows

ID: 7, Organization:Array, Designation:Array, Start-month:Array, Start-year:Array, End-month:Array, End-year:Array

 

now only problem is how to show the data from those array

 

just give me a hint pleaseeeeeeee  :'(

 

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.