Jump to content

[SOLVED] empty problem possibly?


Nexy

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.