Reputation: 4557
I am using the following script for appending the serialized array
mysql_select_db("formdemo", $con);
$result=mysql_query("select * from rohit where fid='$y'");
if(mysql_num_rows($result)!=0)
{
if($result)
{
while($row=mysql_fetch_array($result))
{
$n=$row['tags'];
$a=explode(',', $n);
print_r($a);
$cnt=count($a);
$x=unserialize($row['data']);
for($i=0;$i<$cnt;$i++)
{
$d=$_GET[$a[$i]];
array_push($x,$d);
}
array_push($x,"<br/>");
}
}
}
$str=serialize($x);
$sql="update rohit set data='$str' where fid='$y'";
if(!mysql_query($sql,$con))
die(mysql_error());
else
echo "Your data has been updated successfully\n";
when i am running this for the first time when database is empty, then it is giving an error: array_push() expects parameter 1 to be array, and store a value b;0 in database. what should i do in this situation. please help...
Upvotes: 0
Views: 78
Reputation: 174967
The simplest solution would be to initialize your variable $x
with an array, before you start processing. But please review my comment Here
Upvotes: 1