1

Can anyone explain why this insert is not working?

if(isset($_POST['send'])){
    $query = 'INSERT INTO subsciber(data, ip, email) 
          VALUES(CURRENT_TIMESTAMP, "'.$_SERVER['REMOTE_ADDR'].'", "'.$_POST['email'].'")';
    $result =  @mysqli_query($dbc, $query);
}

And forms code looks like this:

<div class="row">
     <div class="col-md-4 col-md-offset-4 col-sm6-6 col-sm-offset-3 ">
         <form class="form-inline" role="form" method="post">
            <div class="form-group">
                <label class="sr-only" for="exampleInputEmail2">Email address</label>
                <input name='email' id="email" type="email" class="form-control transparent" placeholder="Your email here...">
            </div>
            <button type="submit" name='send' value='send' class="btn btn-danger btn-fill">Notify Me</button>
        </form>
    </div>
</div>
Dave
  • 3,073
  • 7
  • 20
  • 33
Alphonse
  • 61
  • 1
  • 8

4 Answers4

1

You should include mysqli error function to see your errors

    if(isset($_POST['send'])){
        $query = 'INSERT INTO subsciber(data, ip, email) 
              VALUES(CURRENT_TIMESTAMP, "'.$_SERVER['REMOTE_ADDR'].'", "'.$_POST['email'].'")';
//echo $query; to see query output
        $result =  mysqli_query($dbc, $query) or die(mysqli_error($dbc));
    }

Also data is mysqli keyword so use backtick around this

 $query = 'INSERT INTO subsciber(`data`, ip, email) 
                  VALUES(CURRENT_TIMESTAMP, "'.$_SERVER['REMOTE_ADDR'].'", "'.$_POST['email'].'")';
Passionate Coder
  • 7,154
  • 2
  • 19
  • 44
-1

Your form does not have an action property:

Do this:

<form action="the url to your PHP script">
-2

Replace

@mysqli_query($dbc, $query);

with

mysqli_query($dbc, $query);
mahethekiller
  • 514
  • 3
  • 17
  • That won't help. `mysqli_query()` doesn't report MySQL errors automatically, you have to print `mysqli_error($dbc)`. – Barmar Oct 18 '16 at 06:44
-2

instead of single quotation you can use doublequotation

Try This one

if(isset($_POST["send"])) {
    .....
}
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Why would that make a difference? There's nothing in `send` that behaves differently depending on the type of quotes. – Barmar Oct 18 '16 at 06:42
  • i have faced same problem one time then i changed single quotation to doublequotation it working fine – Mathan kumar Oct 18 '16 at 06:47
  • It must have been some other problem. See http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php – Barmar Oct 18 '16 at 06:48