473,322 Members | 1,562 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,322 software developers and data experts.

An "Undefined Variable" Problem - or even more simple?

This has got to be one of those questions only a serious newbie would come up with....

Basicly: I select all the city names in the table and turn them into a pull down menu (code below)
Expand|Select|Wrap|Line Numbers
  1. print "<form action=\"update-city.php\" method=\"post\" name=\"theform\">";
  2. print "<SELECT id=\"city\">\n";
  3.  
  4.     while ($row =mysql_fetch_object($result)) {
  5.  
  6.     foreach ($row as $col=>$val){
  7.     print "<option value=\"\n";
  8.     print $val ;
  9.     print "\">";
  10.     print $val ;
  11.     print "</option>\n";
  12.     }
  13. }
  14. print "</select>\n";
  15. ?>
  16. <!-- Finish the form -->
  17. <input type="submit" name="action" value="Update City">
  18. </form>
  19.  
Then I'm playing with it (working up the way to update) but all the variables seem empty. (Here's code for a simple table)

Expand|Select|Wrap|Line Numbers
  1. $sql = "SELECT city_name, city_default_zip, seatac_price, boeing_price FROM char_city WHERE city_name = ('$city')";
  2. $result = mysql_query($sql) 
  3.   or die(mysql_error());
  4.  
  5. <table border="1">
  6.     <tr>
  7.         <td>City Name</td>
  8.         <td>Default Zip Code</td>
  9.         <td>Seatac Price</td>
  10.         <td>Boeing Price</td>
  11.     </tr>
  12. <? 
  13. while ($row =mysql_fetch_assoc($result)) {
  14. $lshit[] = $cityList[$row['id']] = $row['city_name'];
  15. $shit[] = $cityList[$row['id']] = $row['city_default_zip'];
  16. $mshit[] = $cityList[$row['id']] = $row['seatac_price'];
  17. $bshit[] = $cityList[$row['id']] = $row['boeing_price'];
  18.     print "<tr>\n";
  19.  
  20.     foreach ($row as $col=>$val){
  21.     print "<td>\n";
  22.     print $val ;
  23.     print "</td>\n";
  24.  
  25. }//end for each
  26.     print "</tr>\n";
  27. }//end while
  28. ?>
  29. </table>
As you can see - it doesn't get any more simple.... So why doesn't it work? And what's really got me whacked out... Why doesn't it work in IE 6 or 7 - Yet works just fine in FireFox?

I read the forum sticky before posting so for some more info...
I installed...
error_reporting(E_ALL);
ini_set('display_errors', True);

Which now gives me "Notice: Undefined index: city in /home/content......" For both IE and FireFox - but Firefox at least still fills out the table...

I also tried....
Expand|Select|Wrap|Line Numbers
  1. $sql = "SELECT city_name, city_default_zip, seatac_price, boeing_price FROM char_city WHERE city_name = ('$_POST[city]')";
(and a few variations of where to put the quote)
and
Expand|Select|Wrap|Line Numbers
  1. $city = $_POST['city'];
  2. $sql = "SELECT city_name, city_default_zip, seatac_price, boeing_price FROM char_city WHERE city_name = ('$city')";
Plus: I pulled the following out of a book regarding the global variables....
foreach
Expand|Select|Wrap|Line Numbers
  1. ($_POST as $key => $value) {
  2.   $$key = $value;
  3. }
[Please use CODE tags when posting source code. Thanks! --pbmods]

Watch. I'm missing some little punctuation mark or something -

Anybody see my problem?
Jun 23 '07 #1
6 2421
pbmods
5,821 Expert 4TB
Heya, SuperFool. Welcome to TSDN!

What is the problem you are having? If it's working in one browser, but not another, then the problem is not the PHP (though it could be the HTML).
Jun 23 '07 #2
Heya, SuperFool. Welcome to TSDN!

What is the problem you are having? If it's working in one browser, but not another, then the problem is not the PHP (though it could be the HTML).
Thanks.

I'm upset with myself over how much time I'm spending on this problem - however the more I learn about PHP the more excited I get about the possibilities.

My problem is that while all variations I've created on this attempt work fine in FireFox - they come up blank in both IE 6 & 7, which unfortunately runs about 88% of the visitors, so as cool as it is for my friend - it's useless if IE can't see it.

Right now, I'm just trying to make it work - I'm able to make it pretty later. It's just trying to get a grasp on it with nothing more than me and a couple books is pretty difficult. Maybe if I started on chapter 1... but then that wouldn't be me - I'm more foolish than that.

Back to the subject at hand....
When I input the display error code bit I found in the sticky for this forum - I keep getting told "Notice: Undefined variable: name in /home/content...blah, blah"

So I guess it's a matter of trying to print every variable name I can come up with. Well, that's a decent way to learn I guess. I can't imaging that I have to build a giant list of IF THEN statements for every possible city that could be chosen from the pull down menu - that seems to just contradict the purpose.

I'll figure it out - I just welcome a place to ask some questions occasionally.
Thanks for your insight
Jun 23 '07 #3
pbmods
5,821 Expert 4TB
Heya, SuperFool.

Instead of mysql_fetch_object(), try using mysql_fetch_assoc().

mysql_fetch_object() returns an object, not an array.

As for why it's coming up blank in IE, are you accessing the same server on each computer? In other words, are you typing 'localhost' in the address bar, but using a different computer?
Jun 23 '07 #4
Hello pbmods


Instead of mysql_fetch_object(), try using mysql_fetch_assoc().

mysql_fetch_object() returns an object, not an array.
Nope - No change. I used object a while ago because assoc gave me duplicate results of everything.

As for why it's coming up blank in IE, are you accessing the same server on each computer? In other words, are you typing 'localhost' in the address bar, but using a different computer?
I'm doing everything on the server - not using my local machine for anything but Dreamweaver - well that and FTP to upload it to the server.

Accessing the db is set up through include commands - so no danger of mistyping anything from one to the other.

And now, I've managed to play with it enough to break FireFox for this now as well.

I've added a table, where I've tried to list out every variable I can think of, but of course they all come up blank too.

thanks again
Jun 23 '07 #5
pbmods
5,821 Expert 4TB
Heya, SuperFool.

Ok, let's start from the beginning. What happens when you:

Expand|Select|Wrap|Line Numbers
  1. var_dump($city);
  2.  
If $city is empty, you will get no results from your query, unless there are entries where city_name is empty.

Next:
Expand|Select|Wrap|Line Numbers
  1. print($sql);
and try manually running that query in your MySQL client. Do you get any results?

Next:
Expand|Select|Wrap|Line Numbers
  1. var_dump($result);
and make sure that mysql_query() is returning the proper value.

Next:
Expand|Select|Wrap|Line Numbers
  1. or die(mysql_error());
  2. // Add this line:
  3. print('!');
after your die() statement to make sure that your code is executing properly.

At this point, the HTML in your script HAS to be getting output.

Next, make sure your mysql_query returned the proper results.
Expand|Select|Wrap|Line Numbers
  1. while($row = mysql_fetch_assoc($result)) {
  2.     // Add this line:
  3.     print('<pre>' . print_r($row, true) . '</pre>');
  4. .
  5. .
  6. .
  7.     print('<hr />');
  8. }
That's my reaction at this point. Somewhere, something isn't doing what it's supposed to. Welcome to unit testing. Fun stuff, huh?
Jun 24 '07 #6
Previous Post Deleted.............. I'll try this again.....
Jun 24 '07 #7

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

Similar topics

1
by: JKop | last post by:
Would you classify the following code as "Undefined Behaviour" or as "Non- portable"? signed main() { signed char chedder = 130; } Relevant information:
13
by: Don Vaillancourt | last post by:
What's going on with Javascript. At the beginning there was the "undefined" value which represented an object which really didn't exist then came the null keyword. But yesterday I stumbled...
25
by: Nitin Bhardwaj | last post by:
Well, i'm a relatively new into C( strictly speaking : well i'm a student and have been doing & studying C programming for the last 4 years).....and also a regular reader of "comp.lang.c" I...
4
by: Friday | last post by:
Being an Old L.A.M.P guy, I beg you to please excuse my ignorance of dot.net (and all things Windows, for that matter). As part of an experiment (to learn enough ASP/VB.net to port a series of ...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
5
by: Jason | last post by:
Hello, I am trying to dynamically create a table, then set its <td>'s onclick: var table = document.createElement("table"); var row = table.insertRow(-1); var td = row.insertCell(-1);...
26
by: Frederick Gotham | last post by:
I have a general idea of the different kinds of behaviour described by the C Standard, such as: (1) Well-defined behaviour: int a = 2, b = 3; int c = a + b; (Jist: The code will work...
5
by: Nathan Sokalski | last post by:
I have an ASP.NET application which is giving the following JavaScript error: 'theForm' is undefined However, when I do a View Source one of the <scriptelements is as follows: <script...
5
by: Pseudonyme | last post by:
Dear All : Ever had an httpd error_log bigger than the httpd access log ? We are using Linux-Apache-Fedora-Httpd 2006 configuration. The PHP lines code that lead too tons of errors are : ...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.