Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Php and SQl help please

Options
  • 18-04-2005 5:01pm
    #1
    Registered Users 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 Posts: 68,317 ✭✭✭✭seamus


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


  • Registered Users 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 Posts: 202 ✭✭bribren2001


    Oops,
    ye there is loads of information in the database


  • Registered Users Posts: 68,317 ✭✭✭✭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 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 Posts: 68,317 ✭✭✭✭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 Posts: 202 ✭✭bribren2001


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

    big thanks to you also seamus


  • Advertisement
  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    D'oh!

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


Advertisement