Jump to content

if statement problems


palm88

Recommended Posts

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

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!";
}

 

 

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!";

}
?>

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.