Page 2 of 2
Posted: Thu Mar 31, 2005 6:59 pm
by marike
Am a bit late, but thought I might try to help out. I think we all know how frustrating a blank screen can be.
Your PHP code and MySQL query is 100% correct. I ran it, and it does exactly what it is supposed to do. I agree with the others that you should always put in error checking after each line. It a good idea to follow mysql_connect, mysql_select_db, & mysql_query with the appropriate error checking statements so you know if & where your code is failing.
You said: "I've saved the file as both .php and .html, but I suppose that wouldn't matter as long as the .html had the php script embedded inside"
Your script should be saved with the .php extension. I could be wrong, but the only way I know of to masquerade PHP scripts as HTML file (.html files) is by using Apache's 'mod_rewrite' module and creating an .htaccess file that causes the server to parse PHP files as HTML. I'd stick with the .php extension.
Sounds like you have either configuration issues, or less likely but possible, your MySQL table might not be 100% OK. Can you run a "select * from mydatabase" query in MySQL monitor?
I'm not a Windows guy, if you want to get up and running with PHP quickly and without too much hassle you might look into
a all in one package like XAMP
http://www.apachefriends.org/en/xampp-windows.html I read about it here
http://education.nyphp.org/phundamental ... =2/17/2004 Probably what I would do if you continue having problems. Good luck,
Posted: Tue Apr 19, 2005 3:54 pm
by cdemoneya
sorry for being away this long guys. Work got the better of me.
I hope there's someone out there that can help me with this.
I have this php code, connected to mysql database,that runs to the best of my knowledge. I have applied error codes to identify any connection failures to the database and if I enter wrong database names etc, I am duly informed on the web browser about syntax errors or unknown usernames and passwords.
But when I get all my details right, no errors are generated, but I get a blank page display, with nothin on it.
This suggests that my queries are running okay, but do I need to do anything to view them?
Please help. see code below:
Code: Select all
<html>
<head>
<title>dbtest</title>
</head>
<body>
<?
$dbcnx = mysql_connect("localhost","root","password") or die(mysql_error());
mysql_select_db("test",$dbcnx) or die(mysql_error());
$query = "SELECT email FROM customer WHERE customerid='001'";
$chucka = mysql_query($query) or die("Couldnt connect.");
$row = mysql_fetch_array($chucka) or die("not working");
?>
</body>
</html>
feyd | Please review how to post code using Code: Select all
tags. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Posted: Tue Apr 19, 2005 3:57 pm
by cdemoneya
hey thanks dude.
I just got back from a project at work and I'm looking at the sites you suggested.
from my previous update you can see that the problem hasnt gone away and its awfully depressing watching that blank screen.
I'll check out the sites and get back to you.
Thanks.
Posted: Tue Apr 19, 2005 4:00 pm
by feyd
you haven't printed what came from mysql_fetch_array()..
var_export()
Posted: Tue Apr 19, 2005 4:15 pm
by cdemoneya
"you haven't printed what came from mysql_fetch_array().. "
please explain.
I'm new to php and the speed with which I have had to learn means I might be missing small but vital aspects.
I have specified a query, given the query a variable name and requested that the query to display the results of the query. what am I missing then?
PLEASE IGNORE FROM HERE DOWN (just checking your code writing guideline)
php
mysql_Connect( $localhost, $username, $password);
/php
Posted: Tue Apr 19, 2005 4:47 pm
by feyd
you didn't request it to display anything other than a blank html body. Instead, you stored the first record of the query into $row... but did nothing with it.
Posted: Wed Apr 20, 2005 12:03 am
by cdemoneya
ok. I guess that's where my mistake is and that would explain the blank page without any errors. which means its executing something, but doesnt have the command to display.
I'm obviously going to read more about display, but can you give me a synopsis of the code structure I need to use here?
Posted: Wed Apr 20, 2005 12:30 am
by feyd
I already gave you a link to one function you can call to display some debugging type output to see what happens...
Posted: Wed Apr 20, 2005 1:35 am
by cdemoneya
I've just looked through the history and didnt see any links from yourself. Sorry, if you have, but I'm sure I've looked.
The only link in there so far is from Marike on 31/03 but it seems to be dealing with Apache, while I'm running IIS 5.0

Posted: Wed Apr 20, 2005 1:40 am
by feyd
feyd wrote:you haven't printed what came from mysql_fetch_array()..
var_export()
notice the text on the end..

Posted: Fri Apr 22, 2005 11:45 am
by cdemoneya
Hey everyone.
Thanks for all your feedback on this. I am finally getting some response fromt mysql with php, but obviously, not without problems.
I have just run the following query:
Code: Select all
<html>
<head>
<title>dbtest</title>
</head>
<body>
<?
$dbcnx = mysql_connect("localhost","root","password") or die(mysql_error());
mysql_select_db("test",$dbcnx) or die(mysql_error());
$customer="customerID";
$customernam="customerName";
$customerad="customeradd";
$customertel="customertel";
$customertel2="customertel2";
$email="Email";
$query = "SELECT * FROM customer WHERE customerid='001'or'002'or '003'";
$result = mysql_query($query) or die("No current connection to database.");
echo "<font size='2'><b>ACCOUNT DETAILS</font>";
while ($row = mysql_fetch_array($result))
{
extract($row);
echo "<table border='2' bgcolor='yellow'>";
echo "<tr>\n
<td>$customer</td>\n
<td>$customernam</td>\n
<td>$customerad</td>\n
<td>$customertel</td>\n
<td>$customertel2</td>\n
<td>$email</td>\n
</tr>\n";
echo "</table>\n";
}
?>
</body>
</html>
Everything works fine. except the display is of the column headers rather than the actual data. So for example, I have 20 records on my database, but they are all displayed (all 20 of them) as the header column.
e.g CustomerID CustomerNAME CustomerAdd. etc.
This is repeated 20 times. So I have my connection and display, but there's something not quite right.
Can you help?
Thanks
Posted: Sun Apr 24, 2005 2:32 am
by cdemoneya
Well, just kept getting the blank page and my error codes didnt seem to work, but following some extensive overnight work, I have managed to get everything in place. I can now view the db on the webpage and its been well worth the time and energy.
er! problem though (not really a problem) When I select
I get all the records as well as duplicated table headers. i.e
for every record, I have the headers (customer name, customer address etc) being replicated between records and ideally, I would just like one set of headers and all the records below. I know this would be a simple code enhancements, but after 4 hours of doing this, my brain isnt functioning very well.
this is what I have
Code: Select all
Header section:
<tr bgcolor='9966ff'>
<th><font size='1' face='courier new'>PROJECT ID</font></th>
<th><font size='1' face='courier new'>PROJECT NAME</font></th>
<th><font size='1' face='courier new'>START DATE</font></th>
<th><font size='1' face='courier new'>FINISH DATE</font></th>
<th><font size='1' face='courier new'>CORDINATOR</font></th>
<th><font size='1' face='courier new'>DETAILS</font></th>
Records
<tr bgcolor='white'>
<th><font size='1' face='courier new'>$projectid</font></th>
<th><font size='1' face='courier new'>$projectname</font></th>
<th><font size='1' face='courier new'>$commencedate</font></th>
<th><font size='1' face='courier new'>$finishdate</font></th>
<th><font size='1' face='courier new'>$cordinator</font></th>
<th><font size='1' face='courier new'>$projectdetails</th>
</tr>\n
can you help?
Posted: Sun Apr 24, 2005 11:13 am
by phpScott
put your header section
before your while loop when you are showing the results from the database.
the first time is always the worst, it will only get better form here on out as you delve deeper into the world of php, but odds are you won't make the same mistake more than 3 or 4 times.

Posted: Sun Apr 24, 2005 12:31 pm
by cdemoneya
Thanks mate.
spent 3 hours looking at that before I posted the message, then solved it in 5mins.
you're right though, I'll never make that mistake again.
Well hopefully!
Cheers.