473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Undefined index

Hi, so this issue has been driving me crazy for the entire workday. I hope someone can help; I am sure it is trivial.
I am trying to access a user in a database based on their id. The id is auto incremented and thus unknown to the person accessing the user. I have created the functions below for accessing user information:
Expand|Select|Wrap|Line Numbers
  1.     function get_user_by_id($user) {
  2.         global $connection;
  3.         $query = "SELECT * ";
  4.         $query .= "FROM person ";
  5.         $query .= "WHERE personid=" . $user['id'] ." ";
  6.         $query .= "LIMIT 1";
  7.         $result_set = mysql_query($query, $connection);
  8.         confirm_query($result_set);
  9.         if ($user = mysql_fetch_array($result_set)) {
  10.             return $user;
  11.         } else {
  12.             return NULL;
  13.         }
  14.     }
  15.  
  16. And the function below uses the one above. 
  17.     function find_selected_user() {
  18.         global $user;
  19.         if (isset($_GET['id'])) { 
  20.         //get all info for user in database
  21.             $user = get_user_by_id($_GET['personid']);
  22.         } else {
  23.         //user doesn't exist in database -- return null? 
  24.             $user = NULL; 
  25.         }
  26.     }. 
  27.  
However, whenever I make an edit to the user, it does not make any sort of change to the database (the code for updating is not shown -- I think (*hope) the error is in the code above though).
Does anyone know why the user is not being updated? (I am assuming it is because the user is not even accessed).
Any help would be greatly appreciated!
Please let me know if I can clarify/elaborate on the question
May 14 '12 #1
3 1753
Rabbit
12,516 Expert Mod 8TB
Have you output the SQL string to see if it's being created correctly?

It's probably because on line 5, your $user variable, isn't an array, it's not going to have an id index.
May 14 '12 #2
@Rabbit
Oh, I didn't realise that. I had assumed it was an array consisting of all the information in the database corresponding to the selected user. Is there a way I can make the user's information into an array? Thanks for your help!
May 15 '12 #3
Rabbit
12,516 Expert Mod 8TB
You're thinking about the wrong thing. I'm talking about the $user variable that's being passed to the SQL. You're talking about what's being retrieved from the database. We're not even at that part yet.

I'm talking about line number 5, before anything even happens with the database, you're trying to access an index named id from the variable $user. That variable is just a string, the string that you passed into the function. The string that you pulled from the $_GET array with the index personid.
May 15 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: lawrence | last post by:
I just switched error_reporting to ALL so I could debug my site. I got a huge page full of errors. One of the most common was that in my arrays I'm using undefined offsets and indexes. These still...
5
by: news.bigpond.com | last post by:
getting errors Notice: Undefined index: name in F:\uni\Software engineering\assignment4\guestbook.php on line 6 the variable $name is declared as $name = _POST; What could be causing this?...
4
by: John Oliver | last post by:
PHP Notice: Undefined index: name in /home/www/reformcagunlaws.com/new.php on line 6 PHP Notice: Undefined index: address in /home/www/reformcagunlaws.com/new.php on line 7 PHP Notice: ...
3
cassbiz
by: cassbiz | last post by:
Here are the errors that are coming up in my error_log Notice: Undefined index: andatum in /zipcode.php on line 11 Notice: Undefined index: andatum in /zipcode.php on line 12 Notice: Undefined...
3
by: number1yan | last post by:
Can anyone help me, i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is: Notice:...
15
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about...
5
by: siyaverma | last post by:
Hi, I am new to php, i was doing some small chnages in a project developed by my collegue who left the job and i got the responsibility for that, After doing some changes when i run it on my...
3
by: sickboy | last post by:
$channels=$_GET; if (empty($channels)) { $channels='blank'; } changechannels($channels); $theatre=$_GET; if (empty($theatre)) { $theatre='splash'; } changetheatre($theatre); $info=$_GET; if...
3
by: razvanel442 | last post by:
Hi all i am new here! I take a look on forum but i don't found a the answer for my problem ok this is my problem: Line47:$user = $_GET; Line48:$pass = $_GET; Line49:$char = $_GET;
3
by: mediator | last post by:
Hello I have a php contact email form on my a ecommerce shop website ! I am getting a Undefined index error messages coming from the top of the php code, the email form its self works fine, ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.