Hollows Posted August 18, 2010 Share Posted August 18, 2010 Hi - first time on this forum but I've been lurking for some time and am more then impressed with the knowledge I see, I've learnt so much just reading topics...anyway... What I have here is some code to take form info and populate my db, then grab that info and display it, much the same as a shoutbox / guestbook script, except the end message / shout is not displayed to the sender as it shall be used to send shoutouts and tune requests into a broadcast panel used on our internet station. What I'd like to know is, how can I have the displayed messages on the end script use a CSS style that is selected on the original form? I guess I need to some how wrap the message output in CSS styling when it is sent into the db, but am lost how to select the wrap based on the tickbox being checked or not... please see the code below... This is the form part - <FORM METHOD=POST ACTION="shouts.php"> <TABLE> <TR> <TD>Name :</TD> <TD><INPUT TYPE="text" NAME="author"></TD> </TR> <TR> <TD>Email :</TD> <TD><INPUT TYPE="text" NAME="eml"></TD> </TR> <TR> <TD>Message :</TD> <TD><INPUT TYPE="text" NAME="message"></TD> </TR> <TR> <TD>shout - </TD> <TD><input name="shout" type="checkbox" class="shout" id="shout" value="Yes" /></TD> </TR> <TR> <TD>request - </TD> <TD> <input name="request" type="checkbox" class="request" id="request" value="Yes" /></TD> </TR> <TR> <TD></TD> <TD><INPUT TYPE="submit" name="submit" value="post"></TD> </TR> </TABLE> </FORM> I if the user selects the shout tick box I'd like the message to have a <div id="shout"></div> wrap and if they select request then a request wrap This is the php part of the script - <?php // You just need to configure these 4 variables to match your server. $db_host = "localhost"; // mySQL database host $db_user = "*****"; // mySQL database user $db_password = "*****"; // mySQL database password $db_name = "*****"; // the name of your mySQL database // If a user has submitted a post, we want to : // 1. Validate it // 2. Strip unwanted html // 3. Make sure messages and names aren't too long // 4. Add it to our database. if ( isset($_POST["submit"])) { // 1. Validate it, by checking all the form inputs were filled in if(!$_POST['author']) { echo 'Error ! : No name entered'; die; } if(!$_POST['eml']) { echo 'Error ! : No email entered'; die; } if(!$_POST['message']) { echo 'Error ! : No message entered'; die; } // 2. Strip unwanted HTML $message = strip_tags($_POST['message'], ''); $eml = strip_tags($_POST['eml'], ''); $author = strip_tags($_POST['author'], ''); // 3. Make sure messages and names aren't too long // We will use the strlen() function to count the length. $message_length = strlen($message); $author_length = strlen($author); if($message_length > 150) { echo "Error ! : Your message was too long, messages must be less than 150 chars"; die; } if($author_length > 150) { echo "Error ! : Your name was too long, names must be less than 150 chars"; die; } // 4. Add it to our database. // If the script hasn't died yet due to an error in the inputted data // we need to add the data to the database // Lets connect to our database. mysql_connect($db_host,$db_user,$db_password) or die(mysql_error()); // Select the database. mysql_select_db($db_name) or die(mysql_error()); // Lets define the date format we want to enter to our database // go here for more details // http://www.php.net/manual/en/function.date.php $date = date("h:i A dS M"); // This will produce 11:02 25th Aug // Set the query as $query $query = "INSERT INTO shoutbox (message, author, eml, date, ip) VALUES ('$message','$author','$eml','$date','$_SERVER[REMOTE_ADDR]')"; mysql_query($query); mysql_close(); // Show thanks message and take them back to the main shoutbox echo "Thanks for your post<BR>"; // If they haven't submitted a post, we want to : // 1. Show the latest shouts // 2. Show the shout post form } else { // 1. Show the latest shouts // Lets connect to our database. mysql_connect($db_host,$db_user,$db_password) or die(mysql_error()); // Select the database. mysql_select_db($db_name) or die(mysql_error()); // Set the query as $query, and get the last 10 posts. $query = "SELECT message, author, eml, date, ip FROM shoutbox order by id DESC LIMIT 10"; $result = mysql_query($query); echo "<TABLE>"; while($r=mysql_fetch_array($result)) { // To modify the appearance, edit this : echo "<TR> <TD><font size='1'> Posted $r[date] by <A HREF='mailto:$r[eml]'> $r[author]</A></font></TD> </TR> <TR> <TD><font size='1'>$r[message]</font></TD> </TR> <TR> <TD><HR></TD> </TR>"; } echo "</TABLE>"; } ?> Can anyone help Or if anyone can suggest a better way todo this I would be so very grateful Essential as well, I'd like to off the user of the broadcast panel the option to delete specific messages once read, or change the css id so they can score through already read out messages.. Link to comment https://forums.phpfreaks.com/topic/211038-using-a-tickbox-to-edit-sent-message/ Share on other sites More sharing options...
Hollows Posted August 18, 2010 Author Share Posted August 18, 2010 Just re read my post and it may not be quite clear, I know I need you use something like if $_POST['shout'] == 'Yes') to trigger what happens if they shout is ticked, but it's actually telling the script to add the css to the db info :-\ Link to comment https://forums.phpfreaks.com/topic/211038-using-a-tickbox-to-edit-sent-message/#findComment-1100657 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.