Jump to content

Script's turned upside down!


PsoBloke

Recommended Posts

Hi there,

 

I'd really like some help with this shoutbox script. For the life of me, I can't figure out how to display the shouts first, and the add a shout form second. Currently the form's are first, followed by the actual shouts themselves, which I do not want. Any help to get this the right way up would be greatly appreciated. Thank you!

 

<?php

// calling session_start() the function which starts our authentication session
session_start();

// connecting to mysql server
$l = mysql_connect  ( "localhost" , "login" , "password" ) or die("Error connecting:<BR><BR>".mysql_error());
mysql_select_db( "db" ) or die("Error getting db:<BR><BR>".mysql_error());

// defining getShouts() which is our function that gets all of our shouts
function getShouts()
{

echo '<div align="center">
	<table width="150" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td>
';	


$query = mysql_query("SELECT * FROM shouts ORDER BY id ASC LIMIT 10") or die(mysql_error());
while ($row = mysql_fetch_array($query) )
{

	$name = stripslashes($row['Name']);
	$contact = stripslashes($row['Contact']);
	$shout = stripslashes($row['Shout']);

	if(empty($contact))
	{

		echo '<p><span class="author">'.$name.'</span> - <span class="shout">'.$shout.'</span></p>';

	} else {

		echo '<p><span class="author"><a href="'.$contact.'" target="_blank">'.$name.'</a></span> - <span class="shout">'.$shout.'</span></p>';

	} // if empty contact

} // while row mysqlfetcharray query

echo '<br><br>';

echo '
		</td>
	  </tr>
	  <tr>
		<td height="10"></td>
		<form name="shout" method="post" action="shout.php">
		  <div align="center" VALIGN="bottom">
			<input name="name" type="text" id="name" value="Name" size="25" maxlength="30"><br>
			<input name="contact" type="text" id="contact" value="http://" size="25"><br>
			<textarea name="message" cols="25" rows="5" id="message">Message</textarea><br>
			<input name="shout" type="submit" id="shout" value="Shout!">
		  </div>
		</form>
		</td>
	  </tr>
	  </table>
	  </div>
	';	

} // function getshouts




// our processing if control statement
if ( isset ( $_POST['shout'] ) )
{

$name = addslashes($_POST['name']);
$contact = addslashes($_POST['contact']);
$message =  $_POST['message'];

if ( ( isset($name) ) && ( isset($message) ) )
{

	// getting smilie list
	$smilies = mysql_query("SELECT * FROM smilies") or die(mysql_error());
	while($get = mysql_fetch_array ($smilies))
	{

		$alt = $get['Alt'];
		$smilie = $get['URL'];

		$message = str_replace( $get['Symbol'] , '<img src="smilies/'.$smilie.'" border="0" width="15" height="15" alt="'.$alt.'">' , $message);
		$themessage = addslashes($message);

		// replacing all smilies

	}

	mysql_query("INSERT INTO shouts (Name, Contact, Shout) VALUES ( '$name' , '$contact' , '$message' )") or die(mysql_error());
	$_SESSION['has_posted'] = 'yes';
	header("Location: shout.php");

	// if required fields aren't empty, process into database

} else {

echo '<script>alert("Some fields were not filled out!");</script>';
header("Location: shout.php");

// if required fields were left empty, show an error dialog

}

}

// if they weren't even referred from the form, show error dialog and redirect

// if isset post shout

/* STARTING THE MAIN SCRIPT NOW */

// starting the table

//displaying the shouts



?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?
getShouts();


mysql_close($l);
?>
</body>
</html>

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.