Jump to content

Recommended Posts

Hi,

 

Is it possible to use an array to store a while loop? I am trying to retrieve some information from my database to store in an array.

 

I am trying to store about five of my customer id's, I thought this way was possible and that I had done it before. unfortunately I am getting the following error "Fatal error: [] operator not supported for strings" if possible please can someone point me in the right direction. Is there an easy for me to store all of the ids that come from the database?

 

My code so far...

 

$result = mysql_query("SELECT * FROM customers WHERE $search_field = \"$search_term\"")

or die(mysql_error()); 

 

 

while($row = mysql_fetch_array( $result )) {

 

 

$customer_id[] =  $row['id'];

 

 

}

 

Thank you

:D

Link to comment
https://forums.phpfreaks.com/topic/238723-using-array-to-store-a-while-loop/
Share on other sites

Hi, thank you for the help :) What would be the best way of doing this that wouldn't lead to being hacked?

 

 

If you're not doing so already, you should use the mysql_real_escape_string() on $search_term before querying the database. For more information, visit http://php.net/manual/en/function.mysql-real-escape-string.php

It also appears that you are letting the user determine the outcome of $searchfield

 

Good point, I was assuming that variable was populated by the program. If $searchfield contains data entered/selected by the user, make sure it's a valid choice.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.