noisyscanner
03-12-2010, 12:41 PM
Hello all!
I have a script that SHOULD add friends to a users account by:
Checking the db to see if he has any friends.
If he doesn't, initialize an array with the friend he wants to add: array($friend);
If he has friends already, unserialize his friends array $friends = unserialize($row['friends']) and ARRAY_PUSH() the new friend on the end then serialize it:
serialize(array_push($friends,$friend))
Then insert it into my DB.
What I don't get is the fact that in my db one time i get "a:1:{i:0;s:9:"some_user";}" next time i get "i:2;" then if I add another friend i get "b:0;"
HERE IS MY SCRIPT:
<?php
session_start();
if($_GET[cmd] == "friend"){
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("user_db") or die(mysql_error());
$friend = $_GET['friend'];
$find_friends = mysql_query("SELECT * FROM tablename WHERE user='$_SESSION[username]'");
while ($row = mysql_fetch_array( $find_friends )) {
if($row['friends'] == "")
{
$new_friend_array = array($friend);
}
else
{
$new_friend_array = array_push(unserialize($row['friends']),$friend);
}
print_r(unserialize($row['friends']));
print_r(array_push(unserialize($row['friends']),$friend));
}
$new_friend_array_serial = serialize($new_friend_array);
echo $new_friend_array_serial;
print_r(unserialize($new_friend_array_serial));
mysql_query ("UPDATE tablename SET friends='$new_friend_array_serial' WHERE user='$_SESSION[username]'") or die (mysql_error());
header("Location: ../user/$_SESSION[username]&msg=$friend is now your friend!");
}
?>
This seems strange.. very strange. Hopefully somebody knows the answer to this question!!
My php version is: 5.2.8
Thanks,
Noisyscanner:o:):confused::(:thumbsup::eek::cool::rolleyes::mad::p
I have a script that SHOULD add friends to a users account by:
Checking the db to see if he has any friends.
If he doesn't, initialize an array with the friend he wants to add: array($friend);
If he has friends already, unserialize his friends array $friends = unserialize($row['friends']) and ARRAY_PUSH() the new friend on the end then serialize it:
serialize(array_push($friends,$friend))
Then insert it into my DB.
What I don't get is the fact that in my db one time i get "a:1:{i:0;s:9:"some_user";}" next time i get "i:2;" then if I add another friend i get "b:0;"
HERE IS MY SCRIPT:
<?php
session_start();
if($_GET[cmd] == "friend"){
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("user_db") or die(mysql_error());
$friend = $_GET['friend'];
$find_friends = mysql_query("SELECT * FROM tablename WHERE user='$_SESSION[username]'");
while ($row = mysql_fetch_array( $find_friends )) {
if($row['friends'] == "")
{
$new_friend_array = array($friend);
}
else
{
$new_friend_array = array_push(unserialize($row['friends']),$friend);
}
print_r(unserialize($row['friends']));
print_r(array_push(unserialize($row['friends']),$friend));
}
$new_friend_array_serial = serialize($new_friend_array);
echo $new_friend_array_serial;
print_r(unserialize($new_friend_array_serial));
mysql_query ("UPDATE tablename SET friends='$new_friend_array_serial' WHERE user='$_SESSION[username]'") or die (mysql_error());
header("Location: ../user/$_SESSION[username]&msg=$friend is now your friend!");
}
?>
This seems strange.. very strange. Hopefully somebody knows the answer to this question!!
My php version is: 5.2.8
Thanks,
Noisyscanner:o:):confused::(:thumbsup::eek::cool::rolleyes::mad::p