Jump to content

Echo all table information


Who8MyFish

Recommended Posts

So i have been tinkering with a PHP bulletin board for a project of mine and i'm having problems displaying the contents of my bulletin table. I can get the first entry to post but that is all, can someone take a look at my script and maybe help me out?

 

I am pretty new to PHP and even newer to MySQL so be kind lol

 

 

 

This is bulletin_board.php this is the file used to display posted bulletins.

--------------------------------------------------------------------------------------------------------------------------

<?php
session_start();
ob_start();
$host="localhost"; // Host name 
$username="blahblah"; // Mysql username 
$password="livelong&prosper"; // Mysql password 
$db_name="members"; // Database name 
$tbl_name="bulletins"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$posts = mysql_query("SELECT * FROM $tbl_name") 
or die(mysql_error()); 

$info = mysql_fetch_array( $posts );
$author = $info['user'];
$time = $info['date'];
$post = $info['bulletin'];
$user = $_SESSION['myusername'];
?>

if(empty($_SESSION['myusername'])){
echo "Please log in.";
}
else {
echo "<span class='Heading2'>Notifications for $user.</span><br /><br />";
echo "<span class='Body'>Posted by </span><span class='Heading3'>$author</span><br /><span class='footnote'>$time</span><br /><br /><span class='Body'>$post</span>";
}
?>
-----------------------------------------------------------------------------------------------------------------------------------
And i'm not sure if it matters but here is compose_bulletin.php
I don't know if it matters because like i said the bulletins are being written to the database just fine.
-----------------------------------------------------------------------------------------------------------------------------------
<?php
session_start();
$user= $_SESSION['myusername'];
if(empty($_SESSION['myusername'])){
echo "Please log in.";
}
else {
echo "<span class='Heading2'> Compose Bulletin.</span><br>
<span class='Body'>Use this form to post a bulletin, bulletins will post to the home page of every user.</span><br>
<form action='bulletin_board_post.php' method='post'>
<textarea name='bulletin' cols='120' rows='25'></textarea><br>
<input name='submit' type='submit' value='POST'>
</form>";
}
?>
--------------------------------------------------------------------------------------------------------------------------------------------------------
bulletin_board_post.php takes info from compose_bulletin.php and writes to the bulletin table in the members database
---------------------------------------------------------------------------------------------------------------------------------------------------------
<?php
session_start();
ob_start();
$host="localhost"; // Host name 
$username="Whindoes"; // Mysql username 
$password="livelong&prosper"; // Mysql password 
$db_name="members"; // Database name 
$tbl_name="bulletins"; // Table name

// Define timestamp and user variables
$user = $_SESSION['myusername']; //define username
$date = date("d/m/y : H:i:s", time());
$bulletin = $_POST['bulletin'];

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$posts = mysql_query("INSERT INTO $tbl_name
(user, date, bulletin) VALUES('$user', '$date', '$bulletin' ) ") 
or die(mysql_error()); 

?>

-------------------------------------------------------------------------------------------------------------------------------

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.