[SOLVED] No results & no error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RampantGiraffe
Forum Newbie
Posts: 6
Joined: Sat Mar 11, 2006 4:39 pm

[SOLVED] No results & no error

Post by RampantGiraffe »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi there.  I have been experiencing problems with my first php page I have created.  

When loading the page I do not get any error messages and the query results do not display,  it will not even display any html after the query has run.

I thought it was just my webserver setup on my machine at home so to test my theory I added by scripts to my hosts webserver and was dismayed to find that I am still having the same problems. (yet pleased that it wasn't just my poor configuration skills on my home machine)

It is connecting to the database fine and executing the query ok (as I do get errors displayed when this has failed previously and I have manually run the query in command prompt... pretty sure its not the sql elements). When I load the page it is not displaying the table of results or the paragrah telling me something is wrong.  All of my includes are working fine but as yet contain no dynamic content.

Code: Select all

<body>
<?php error_reporting (E_ALL);?>
<?php include "leftnav.php";?>
<?php include "topnav.php";?>
<?php include "footer.php";?>

<div id="Layer4" style="position:absolute; left:170px; top:169px; width:850px; height:594px">
<! here is this bit you fill in!>
  <?php 

require_once ('mysql_connect.php');

$sql = 'SELECT `title`,`author`,`subdate`,`text` FROM `sitec` WHERE `category` =\'Articles\' ORDER BY `subdate`';
$result= mysql_query($sql)OR 
die (mysql_error());

if ($result) {

echo '<table><tr><td> Title</td><td>Author</td><td>Articles</td></tr>';
             
while ($row=mysql_fetch_array($result)){
echo '<tr><td> '. $row['title'] .' </td><td> '. $row['author'] .' </td><td> '.$row['text'] .'</td></tr>';}

echo '</table>';


}else{
echo '<p> The current query did not execute successfully</p>';
echo '<p>' .mysql_error() . '<br />
<br /> Query: '. $query .' </p>';}

mysql_close();

?>
<!end of main content!>

</body>
</html>
Any suggestions greatfully received.
Regards


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Most likely you are not connecting to your database. Have you verified a connection?
RampantGiraffe
Forum Newbie
Posts: 6
Joined: Sat Mar 11, 2006 4:39 pm

Post by RampantGiraffe »

Connection seems to be fine. If I change any of the details in the 'mysql_connect.php' file I get sql error connecting to database messages displayed on the screen. The fact that I'm not getting any sql errors led me to believe that this bit was fine (equally if I changed anything in the query that did not match the sql database fields I also received an SQL error displayed)

Is there some other way I can verify the connection other than this?

Cheers
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Sounds like your connection is fine. What does your table look like? What does your connection look like?

The issue may be in your mysql_connect.php file so try adding an echo 'Hello World'; under the require_once ('mysql_connect.php'); to see if it ouputs.

Other things you can try:

Try a query such as 'show tables' or 'select * from sitec' to see if it returns any results.

Let me know what happens?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

somthing like

Code: Select all

mysql_connect(/*info here*/) or die(mysql_error());
if you dont get a error then you are connected fine
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

shiznatix wrote:somthing like

Code: Select all

mysql_connect(/*info here*/) or die(mysql_error());
if you dont get a error then you are connected fine
best to use mysql_error on all queries
RampantGiraffe
Forum Newbie
Posts: 6
Joined: Sat Mar 11, 2006 4:39 pm

Post by RampantGiraffe »

Occam's Razor applied and solution found :)

Indeed a problem with my connection so thank you muchly for inisiting I check it. I would be embarrassed if I didn't feel three days of frustration being replaced by so much relief.

echoing hello world didn't work so I looked again at mysql_connect.php and found

Code: Select all

$dbc = mysqlconnect(DB_HOST, DB_USER, DB_PASSWORD)
yes! where, oh where, was the underscore? and why wasn't I receiving the error message? because I forgot to remove the @ .

~~

With the @ removed I received error: Fatal error: Call to undefined function: mysqlconnect()

Which then led to me changing my code to

Code: Select all

$dbc = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)
Which worked! Hurrah! I can sleep now!

Thanks in advance for not mocking me... despite the frustration I am enjoying the learning curve.

RG



User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

glad you got it working!

on a side note you should really not use the @ except for some very specific situations (connecting to mysql is NOT one of those times) because suppressing errors is just avoiding the problem instead of fixing it.
Post Reply