palm88 Posted April 16, 2008 Share Posted April 16, 2008 Hi i am having trouble with the if statement outlined with ---> Ive been trying to figure it out but i cant seem to get my head around what im doing wrong. Thanks :-X <? session_start(); include_once "includes/db_connect.php"; $username=$_SESSION['username']; $fetch=mysql_fetch_object(mysql_query("SELECT * FROM users WHERE username='$username'")); $fromper=$_GET['fromper']; $goody = mysql_query("SELECT `message`, `date`, `from` FROM `inbox` WHERE `id`='$rep'"); while($success = mysql_fetch_row($goody)){ $ini = $success[0]; $dateon = $success[1]; $fromper = $success[2]; } $kill_username=strip_tags($_POST['kill_username']); $message=strip_tags($_POST['message']); $subject = strip_tags($_POST['subject']); $date = gmdate('Y-m-d h:i:s'); $username_check = mysql_num_rows(mysql_query("SELECT username FROM users WHERE username='$kill_username'")); ----->if ($_POST['kill_button']){ if(!stripslashes($_POST['kill_username']) || !stripslashes($_POST['message'])){ print "Please enter a username and message."; } elseif (!stripslashes($_POST['subject'])){ $subject = "No Subject Title."; } elseif($username_check < "1"){ print "No such user!"; unset($reg_username); } }else{ mysql_query("INSERT INTO `inbox` ( `id` , `to` , `from` , `message` , `subject` , `date` , `read` , `saved` , `event_id` ) VALUES ( '', '$kill_username', '$username', '$message', '$subject', '$date', '0', '0', '0' )"); mysql_query("UPDATE `user_info` SET `messages` = `messages`+1 WHERE username='$username'"); /// echo "Message sent to $kill_username!"; }<----- ?> <link href="includes/in.css" rel="stylesheet" type="text/css"> </form> <table width="76%" border="0" align="center" cellpadding="0" cellspacing="3"> <tr> <td> <div align="center"> <center> <table border="o" cellpadding="0" cellspacing="0" class=tablearea style="border-collapse: collapse"> <form name="form1" method="post" action=""> <tr> <td colspan="2" class="TableHeading"><center> Compose Message </center></td> </tr> <tr> <td class="TableArea">Username:</td> <td class="TableArea"> <input name="kill_username" type="text" class="input" id="kill_username3" value='<?php echo $fromper; ?>' size="20"></td> </tr> <tr> <td class="TableArea">Subject Title:</td> <td class="TableArea"> <input name="subject" type="text" class="input" id="subject" size="50"></td> </tr> <tr> <td valign="top" class="TableArea">Message:</td> <td class="TableArea"><textarea name="message" cols="50" rows="10" type="text" id="message"><?php if($_GET['id']) { $id = $_GET['id']; $reply = mysql_query("SELECT * FROM inbox WHERE id = '$id'"); $fetch_reply = mysql_fetch_object($reply); echo "On $fetch_reply->date $fromper said: $fetch_reply->message"; } ?></textarea></td> </tr> <tr> <td colspan="2" class="TableArea"><div align="right"> <input name="kill_button" type="submit" class="submit" id="kill_button3" value="Submit"> </div></td> </tr> </table> </center></form> </div> </td> </tr> <SCRIPT> <!-- function input(Item) { document.getElementById('send_id').value = Item; } //--> </SCRIPT> </table> Link to comment https://forums.phpfreaks.com/topic/101347-if-statement-problems/ Share on other sites More sharing options...
conker87 Posted April 16, 2008 Share Posted April 16, 2008 Erm. Whats the problem with it? Link to comment https://forums.phpfreaks.com/topic/101347-if-statement-problems/#findComment-518370 Share on other sites More sharing options...
Cep Posted April 16, 2008 Share Posted April 16, 2008 I second the motion although, I would like to know what your trying to evaluate by doing, if($_POST['kill_button']) { Link to comment https://forums.phpfreaks.com/topic/101347-if-statement-problems/#findComment-518374 Share on other sites More sharing options...
palm88 Posted April 16, 2008 Author Share Posted April 16, 2008 This works fine, but iw ould rather it be one statement if you know what i mean and remove the die; if ($_POST['kill_button']){ if(!stripslashes($_POST['kill_username']) || !stripslashes($_POST['message'])){ print "Please enter a username and message."; die; } elseif (!stripslashes($_POST['subject'])){ $subject = "No Subject Title."; } if($username_check < "1"){ echo "No such user!"; unset($reg_username); }} if (strip_tags($_POST['kill_username'])){ mysql_query("INSERT INTO `inbox` ( `id` , `to` , `from` , `message` , `subject` , `date` , `read` , `saved` , `event_id` ) VALUES ( '', '$kill_username', '$username', '$message', '$subject', '$date', '0', '0', '0' )"); mysql_query("UPDATE `user_info` SET `messages` = `messages`+1 WHERE username='$username'"); /// echo "Message sent to $kill_username!"; } Link to comment https://forums.phpfreaks.com/topic/101347-if-statement-problems/#findComment-518379 Share on other sites More sharing options...
Cep Posted April 16, 2008 Share Posted April 16, 2008 There is no die statement in your original post, (and this is a tidy version so I can read it easier) <?php if ($_POST['kill_button']) { if(!stripslashes($_POST['kill_username']) || !stripslashes($_POST['message'])) { print "Please enter a username and message."; } elseif (!stripslashes($_POST['subject'])) { $subject = "No Subject Title."; } elseif($username_check < "1") { print "No such user!"; unset($reg_username); } } else { mysql_query("INSERT INTO `inbox` (`id` ,`to` ,`from` ,`message` ,`subject` ,`date` ,`read`, `saved` ,`event_id` ) VALUES ( '', '$kill_username', '$username', '$message', '$subject', '$date', '0', '0', '0')"); mysql_query("UPDATE `user_info` SET `messages` = `messages`+1 WHERE username='$username'"); echo "Message sent to $kill_username!"; } ?> Link to comment https://forums.phpfreaks.com/topic/101347-if-statement-problems/#findComment-518384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.