Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Php and SQl help please

  • 18-04-2005 05:01PM
    #1
    Registered Users, Registered Users 2 Posts: 202 ✭✭


    hey all, the following php/sql code will not bring back the required information

    im trying to get back just one field-order number

    it keeps giving me back the table with the label but no order number value

    any help greatly appreciated

    <?php
    session_start();
    header("cache-control: private");
    $Student_Username = $_POST;
    // Make a MySQL Connection
    mysql_connect("xx", "xx", "xx") or die(mysql_error());
    mysql_select_db("gamesemp_cart") or die(mysql_error());
    $sql = mysql_query("SELECT * FROM orders WHERE Student_UserName = 'Smith");

    echo "<table border='1'>";
    echo "<tr> <th>Order Number</th></tr>";

    {
    echo "<table border='1'>";
    echo "<tr><td>";
    echo $row;
    echo "</td></tr>";
    }
    echo "</table>";
    ?>


Comments

  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    OK.
    $sql = mysql_query("SELECT * FROM orders WHERE Student_UserName = 'Smith");
    Missing a closing single quote after Smith.


  • Registered Users, Registered Users 2 Posts: 202 ✭✭bribren2001


    cheers seamus
    i put that in but still the same unfortunately


  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    first of all edit your code, you left in your db name and password

    second of all - make sure the information is there in the database, otherwise nothing will be returned


  • Registered Users, Registered Users 2 Posts: 202 ✭✭bribren2001


    Oops,
    ye there is loads of information in the database


  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    Do us a favour. Run the following queries and tell us the results you get.

    SELECT COUNT(*) FROM orders WHERE Student_UserName = 'Smith'
    SELECT COUNT(*) FROM orders WHERE Student_UserName LIKE 'Smith'

    :)


  • Advertisement
  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    <?php
    session_start();
    header("cache-control: private");
    $Student_Username = $_POST['Student_Username'];
    // Make a MySQL Connection
    mysql_connect("xx", "xx", "xx") or die(mysql_error());
    mysql_select_db("gamesemp_cart") or die(mysql_error());
    $sql = mysql_query("SELECT * FROM orders WHERE Student_UserName = 'Smith");
    
    echo "<table border='1'>";
    echo "<tr> <th>Order Number</th></tr>";
    while ($row = mysql_fetch_array($sql)) {
    
    echo "<table border='1'>";
    echo "<tr><td>";
    echo $row['OrderNumber'];
    echo "</td></tr>";
    }
    echo "</table>";
    ?>
    

    that should do it


  • Registered Users, Registered Users 2 Posts: 202 ✭✭bribren2001


    seamus-it give me errors on line 12 similar to the one below.

    ph3nom- it gave me the following error-Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gamesemp/public_html/getordernum.php on line 12


  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    seamus-it give me errors on line 12 similar to the one below.
    Can you run them through a MySQL interface, and not through PHP? Just to ensure your DB is returning the correct info.


  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    oops, try this;

    <?php
    session_start();
    header("cache-control: private");
    $Student_Username = $_POST['Student_Username'];
    // Make a MySQL Connection
    mysql_connect("xx", "xx", "xx") or die(mysql_error());
    mysql_select_db("gamesemp_cart") or die(mysql_error());
    $sql = mysql_query("SELECT OrderNumber FROM orders WHERE Student_UserName = 'Smith'");
    
    echo "<table border='1'>";
    echo "<tr> <th>Order Number</th></tr>";
    while ($row = mysql_fetch_array($sql)) {
    
    echo "<table border='1'>";
    echo "<tr><td>";
    echo $row['OrderNumber'];
    echo "</td></tr>";
    }
    echo "</table>";
    ?>
    


  • Registered Users, Registered Users 2 Posts: 202 ✭✭bribren2001


    Worked a treat Ph3n0m-thanks a million for that!!!

    big thanks to you also seamus


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    D'oh!

    Should have read Ph3nom's posts. The simple ones are sometimes the hardest to spot :).


Advertisement