1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2007
    Rep Power

    Why is a variable coming up as undefined when I defined it?


    When I run this code, it says
    "FAIL: UPDATE colleges SET latitude=1, longitude=4 WHERE index='' LIMIT 1 BECAUSE: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'index='' LIMIT 1' at line 1"

    I think the problem is with the $b variable, although I don't understand why this is so, as you can see, I defined it. Any ideas on how to fix this problem? Thanks

    PHP Code:
    <?php $con mysql_connect("localhost","root",""); if (!$con) {     die('Could not connect: ' mysql_error()); }  mysql_select_db("test2"$con);  $sql "SELECT institution_address, institution_city, institution_name, institution_state, institution_zip FROM colleges"$result mysql_query($sql); $total_rows mysql_num_rows($result); var_dump($total_rows); echo $total_rows$b 1;  while ($row mysql_fetch_assoc($result)) {            for ($i=1$i<=30$i++){           $uql "UPDATE colleges SET latitude=1, longitude=4  WHERE index='{$row['" . $b . "']}' LIMIT 1";    $ues mysql_query($uql) or die("FAIL: $uql BECAUSE: " mysql_error());           echo $b;           $b++;                                 $total_rows 30;          }  sleep(2);       }         ?>
  2. #2
  3. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Washington, USA
    Rep Power
    "index" is a reserved word in MySQL. If you want to use it as a name then it has to be quoted.
    UPDATE colleges SET latitude=1, longitude=4 WHERE `index`='' LIMIT 1
    Also, next time you post PHP code don't enter it into the popup you get when you click that one button. Paste your code into the textarea, select it, and then click the button. Or manually type &amp;#91;php] and [/php] around it.
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Pennsylvania, USA
    Rep Power
    To be clear, it needs to be enclosed in `backticks,` not 'quotes'.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo