new to php and mysql and need a little help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • glenn

    new to php and mysql and need a little help

    I am try to teach myself PHP and MYSQL.

    Below I have a php file I have created which when i look at it in a browser
    returns a nice list of people and there addresses.

    When I change the $data line from
    $data = mysql_query("SE LECT * FROM dir ORDER BY SURNAME") or
    die(mysql_error ());
    to
    $data = mysql_query("SE LECT * FROM dir WHERE SURNAME = 'SMITH'") or
    die(mysql_error ());

    I expected my page to show all the people who had the surname SMITH. But
    instead I get nothing.

    When I run the query SELECT * FROM dir WHERE SURNAME = 'SMITH';
    against my mysql databse it returns the lines with SURNAME Smith.

    Can anyone tell me why it doesnt work in my php file?


    <html>
    <head>
    <title></title>
    </head>
    <body>
    <font size="2" face="Century Gothic" color="#0000FF" >

    <?php

    //Connect information
    mysql_connect(" localhost", "gaspa", "blah123") or die (mysql_error()) ;
    mysql_select_db ("SBC") or die (mysql_error()) ;

    // Collects data from "dir" table
    $data = mysql_query("SE LECT * FROM dir ORDER BY SURNAME") or
    die(mysql_error ());

    // puts the "dir" info into the $info array
    $info = mysql_fetch_arr ay( $data );

    // Print out the contents of the entry
    while($info = mysql_fetch_arr ay( $data ))
    {
    Print "<b>SURNAME :</b".$info['SURNAME'] . " ";
    Print "<b>HOME PHONE:</b".$info['HOME_PHONE'] . " ";
    Print "<b>Name:</b".$info['NAME_1'] . " ";
    Print "<b>Mob:</b".$info['PHONE_1'] . " ";
    Print "<b>Birthda y:</b".$info['BIRTHDAY_1'] . " ";
    Print "<b>Name:</b".$info['NAME_2'] . " ";
    Print "<b>Mob:</b".$info['PHONE_2'] . " ";
    Print "<b>Birthda y:</b".$info['BIRTHDAY_2'] . "<br><Br";
    }
    Print "</table>";

    ?>

    </font>
    </strong>
    </body>
    </html>




  • cldmismgr

    #2
    Re: new to php and mysql and need a little help

    On Feb 24, 5:45 am, "glenn" <g...@bigpond.c omwrote:
    I am try to teach myself PHP and MYSQL.
    >
    Below I have a php file I have created which when i look at it in a browser
    returns a nice list of people and there addresses.
    >
    When I change the $data line from
    $data = mysql_query("SE LECT * FROM dir ORDER BY SURNAME") or
    die(mysql_error ());
    to
    $data = mysql_query("SE LECT * FROM dir WHERE SURNAME = 'SMITH'") or
    die(mysql_error ());
    >
    I expected my page to show all the people who had the surname SMITH. But
    instead I get nothing.
    >
    When I run the query SELECT * FROM dir WHERE SURNAME = 'SMITH';
    against my mysql databse it returns the lines with SURNAME Smith.
    >
    Can anyone tell me why it doesnt work in my php file?
    >
    <html>
    <head>
    <title></title>
    </head>
    <body>
    <font size="2" face="Century Gothic" color="#0000FF" >
    >
    <?php
    >
    //Connect information
    mysql_connect(" localhost", "gaspa", "blah123") or die (mysql_error()) ;
    mysql_select_db ("SBC") or die (mysql_error()) ;
    >
    // Collects data from "dir" table
    $data = mysql_query("SE LECT * FROM dir ORDER BY SURNAME") or
    die(mysql_error ());
    >
    // puts the "dir" info into the $info array
    $info = mysql_fetch_arr ay( $data );
    >
    // Print out the contents of the entry
    while($info = mysql_fetch_arr ay( $data ))
    {
    Print "<b>SURNAME :</b".$info['SURNAME'] . " ";
    Print "<b>HOME PHONE:</b".$info['HOME_PHONE'] . " ";
    Print "<b>Name:</b".$info['NAME_1'] . " ";
    Print "<b>Mob:</b".$info['PHONE_1'] . " ";
    Print "<b>Birthda y:</b".$info['BIRTHDAY_1'] . " ";
    Print "<b>Name:</b".$info['NAME_2'] . " ";
    Print "<b>Mob:</b".$info['PHONE_2'] . " ";
    Print "<b>Birthda y:</b".$info['BIRTHDAY_2'] . "<br><Br";}
    >
    Print "</table>";
    >
    ?>
    >
    </font>
    </strong>
    </body>
    </html>
    take out the first mysql_fetch_arr ay line
    Craig

    Comment

    Working...