0

I spent hours trying to figure out my problem but no luck :/ I am running this query:

if($_POST) {
    $ask_name = mysqli_real_escape_string($connect, $_POST['ask_name']);
    $ask_email = mysqli_real_escape_string($connect, $_POST['ask_email']);
    $ask_text = mysqli_real_escape_string($connect, $_POST['ask_text']);
    $ask_category = mysqli_real_escape_string($connect, $_GET['categ']);
    $ask_time = date("d-F-Y");

    if($ask_name = "" || $ask_email == "" || $ask_text == "" || $ask_category == "") {
        $msg = '<span class="fa fa-exclamation-triangle fa-lg"></span> Fill Out All Inputs Please';
    }

    else {  
        $insert_post = mysqli_query($connect, "INSERT INTO forum_posts (name, email, text, category, time) VALUES ('$ask_name', '$ask_email', '$ask_text', '$ask_category', '$ask_time')");
        header('Location: forum.php?categ=' .$ask_category);
        exit(); 
    }
}

This is the form in my php file

<!--Insert Post-->
   <form id="ask-question" method="post" name="ask_question" action="">
    <label for="ask-name">Your Name</label><br>
    <input type="text" name="ask_name" id="ask-name"><br>
    <label for="ask-email">Your E-Mail (Won't be displayed)</label><br>
    <input type="email" name="ask_email" id="ask-email"><br>
    <label for="ask-text">Your Question</label><br>
    <textarea name="ask_text" id="ask-text"></textarea><br>
    <input type="submit" name="post_submit" value="Ask Now" id="post-submit">
    <?php if(isset($msg)) { echo('<p>' .$msg. '</p>'); } ?>
   </form>

The problem is that the query does not insert the "name" value. All other values are successfully inserted into my mysql database, but the "name" value.

Any ideas please? Thank you very much!

2 Answers2

4

You have used single = sign instead of double in your if condition.

Change

if($ask_name = ""...

to

if($ask_name == ""...
              ^

otherwise you are assigning empty string to that variable

n-dru
  • 9,285
  • 2
  • 29
  • 42
  • Thank you too, very much !!! That was the only line I was not even bothering to check...I waas like,nah, this is too simple to be causing any problem...thanks – user3316749 Feb 02 '16 at 10:02
  • it is common not to see own mistakes - that's why this is good to ask... – n-dru Feb 02 '16 at 10:03
0

$ask_name = "" means you are assigning blank value to that variable.

Change

if($ask_name = "" || $ask_email == "" || $ask_text == "" || $ask_category == "")

to

if($ask_name == "" || $ask_email == "" || $ask_text == "" || $ask_category == "")
AnkiiG
  • 3,468
  • 1
  • 17
  • 28