Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 129299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:46:09+00:00 2026-05-11T05:46:09+00:00

I have another problem with my scripy now I have made it more advance,

  • 0

I have another problem with my scripy now I have made it more advance, first off the count function doesnt work properly and it gives this error.

Warning: array_push() [function.array-push]: First argument should be an array in C:\wamp\www\social\add.php on line 42

Here is my script:

$query = mysql_query('SELECT friends FROM users WHERE id='$myid''); $friends = mysql_fetch_array($query); $friends2 = unserialize($friends['friends']);  if (count($friends2) == 0) {  //option 1 $friends2 = array($id); $friendsUpdated = serialize($friends2); mysql_query('UPDATE users SET friends='$friendsUpdated' WHERE id='$myid'');  }else{  //option 2 array_push($friends2, $id); $friendsUpdated = serialize($friends2); mysql_query('UPDATE users SET friends='$friendsUpdated' WHERE id='$myid''); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:46:10+00:00Added an answer on May 11, 2026 at 5:46 am

    If you run this code right after having created the database but before putting any data in there, ‘unserialize($friends[‘friends’]);’ returns something other than an array. Probably an empty string. So in option 2, you may want to do something like this before array_push:

    if (!is_array($friends2)) {   $friends2 = array(); } 

    This way, if the person has no friends by this point (sad.. but you’ll fix it by pushing a new friend to them), an empty friends list gets initialized.

    Plus, any time you see two identical lines of code in different parts of the ‘if’ condition…

    $friendsUpdated = serialize($friends2); mysql_query('UPDATE users SET friends='$friendsUpdated' WHERE id='$myid''); 

    That’s a signal that you should restructure your code so that you’d only have one copy of these lines.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been struggling with Zend_Navigation all weekend, and now I have another problem, which
I have a problem where I'm trying to use a function from another module
Following on from a question I posted yesterday about GUIs, I have another problem
Okay, so I have another question on a prolog homework problem I am struggling
After getting a helpful answer here , I have run into yet another problem:
And another TreeView problem , should've used qt ;) I have a TreeView in
another ordered delivery problem. We have an orchestration which is bound to a send
I have a problem with .NET assembly redirection. 3rd party assembly A references another
here is the problem. I have one PC using VS2008 (SP1 ) and another
i have another piece for more advanced guys than me ;) I am developing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.