1

i'm trying to show notice to user if information sent property:

"نظر شما با موفقیت ثبت شد"

or else show notice if he or she try to click on button when fields are empty:

"لطفا فیلدهای خالی را پر کنید"

but always it show me 'else' part when i run my page.

<?php
if(isset($_POST['send_shekayat']))
{
  if(!empty($_POST['body']) AND !empty($_POST['title']))
    {
    $user_id =$fgmembersite->UserID();

       $db_host = 'localhost';
       $db_name= 'site';
       $db_table= 'shekayat';
       $db_user = 'root';
       $db_pass = '';

    $con = mysql_connect($db_host,$db_user,$db_pass) or die("خطا در اتصال به پايگاه داده");

    mysql_query("SET NAMES 'utf8'", $con);
    mysql_query("SET CHARACTER SET 'utf8'", $con);
    mysql_query("SET character_set_connection = 'utf8'", $con);

    $selected=mysql_select_db($db_name, $con) or die("خطا در انتخاب پايگاه داده");
    mysql_query("SET CHARACTER SET  utf8");
    $ins="INSERT INTO $db_table (user_id,title,body) 
                VALUES('$user_id','" . mysql_escape_string($_POST['title']) . "','" . mysql_escape_string($_POST['body']) . "')";
    $saved=mysql_query($ins );
    mysql_close($con); 
    echo '<script language="javascript">';
    echo 'alert("نظر شما با موفقیت ثبت شد")';
    echo '</script>';
    echo '<script>window.location.href = "submit_pishnahad.php";</script>';

    }
}
else
{
    echo '<script language="javascript">';
    echo 'alert("لطفا فیلدهای خالی را پر کنید")';
    echo '</script>';
    echo '<script>window.location.href = "submit_pishnahad.php";</script>';
}
?>

And here is one textbox one textfield and one button to send:

<form name="form2" method="post" action="" accept-charset='UTF-8'>

<div class='container' dir="rtl" >
    <label for='title'>موضوع: </label>
    <input type='text' name='title' id='title'/><br/>

</div>

<div class='container' dir="rtl" >
    <label for='body'>توضیحات: </label> <br />
    <textarea name="body" id="body" cols="" rows="" style="width:300 ;height:300"></textarea>

</div>

<div class='container'>
    <input type='submit'  name='send_shekayat' value='ارسال اطلاعات' />

</div>
</form>
1
  • use this $_SERVER['REQUEST_METHOD'] == 'POST' instead of if(isset($_POST['send_shekayat'])) Commented Nov 9, 2015 at 12:30

3 Answers 3

1

Try this. This working fine for me. Hope it works for you also.

<?php
if(isset($_POST['send_shekayat']))
{
  if(!empty($_POST['body']) || !empty($_POST['title']))
    {
        .
        . //Your Code
        .
        echo '<script language="javascript">';
        echo 'alert("Value Entered")';
        echo '</script>';
        echo '<script>window.location.href = "submit_pishnahad.php";</script>';
    }
    else
    {
        .
        .
        echo '<script language="javascript">';
        echo 'alert("Value Not Entered")';
        echo '</script>';
        echo '<script>window.location.href = "submit_pishnahad.php";</script>';
    }
}
?>
Sign up to request clarification or add additional context in comments.

4 Comments

yeah i found that problem also myself, its because of first if tag have to close after else tag as u wrote
Hi @sajad. Yeah. I personally checked this code. Your code is fine. Little modification required. So i did it. Write your code in place of //your code
If code works for you too, please let me know Mr @sajad. Thanks.
Happy To Help You. Enjoy Coding @sajad भाई. :)
0

use this

if($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['send_shekayat']))

Comments

0

i have to close if tag after else tag for working property:

<?php
if(isset($_POST['send_shekayat']))
{
    if(!empty($_POST['body']) AND !empty($_POST['title']))
    {
         $user_id =$fgmembersite->UserID();
         $db_host = 'localhost';
         $db_name= 'site';
         $db_table= 'shekayat';
         $db_user = 'root';
         $db_pass = '';

    $con = mysql_connect($db_host,$db_user,$db_pass) or die("خطا در اتصال به پايگاه داده");

    mysql_query("SET NAMES 'utf8'", $con);
    mysql_query("SET CHARACTER SET 'utf8'", $con);
    mysql_query("SET character_set_connection = 'utf8'", $con);

    $selected=mysql_select_db($db_name, $con) or die("خطا در انتخاب پايگاه داده");
    mysql_query("SET CHARACTER SET  utf8");
    $ins="INSERT INTO $db_table (user_id,title,body) VALUES('$user_id','" . mysql_escape_string($_POST['title']) . "','" . mysql_escape_string($_POST['body']) . "')";
    $saved=mysql_query($ins );
    mysql_close($con); 
    echo '<script language="javascript">';
    echo 'alert("نظر شما با موفقیت ثبت شد")';
    echo '</script>';
    echo '<script>window.location.href = "submit_pishnahad.php";</script>';

  }
  else
  {
    echo '<script language="javascript">';
    echo 'alert("لطفا فیلدهای خالی را پر کنید")';
    echo '</script>';
    echo '<script>window.location.href = "submit_pishnahad.php";</script>';
   }
}?>

1 Comment

Yup. Correct. You got it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.