Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using echo for a table produces blank page, not even errors!!!?

    Hi, I have a hyperlink which goes to the page below and passes the PK_ID from a query into 'userid'. From this we query the DB and then echo a table with a form; only the textboxes are already populated with the data from the query (in theory)!!!

    But I get a blank page! I have error reporting on php and mysql but nothing is displayed?

    Code:
    <?php
    
    echo "<form method=\"post\" action=\"\" style=\"padding-left: 10px\">";
    
    ini_set('display_errors','On');
    error_reporting(E_ALL);
    
    $user = $_GET['userid'];
    
    include 'config.php';
    include 'opendb.php';
    
    $query = "select * from users WHERE user_id LIKE '$user'"; 
    
    $result = mysql_db_query("servicemgmt", $query . mysql_error());
    
    $r = mysql_fetch_array($result);
    
    $firstname = $r['user_fname'];
    $lastname = $r['user_lname'];
    $ext = $r['user_ext'];
    $bleep = $r['user_bleep'];
    $exttel = $r['user_extno'];
    $email = $r['user_email'];
    
    
    echo "<table style=\"width: 80%\">";
    echo "<tr><td>First Name</td><td><input type=\"text\" value=\"$firstname\" name=\"firstname\" id=\"firstname\" style=\"width: 160px\"/></td><td>Last Name</td><td> <input type=\"text\" value=\"$lastname\" name=\"lastname\" id=\"lastname\" style=\"width: 160px\"/></td></tr>";
    echo "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
    echo "<tr><td>Extension</td><td> <input type=\"text\" value=\"$ext\" name=\"ext\" id=\"ext\" style=\"width: 160px\"/></td><td>Bleep No.</td><td> <input type=\"text\" value=\"$bleep\" name=\"bleep\" id=\"bleep\" style=\"width: 160px\"/></td></tr>";
    echo "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
    echo "<tr><td>External Tel.</td><td><input type=\"text\" value=\"$exttel\" name=\"exttel\" id=\"exttel\" style=\"width: 160px\"/></td><td>&nbsp;</td><td>&nbsp;</td></tr>";
    echo "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
    echo "<tr><td>Email</td><td><input type=\"text\" value=\"$email\" name=\"email\" id=\"email\" style=\"width: 200px\" /></td><td>&nbsp;</td><td>&nbsp;</td></tr>";
    echo "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";
    echo "<tr><td><input name=\"updateuser\" type=\"submit\" id=\"updateuser\" value=\"Update User Details\" /></td><td>&nbsp;</td><td>&nbsp;</td><td><input name=\"reset1\" type=\"reset\" value=\"Clear Form\" /></td></tr>";
    echo "</table>";
    
    echo "</form>";
    
    ?>

  • #2
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    First, the mysql_db_query function has been deprecated since 4.0.6, so if you're using a PHP version after it, use mysql_select_db and mysql_query to select a database and then query on it.

    Second, your query $result = mysql_db_query("servicemgmt", $query . mysql_error()); is wrong. Why are you appending a mysql error to your query? Do: $result = mysql_db_query("servicemgmt", $query); (even though like I said before that you should be using the other two functions).

    -Shane

  • #3
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Shane

    But I use that function is the previous page and it works fine. Is it not something to do with single and double quotes on the echo statement and escaping them?

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    If you have a syntax issue with the double/single quotes and escaping, PHP will most likely throw an error.

    Like Shane said, why are you appending the mysql_error to the query?

    Edit: Also, view the HTML source with your browser.. sometimes that can be informative!


    HTH
    Dan
    Last edited by whizard; 08-15-2007 at 10:48 PM.
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #5
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    I cleaned up the code a bit, you don't have to echo your table like that. There will be some syntax errors but it should give you a good idea of how to code a bit more efficient.

    PHP Code:
    <?php
    include 'config.php';
    include 
    'opendb.php';


    $user $_GET['userid'];
    $query "select * from users WHERE user_id LIKE '$user'"
    $result mysql_db_query("servicemgmt"$query mysql_error());
    $r mysql_fetch_array($result);

    $firstname $r['user_fname'];
    $lastname $r['user_lname'];
    $ext $r['user_ext'];
    $bleep $r['user_bleep'];
    $exttel $r['user_extno'];
    $email $r['user_email'];

    ?>

    <form method="post" action="" style="padding-left: 10px">
    <table style="width: 80%">
    <tr><td>First Name</td><td><input type="text" value="<? echo $firstname?>" name="firstname" id="firstname" style="width: 

    160px"></td><td>Last Name</td><td> <input type="text" value=<? echo $lastname?>" name="lastname" id="lastname" 

    style="width: 160px"/></td></tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><td>Extension</td><td> <input type="text" value="<? echo $ext?>" name="ext" id="ext" style="width: 

    160px"></td><td>Bleep No.</td><td> <input type="text" value=<? echo $bleep?>" name="bleep" id="bleep" style="width: 

    160px"/></td></tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><td>External Tel.</td><td><input type="text" value="<? echo $exttel?>" name="exttel" id="exttel" style="width: 

    160px"></td><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><td>Email</td><td><input type=\"text\" value=\"$email\" name=\"email\" id=\"email\" style=\"width: 200px\" 

    /></td><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
    <tr><td><input name="updateuser" type="submit" id="updateuser" value="Update User Details">
    </td><td>&nbsp;</td><td>&nbsp;</td><td><input name="reset1" type="reset" value="Clear Form" /></td></tr>
    </table>
    Leonard Whistler

  • #6
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    Definitely use Len's code as an example of how you should be outputting your form and table. PHP was created to be placed alongside HTML, not to output all your HTML.

    And I still don't understand this line:
    PHP Code:
    $result mysql_db_query("servicemgmt"$query mysql_error()); 
    Why are you attaching mysql_error() to the query? It may have worked previously because mysql wasn't throwing any errors, but as soon as it does, it's going to ruin your query too and then throw another error.

    It should be:
    PHP Code:
    $result mysql_db_query("servicemgmt"$query); 
    mysql_error() should only be used for debugging and logging errors.

    -Shane

  • #7
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    mysql_db_query is deprecated
    4.0.6 This function is deprecated, do not use this function. Use mysql_select_db() and mysql_query() instead.
    http://php.net/mysql_db_query

  • #8
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,108
    Thanks
    2
    Thanked 326 Times in 318 Posts
    Your code likely generates a php fatal parse error that is causing a blank page. Check your web server log for errors. When learning or when developing code, always turn on full php error reporting (display_errors and error_reporting), either in php.ini or a .htaccess file. Also, do a "view source" of the blank page in your bowser to see what might be present.

    In final "live" code, the mysql_error() output should not be displayed. However, all well written code must check the results of each mysql function call and output a meaningful user message (something like "The programmer failed to validate the external data you entered and executed a database query that failed, try again later..." ) and take appropriate action when there is an error (like exit the program) instead of blindly continuing to execute code.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

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