SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot Nu1's Avatar
    Join Date
    Jul 2000
    Location
    California
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Having trouble with php and MySQL

    Hey folks, I am having trouble with PHP & MySQL. I have this page which I am working on which will give users a choice of city they want to see. I have provided them with a pull down menu of cities and a button to submit.

    After submitting they get a a page which is supposed to have the city name at the top and is also supposed to pull all events about that city from MySQL. The city name does pull but the events don't. I have laid out the scripts on this post for anyone who can help me. Thanks!!!

    I have not included the HTML as I think it is not important.

    This page asks user to choose a city:
    ============================================
    <?php
    # set your cookie here
    setcookie ("city_name", $_GET[city_name],time()+3600);
    ?>

    <form method="post" action="city.php">
    <select name="city_name">
    <option>city 1</option>
    <option>city 2</option>
    </select>
    <input type="submit" value="Submit">
    </form>
    ============================================
    END OF PAGE

    This page appears with name of city but is having trouble pulling the events that go with that city:
    ============================================
    <?php
    // db login details
    include("db_login.php");
    $city = $_POST['city_name'];
    // display events for this city
    $sql = "SELECT * FROM Events_tbl,0,city_name";
    $result = mysql_query($sql);
    ?>


    <?php

    while ($data = mysql_fetch_array($result)) {
    $event_name = $data["event_name"];
    $event_date = $data["event_date"];
    $event_time = $data["event_time"];
    $event_desc = $data["event_details"];
    echo("<tr>" );
    echo("<td>$event_name</td><td>$event_date</td><td>$event_time</td><td>$event_desc</td>" );
    echo("</tr>" );
    }
    ?>
    ============================================

    The following error is coming on the part of the page where the events should pop up:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/city.php on line 128
    "Don't sweat the small stuff"

  2. #2
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Blend the last to snippets together:
    PHP Code:
    $sql "SELECT * FROM Events_tbl,0,city_name";
    $result mysql_query($sql);
    while (
    $data mysql_fetch_array($result)) { 
    Also, what is the ,0, for?
    If knowledge is power - Why isn't our army librarians?!
    Statistics show that 63% of all statistics are fake.
    When i was little i broke my neck, and i havent looked back since .
    I completed the internet in 1 week. The end boss was pretty easy though .

  3. #3
    SitePoint Zealot Nu1's Avatar
    Join Date
    Jul 2000
    Location
    California
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Not sure what 0 is for?

    Quote Originally Posted by 1337-Dev
    Blend the last to snippets together:
    PHP Code:
    $sql "SELECT * FROM Events_tbl,0,city_name";
    $result mysql_query($sql);
    while (
    $data mysql_fetch_array($result)) { 
    Also, what is the ,0, for?
    I have to figure it out. The script was given to me but I was having trouble figuring that one out.

    Thanks for your help, I'll give it a try.

    Nu1
    "Don't sweat the small stuff"

  4. #4
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heh.
    Also:
    PHP Code:
    $sql "SELECT * FROM Events_tbl,0,city_name"
    Should it be something like:
    PHP Code:
    $sql "SELECT * FROM Events_tbl ('city_name', 'that_city_info_column')"
    Or some sort of query to grab the 2 columns with the city name AND city info. Dont think you need the 0 either .
    If knowledge is power - Why isn't our army librarians?!
    Statistics show that 63% of all statistics are fake.
    When i was little i broke my neck, and i havent looked back since .
    I completed the internet in 1 week. The end boss was pretty easy though .

  5. #5
    SitePoint Zealot Nu1's Avatar
    Join Date
    Jul 2000
    Location
    California
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    still having trouble

    Quote Originally Posted by 1337-Dev
    Heh.
    Also:
    PHP Code:
    $sql "SELECT * FROM Events_tbl,0,city_name"
    Should it be something like:
    PHP Code:
    $sql "SELECT * FROM Events_tbl ('city_name', 'that_city_info_column')"
    Or some sort of query to grab the 2 columns with the city name AND city info. Dont think you need the 0 either .
    Here is what I have:
    <?php
    // db login details
    include("db_login.php");
    $city = $_POST['city_name'];
    // display events for this city
    $sql = "SELECT * FROM Events_tbl,city_name";
    $result = mysql_query($sql);
    while ($data = mysql_fetch_array($result)) {
    ?>

    Do I need to put something after the { ?
    I am getting an error on line 166 which happens to be where the </html> tag is at on the page. Any thoughts?

    Thanks!
    "Don't sweat the small stuff"

  6. #6
    <? james('rules'); ?>
    Join Date
    Jun 2004
    Location
    Wales, UK
    Posts
    788
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yah you missed the closing brace (}), try this:
    PHP Code:
    <?php
    // db login details
    include("db_login.php");
    $city $_POST['city_name'];
    // display events for this city
    $sql "SELECT * FROM Events_tbl,0,city_name";
    $result mysql_query($sql);
    while (
    $data mysql_fetch_array($result)) {
    $event_name $data["event_name"];
    $event_date $data["event_date"]; 
    $event_time $data["event_time"]; 
    $event_desc $data["event_details"]; 
    echo 
    "<tr>";
    echo 
    "<td>$event_name</td><td>$event_date</td><td>$event_time</td><td>$event_desc</td>";
    echo 
    "</tr>";
    }
    ?>
    Thats the combination. Notice how i removed brackets from the echo statements - i dont like using brackets, heh .

    Going back to your first post - the first bit of code is fine, just the last 2 needed to be combined, like ive shown above.
    If knowledge is power - Why isn't our army librarians?!
    Statistics show that 63% of all statistics are fake.
    When i was little i broke my neck, and i havent looked back since .
    I completed the internet in 1 week. The end boss was pretty easy though .


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
  •