Jump to content

Recommended Posts

Morning

Any chance you can give me some hints as to where I'm going wrong with this. Or at least some advice on how to get the errors to display so I can work it out for myself. Please do bear with me... I'm at the noob stage where I still need to keep the book on my lap. :)

Here is my DB connection script
[code]
<?php

DEFINE ('DB_USER', 'usertype1');
DEFINE ('DB_PASSWORD', 'password');
DEFINE ('DB_HOST', 'localhost');
DEFINE('DB_NAME','Withheld');

$dbc = @mysqlconnect(DB_HOST, DB_USER, DB_PASSWORD) OR
die ('Could not connect to mysql: ' . mysql_error());

@mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error().'');
?>[/code]

I think the above is ok... I followed that one traight from the book....

Here is my query code which I had a go at myself using the code from the book and changing the relevant details for my own DB.

[code]
<div id="Layer4" style="position:absolute; left:170px; top:169px; width:700px; height:594px; z-index:5">

  <?php

require_once ('mysql_connect.php');

$query ='SELECT title AS Title, author AS Author FROM content ORDER BY author';
$result= mysql_query($query);

if ($result) {

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

echo '</table>';

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

mysql_close();  ?>

</div>[/code]

this section is in a division of my index.php file and is the only bit of dynamic code I've tried to implement. Its really driving me crazy I have the database set up and all the content but I can't get the pages to display the query results. I'm not receiving any errors at all. When I open the webpage from my htdocs folder it looks like it refreshes the page but nothing is displayed. What have I done?

Thanks in advance for your assistance.

Regards
Giraffe
Link to comment
https://forums.phpfreaks.com/topic/4311-no-query-results-no-errors/
Share on other sites

[code]

<div id="Layer4" style="position:absolute; left:170px; top:169px; width:700px; height:594px; z-index:5">

  <?php

require_once ('mysql_connect.php');

$query ='SELECT title, author FROM content ORDER BY author';
$result= mysql_query($query);

if ($result) {

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

echo '</table>';

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

mysql_close();  ?>

</div>
[/code]


I think your problem was that you were selecting title as Title and mysql if not set to caps sencitive will see title and Title as the same thing and doesn't allow 2 fields with the same name in same table.. a way to see the error would be to temporaryly add this..
$result= mysql_query($query) OR die(mysql_error());

And that will output the Mysql error so you can diagnose the problem :) and if you can't fix it from that then just post that error here and it's likly to be a simple syntax error or somthing like that :D
Brilliant!

Nope it didn't work :(

Ho hum.

Changed my query as advised (which was a fair comment ... what was I thinking! lol) and added OR die(mysql_error()); to the end of $result= mysql_query($query) as suggested. It still won't disaply an error or the results any suggestions? Yes I am typing it correctly . :)

Have checked that the query is ok by directly typing it into MySQL prompt (results displayed are expected). Which makes me think its more likely to be a problem with this bit of code. :/ *puzzled*

Cheers
<div id="Layer4" style="position:absolute; left:170px; top:169px; width:700px; height:594px; z-index:5">

<?php

require_once ('mysql_connect.php');

$query ='SELECT title, author FROM content ORDER BY author';
$result= mysql_query($query);

if ($result) {

echo '<table><tr><td> Title</td><td>Author</td></tr>';

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

echo '</table>';

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

mysql_close(); ?>

</div>


Try that, i've modified the loop as the problem oviusly isn't in the SQL
Hi there, gave that a try and it still didn't work. I can't seem to get it to display anything that has been processed by php at all.

I can however get phpinfo()... so its a start. lol

I think I must have a problem with either the php or apache config file which is preventing this from being displayed. I will go back to the books and see if I can resolve the issue.

In the meatime if you have any suugestions about where to start they would be very much appreciated.

Regards
Hello again

Still having the same problem. I was concerned that it may be due to my config files for php or apache that were the problem.

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)

So guys... can anyone make any suggestions as to why this is still happening. It is connecting to the database fine and executing the query ok (as I do get errors displayed when this has failed previously). When I load the page it is not displaying the table of results or the paragrah telling me something is wrong.

From my previous example some of the variable names have been changed as these now reflect my actual database values. All of my includes are working fine but as yet contain no dynamic content.

I think I may be confusing myself but do I have to define the query before any html input? if so could my <div> tags be causing this to fail? I'm feeling really miserable.

[code]<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>[/code]

As usual any suggestions greatfully received.
Regards
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.