database results not showing? using wamp
Posted by: Brett White (---.dsl.pipex.com)
Date: February 22, 2006 02:38AM

hi guys,

im just trying to get a simple news posting script working but after i submit the form the page thats meant to display the database is just blank, i have copied the code below, can anyone help??

(dbconnect.php)

<?php
$username = "marginex";//your username
$password = "steven";//your password
$host = "localhost";//your mySQL server
$database = "newscms";//The name of the database your table is in

mysql_connect($host,$username,$password) or die("Error connecting to Database!<br>" . mysql_error());//connect, but if there is a problem, display an error message telling why there is a problem
mysql_select_db($database) or die("Cannot select database!<br>" . mysql_error());//Choose the database from your mySQL server, but if there is a problem, display an error telling why
?>

(submit.php)

<?php
include("dbconnect.php"winking smiley;//include the file that connects to the database
if(!empty($title)) {//if the title is not empty, than do this function
$title = addslashes($title);
$user = addslashes($user);
$message = addslashes($message);

$date = date("F j, Y"winking smiley;//set up the date format
$date2 = mktime();

$sql = "INSERT INTO mynews (id, title, user, message, date) VALUES ('NULL', '$title','$user','$message','$date')";//Insert all of your information into the mynews table in your database
$query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
echo "Database Updated.";
} else {//However, if the title variable is empty, than do this function
?>
<form name="news" method="post" action="<?php echo $PHP_SELF; ?>">
<p>Please fill out all of the following fields:</p>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="117"><font size="1">News Topic/Title*: </font> </td>
<td width="577">
<font size="1">
<input type="text" name="title" size="50">
</font>
</td>
</tr>
<tr>
<td width="117"><font size="1">Username*:</font></td>
<td width="577">
<font size="1">
<input type="text" name="user" size="50">
</font>
</td>
</tr>
<tr>
<td width="117"><font size="1">Message*:</font></td>
<td width="577">
<font size="1">
<textarea name="message" rows=10 cols=43></textarea>
</font>
</td>
</tr>
</table>
<p>
<font size="1">
<input type="submit" name="Submit" value="Submit"></font>
</p>
</form> <?php
}//end this function
?>

(viewnews.php)

<?php
include("dbconnect.php"winking smiley;//include the file to connect to the database
$getnews = mysql_query("SELECT * FROM mynews ORDER BY id DESC"winking smiley;//query the database for all of the news

while($r=mysql_fetch_array($getnews)){//while there are rows in the table
extract($r);//remove the $r so its just $variable

echo("<hr>
<font size=3>$title added on $date</font><br>
<font size=1>Posted by $user</font><br>
<font size=2>$message</font><p>"winking smiley;

}

?>


Really hope someone can help!!!

Brett

Options: ReplyQuote
Re: database results not showing? using wamp
Posted by: CyberSpatium (---.hsd1.or.comcast.net)
Date: February 22, 2006 02:51AM

first, do not post your database password in a post, it is a huge security risk.

what errors are you getting, simply posting your php code here does not help.

Options: ReplyQuote
Re: database results not showing? using wamp
Posted by: Brett White (---.dsl.pipex.com)
Date: February 22, 2006 02:55AM

ok thanks.

im not getting any errors, once i submit some news, i then type in viewnews.php and the page loads but its blank and when i look at the source the php is missing sad smiley

Brett

Options: ReplyQuote
Re: database results not showing? using wamp
Posted by: CyberSpatium (---.hsd1.or.comcast.net)
Date: February 22, 2006 07:31AM

when you look at the source of a webpage, the php code wont be displayed, it is parced by the web server.

about your php not working, make sure that you are not using ASP style tags. so, change the first line of your php code from this:

<?

to this

<?php

Options: ReplyQuote
Re: database results not showing? using wamp
Posted by: Brett White (---.dsl.pipex.com)
Date: February 22, 2006 10:30AM

yes true,

although if you look at the code above I have used <?php ???

Options: ReplyQuote
Re: database results not showing? using wamp
Posted by: Brett White (---.park-s46b.dslaccess.co.uk)
Date: February 22, 2006 03:52PM

I have tested this on a webserver and its working fine, but not on my local machine, after the first page its then meant to take you to a form, the address bars is chaning but the page it loads is blank, sorry to bump this post up by getting real desparate :-(

BRett

Options: ReplyQuote
Re: database results not showing? using wamp
Posted by: CyberSpatium (---.hsd1.or.comcast.net)
Date: February 22, 2006 10:09PM

since you are getting no errors being displayed, it is hard to come up with a working reply. Edit your php.ini file, and around line 292, you will see this code:

error_reporting = E_ALL & ~E_NOTICE

Change it to this:

error_reporting = E_ALL

Now, save the file, then restart apache so the new settings take effect, and try access your page again. If you get any errors, copy them and paste them here so we can take a look at them.

By changing to E_ALL, we are making php display all php errors, instead of just the most serious ones.

Options: ReplyQuote


Sorry, only registered users may post in this forum.