Professional Web Applications Themes

php variables are killing me - Macromedia Flash Data Integration

I'm using a WHERE condition in a SELECT clause of my query thats looking for 3 parameters. When I plug the WHERE condition with strings it works: mysql_connect(localhost, $username, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); // Get a specific result from the "example" table $result = mysql_query("SELECT * FROM allMeetings WHERE city = 'Boise, Idaho' AND day = 'Monday' AND time = '7:00a '") or die(mysql_error()); // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row //echo $row['city']." - ".$row['group']. "<br />"; echo ...

  1. #1

    Default php variables are killing me

    I'm using a WHERE condition in a SELECT clause of my query thats looking for 3
    parameters. When I plug the WHERE condition with strings it works:


    mysql_connect(localhost, $username, $password) or die(mysql_error());
    mysql_select_db($database) or die(mysql_error());

    // Get a specific result from the "example" table
    $result = mysql_query("SELECT * FROM allMeetings WHERE city = 'Boise,
    Idaho' AND day = 'Monday' AND time = '7:00a
    '")
    or die(mysql_error());

    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row
    //echo $row['city']." - ".$row['group']. "<br />";
    echo $row['city']." - ".$row['day']." - ".$row['time']." -
    ".$row['group']." - ".$row['address']." - ".$row['flag1']." - ".$row['flag2'].
    " - ".$row['flag3'].'<br />';
    }


    Now the fun part. If I replace the strings with variables it errors out:

    $fcity = "Boise, Idaho";
    $fday = "Monday";
    $ftime = "7:00a";


    mysql_connect(localhost, $username, $password) or die(mysql_error());
    mysql_select_db($database) or die(mysql_error());

    // Get a specific result from the "example" table
    $result = mysql_query("SELECT * FROM allMeetings WHERE day=$fday AND
    city=$fcity AND time=$ftime
    ") or die(mysql_error());


    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row
    //echo $row['city']." - ".$row['group']. "<br />";
    echo $row['city']." - ".$row['day']." - ".$row['time']." -
    ".$row['group']." - ".$row['address']." - ".$row['flag1']." - ".$row['flag2'].
    " - ".$row['flag3'].'<br />';
    }


    The above returns the following:
    You have an error in your SQL syntax near ' Idaho AND time=7:00a ' at line
    1


    I'm sure its something simple and stupid so if anyone can enlighten me I would
    be much obliged.

    Sean McMurtrey Guest

  2. #2

    Default Re: php variables are killing me

    Why are you asking this in a flash forum?

    "You have an error in your SQL syntax"

    Anyways, your variables need quotes for the query, try this instead ( var = "
    \ ' value ' \ " ; variable = double quote, slash, single quote, value, single
    quote, slash, double quote):

    $fcity = "\'Boise, Idaho\'";
    $fday = "\'Monday\'";
    $ftime = "\'7:00a\'";

    Cheers
    Gorka

    Gorka Ludlow Guest

Similar Threads

  1. killing session variables when closing browser
    By codenewbie in forum Macromedia ColdFusion
    Replies: 0
    Last Post: June 18th, 02:04 PM
  2. Many ASP.NET controls killing my CPU
    By Carlos in forum ASP.NET Building Controls
    Replies: 2
    Last Post: April 9th, 08:14 AM
  3. OSX- the slowness is killing me
    By sly one webforumsuser@macromedia.com in forum Macromedia Fireworks
    Replies: 4
    Last Post: October 9th, 11:00 PM
  4. HELP! BLOB is killing me
    By Kwan in forum Informix
    Replies: 1
    Last Post: July 18th, 05:15 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139