Hi
Not sure if this is a PHP question or a mySQL question, but here goes.
As can be guessed from my files and my issue, I'm quite new to PHP and especially to linking to a mySQL datebase.
But basically I have a News database which I have added a form on my website for users to add news stories. These are then displayed using some PHP scripting.
The issue I have is that I can then list all the news stories with an linked ID, which should then open another form to allow the user to edit the item.
Heres the form to display all the items:
The details.php file is the following:
The issue is when I select one of the ID's from the list I display, the resultant page simply states "Error: Could not get News from database."
The URL looks OK:
Any ideas? I just feel there is something really simply wrong with this and I can't see it.
Thanks ....
Not sure if this is a PHP question or a mySQL question, but here goes.
As can be guessed from my files and my issue, I'm quite new to PHP and especially to linking to a mySQL datebase.
But basically I have a News database which I have added a form on my website for users to add news stories. These are then displayed using some PHP scripting.
The issue I have is that I can then list all the news stories with an linked ID, which should then open another form to allow the user to edit the item.
Heres the form to display all the items:
Code:
<html>
<body>
<?php
// listing script
// connect to the server
mysql_connect( 'localhost', 'username', 'password' )
or die( "Error! Could not connect to database: " . mysql_error() );
// select the database
mysql_select_db( 'db_name' )
or die( "Error! Could not select the database: " . mysql_error() );
// retrieve all the rows from the database
$query = "SELECT * FROM `news` ORDER BY `ID`";
$results = mysql_query( $query );
// print out the results
if( $results )
{
while( $news = mysql_fetch_object( $results ) )
{
// print out the info
$ID = $news -> ID;
$StartDate = $news -> StartDate;
$EndDate = $news -> EndDate;
$Section = $news -> Section;
$Title = $news -> Title;
$Summary = $news -> Summary;
$Content = $news -> Content;
$Year = $news -> Year;
echo( "<a href='details.php?ID=$ID'>$ID</a>, $Title, $Summary<br /><br />" );
}
}
else
{
die( "Trouble getting News from database: " . mysql_error() );
}
?>
</body>
</html>
The details.php file is the following:
Code:
<html>
<head>
<title>Edit Items</title>
</head>
<body>
<?php
// listing script
// connect to the server
mysql_connect( 'localhost', 'username', 'password' )
or die( "Error! Could not connect to database: " . mysql_error() );
// select the database
mysql_select_db( 'db_name' )
or die( "Error! Could not select the database: " . mysql_error() );
// get the id from the URL request
$ID = $_REQUEST['ID'];
// retrieve all the rows from the database
$query = "SELECT * FROM `news` WHERE `ID`='$ID'";
$results = mysql_query( $query );
// print out the results
if( $result && $news = mysql_fetch_object( $result ) )
{
// print out the info
$ID = $news -> ID;
$DateEntry = $news -> DateEntry;
$StartDate = $news -> StartDate;
$EndDate = $news -> EndDate;
$Section = $news -> Section;
$Title = $news -> Title;
$Summary = $news -> Summary;
$Content = $news -> Content;
$Year = $news -> Year;
?>
<table border="2" cellpadding="2" cellspacing="0">
<tr>
<th align="left">ID</th>
<th align="left">Start Date</th>
<th align="left">End Date</th>
<th align="left">Section</th>
<th align="left">Title</th>
<th align="left">Summary</th>
<th align="left">Content</th>
<th align="left">Year</th>
</tr>
<tr>
<td align="left"><?php echo($ID) ?></td>
<td align="left"><?php echo($StartDate) ?></td>
<td align="left"><?php echo($EndDate) ?></td>
<td align="left"><?php echo($Section) ?></td>
<td align="left"><?php echo($Title) ?></td>
<td align="left"><?php echo($Summary) ?></td>
<td align="left"><?php echo($Content) ?></td>
<td align="left"><?php echo($Year) ?></td>
</tr>
</table>
<?php
}
else
{
die( "Error: Could not get News from database. ".mysql_error() );
}
?>
</body>
</html>
The issue is when I select one of the ID's from the list I display, the resultant page simply states "Error: Could not get News from database."
The URL looks OK:
Any ideas? I just feel there is something really simply wrong with this and I can't see it.
Thanks ....