Jump to content

[SOLVED] PHP won't retrieve the information from the database.


Daegalus

Recommended Posts

Well im making a custom news system for a site im building, I don't like the ones already out there, and I've hit a roadblock and have 0 clue why its not working.

 

<?php
include('config.php');
$dbh = mysql_connect($mysql_server, $username, $password) 
or die("Unable to connect to MySQL");
mysql_select_db($database,$dbh) or die("Could not select first_test");
$query = "SELECT * FROM news ORDER BY id DESC LIMIT 15";
$result = mysql_db_query($database,$query,$dbh) or die("Error in query: $query. " . mysql_error());

while($row = mysql_fetch_row($result))
{
?>
<tr>
<td>
<? echo $row{'title'} ?><br /><? echo $row{'date'} ?> - <? echo $row{'time'} ?> - Posted By: Admin
</td>
</tr>
<tr>
<td>
<? echo $row{'body'} ?>
</td>
</tr>
<br />
<br />
<br />

<?
}
mysql_close($dbh);
?>

 

http://www.kuncheff.com:81/WAR/ is where I test it. and as you see, the normal text appears, but none of the items retrieved from the database appear.

Any help would be greatly appreciated.

Link to comment
Share on other sites

<?php
mysql_connect($hostname, $username, $password);
mysql_select_db($dbname);

$result = mysql_query("SELECT * FROM news ORDER BY ID");

print "<table>";

while($array = mysql_fetch_while($result)) {
	$title = $result['title'];
	$date = $result['date'];
	$time = $result['time'];
	$body = $result['body'];

	print <<<HERE
		<tr>
			<td>
				$title <br>
				-$date <br>
				-$time <br>
				-Posted by: Admin
			</td>
		</tr>
		<tr>
			<td>
				$body
			</td>
		</tr>
HERE;
}
             print "</table>";
mysql_close;
?>

Link to comment
Share on other sites

Nope doesn't work, I applied your changes, and it still results in the same.

 

This the current code with corrections:

<?php
include('config.php');
$dbh = mysql_connect($mysql_server, $username, $password) 
or die("Unable to connect to MySQL");
mysql_select_db($database,$dbh) or die("Could not select " + $database);
$query = "SELECT * FROM news ORDER BY id DESC LIMIT 15";
$result = mysql_db_query($database,$query,$dbh) or die("Error in query: $query. " . mysql_error());

while($row = mysql_fetch_row($result))
{
?>
<tr>
<td>
<?php echo $row['title'] ?><br /><?php echo $row['date'] ?> - <?php echo $row['time'] ?> - Posted By: Admin
</td>
</tr>
<tr>
<td>
<?php echo $row['body'] ?>
</td>
</tr>
<br />
<br />
<br />

<?php
}
mysql_close($dbh);
?>

 

 

Link to comment
Share on other sites

<?php
include('config.php');
$dbh = mysql_connect($mysql_server, $username, $password) 
or die("Unable to connect to MySQL");
mysql_select_db($database,$dbh) or die("Could not select " + $database);
$query = "SELECT * FROM news ORDER BY id DESC LIMIT 15";
$result = mysql_db_query($database,$query,$dbh) or die("Error in query: $query. " . mysql_error());

while($row = mysql_fetch_row($result))
{
?>
<tr>
<td>
<?php echo ($row['title']); ?><br /><?php echo ($row['date']);?> - <?php echo ($row['time']); ?> - Posted By: Admin
</td>
</tr>
<tr>
<td>
<?php echo ($row['body']) ;?>
</td>
</tr>
<br />
<br />
<br />

<?php
}
mysql_close($dbh);
?>




Link to comment
Share on other sites

http://us3.php.net/function.mysql-db-query

 

That function is depreciated! Read the page and see what you need to use instead.

 

Silly question but is there anything in the "news" table?

 

Second, are the fields title, date and time exactly as shown in the table? Calling a field "Title" and accessing by "title" will give you empty results.

Link to comment
Share on other sites

http://us3.php.net/function.mysql-db-query

 

That function is depreciated! Read the page and see what you need to use instead.

 

Silly question but is there anything in the "news" table?

 

Second, are the fields title, date and time exactly as shown in the table? Calling a field "Title" and accessing by "title" will give you empty results.

 

Ok i used the new one, and i checked everything field titles are right and everything. there is data in the news table. With every new addition, the code does add another line of " - - Posted by: Admion." still no go.

Link to comment
Share on other sites

<?php
$result = mysql_query($database,$query,$dbh) or die("Error in query: $query. " . mysql_error());?>

 

mysql_query only requuires the query in it. Also i got it working with your help guys, thanks. I changed the mysql_fetch_row() (since its not part of mysql_query) to mysql_fetch_assoc, and it worked instantly. Thanks guys.

Link to comment
Share on other sites

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.