hello I've been working with Mysql PHP for a little while and cn't figure out why after putting my data into MYSQL the array can't unserialize. Here is a code sample:
$gigemail = "email";
$gigs = array(1=>"John\'s", 2=>"Joe\'s");
$gigaddress = "";
$gigcity= "";
$gigstate = "";
$gigcountry = "";
$gigzip = "";
$gigtimedate = "";
$gigcover = "";
$gigcomment = "";
$newgigs = @serialize($gigs);
echo $newgigs;
$trying = @unserialize($newgigs);
echo $trying[1];
I wrote this for debugging purposes.
The above $newgigs echoes the entire array which is what I want.
The above $trying[1] echoes "John\'s" which is correct However:
When I enter the above into mysql using this, it doesn't unserialize the array, it print_r the array but doesn't unserialize it.
mysql_connect("localhost" , "00000000" , "0000000")
or die('Database is not responding.');
mysql_select_db("00000000") or die('Unable to connect to database');
mysql_query("UPDATE giglists SET gigs = '$newgigs', gigaddress = '$gigaddress', gigcity = '$gigcity', gigstate = '$gigstate', gigcountry = '$gigcountry', gigzip = '$gigzip', gigtimedate = '$gigtimedate', gigcover = '$gigcover', gigcomments = '$gigcomment' WHERE gigemail = '$gigemail'") or die ('Could not connect to database' . mysql_error());;
mysql_query("UPDATE Userinfo SET gigs = '' WHERE email = '$gigemail'") or die ('Could not connect to database' . mysql_error());;
mysql_close();
mysql_connect("localhost" , "00000000" , "0000000")
or die('Database is not responding.');
mysql_select_db("00000000") or die('Unable to connect to database');
$match2 = "SELECT gigs, gigtimedate, gigcover, gigcomments, gigstate, gigcity, gigaddress, gigcountry, gigzip FROM giglists WHERE gigemail = '$gigemail'";
$qry2 = mysql_query($match2)
or die('Could not match data because of database error' . mysql_error());;
$num_rows2 = mysql_num_rows($qry2);
while ($row2 = mysql_fetch_array($qry2)){
print_r($row2['gigs']);
$newgigs = unserialize($row2['gigs']);
}
echo $newgigs[1];
The above print_r($row2['gigs']) prints the array in the row "gigs", correwct.
When I try to unserialize it doesn't echo anything, but it should echo John's.
Any suggestions. I found a topic on another site that is almost exactly like this if someone could check it out.
http://www.phpfreaks.com/forums/index.php?topic=125030.0
Thanks in advance for any help you can provide.