...

View Full Version : Using echo for a table produces blank page, not even errors!!!?



rawky1976
08-15-2007, 10:43 PM
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?


<?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>";

?>

TheShaner
08-15-2007, 10:52 PM
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

rawky1976
08-15-2007, 11:21 PM
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?

whizard
08-15-2007, 11:45 PM
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?

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

HTH
Dan

Len Whistler
08-16-2007, 09:54 AM
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
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>

TheShaner
08-16-2007, 04:07 PM
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:

$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:

$result = mysql_db_query("servicemgmt", $query);
mysql_error() should only be used for debugging and logging errors.

-Shane

rafiki
08-16-2007, 04:12 PM
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

CFMaBiSmAd
08-16-2007, 04:45 PM
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..." :D ) and take appropriate action when there is an error (like exit the program) instead of blindly continuing to execute code.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum