Jump to content

Recommended Posts

Why Hello There! :) I don't see why this problem is happening.

 

<?php
$shomes = mysql_real_escape_string(stripslashes($_POST['shoutext']));
$sshuser = mysql_real_escape_string(stripslashes($_SESSION['username']));
$cshuser = mysql_real_escape_string(stripslashes($_COOKIE['user']));
$shtime = mysql_real_escape_string(stripslashes(date('h:i:s a')));

$sherror = "0";

if($_POST['shoutsub']) {

if(!empty($shomes))
{
	if($_SESSION['username']) {	mysql_query("INSERT INTO shoutbox(user, time, message) VALUES('$sshuser', '$shtime', '$shomes')"); }
	else if($_COOKIE['user']) { mysql_query("INSERT INTO shoutbox(user, time, message) VALUES('$cshuser', '$shtime', '$shomes')"); }
}
else if(empty($shomes)) { $sherror = "1"; }
}

?>

<div class='create margin' style='font-size: .8em; width: 700px; margin-top: .8em; margin-bottom: 0'>
Shoutbox (

<a href="javascript:;" 
onmousedown="if(document.getElementById('shoutbox').style.display == 'none' || document.getElementById('shoutform').style.display == 'none') 
{ 
	document.getElementById('shoutbox').style.display = 'block'; 
	document.getElementById('shoutform').style.display = 'block'; 
}
else 
{ 
	document.getElementById('shoutbox').style.display = 'none';
	document.getElementById('shoutform').style.display = 'none'
}
">Show/Hide</a>
)
</div>

<div id="shoutbox" style="display:none">

<?php
	$shsql = "SELECT * FROM shoutbox WHERE id > 0 ORDER BY id DESC";
	$shres = mysql_query($shsql) OR die(mysql_error());

	while($shout = mysql_fetch_array($shres))
	{
		echo $shout['time'] . " " . $shout['user'] . ': ' . $shout['message'] . '<br />';
	}
?>

</div>

<?php

if($_SESSION['username'] || $_COOKIE['user']) {

echo "<div id='shoutform' style='display: none'>";

	if($_POST['shoutsub'] && $sherror == "1") { echo "<span style='color: red'>Please enter a message!</span>"; }


echo "<form action='#' method='post'>
	<fieldset id='shout'>

	<label for='shoutext'>Message:</label>
	<input type='text' id='shoutext' name='shoutbox' tabindex='6' style='width: 500px' />

	<input type='submit' id='shoutsub' name='shoutsub' value='Shout!' tabindex='7' />

	</fieldset>
</form>

</div>";
}

?>

 

The problem is, it keeps telling me "Please enter a message". I know this isn't the best way to do a shoutbox, I will use AJAX later, but does anyone see any reason as to why it would keep saying that even after I enter something? I can't tell if the INSERT statements are working or not because it never gets there. I echoed "$shomes" but it returned nothing. Any help would be appreciated.

 

Thank You! :)

Link to comment
https://forums.phpfreaks.com/topic/111204-solved-empty-problem-possibly/
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.