0

After update wamp php 5.6 php insert not working...what i do wrong? Before update same code work fine.

<form action="signup.php" method="POST">
         <input class="insert" name="firstname" required id="firstname-signup" type="text" value="" placeholder="First name"><br><br>
         <input class="insert" name="lastname" required id="lastname-signup" type="text" value="" placeholder="Last neme"><br><br>
         <input class="insert" name="email" required id="email-signup" type="text" value="" placeholder="Email"><br><br>
         <input class="insert" name="password" id="password-signup" type="text" value="" placeholder="Password"><br><br>
 <input class="submit" name="submit" id="button-signup" type="submit" value="Signup">
         </form>


<?php    
     if (isset($_POST['submit'])){

         session_start();
         $firstname = $_POST['firstname'];
         $lastname = $_POST['lastname'];
         $email = $_POST['email'];
         $password = $_POST['password'];

    $sql = "INSERT into user ( firstname, lastname, email, password ) VALUES ('$firstname','$lastname', '$email', '$password' )";
    $result = mysqli_query($con,$sql);

    header('location: login.php');


     }
?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
sanel
  • 1
  • 1
  • 1
    Could you expand on _"not working"_, please? Error message on the screen? Checked your error log? Is the mysql-extension installed? – M. Eriksson Feb 03 '17 at 22:16
  • 2
    You are wide open to [SQL Injections](http://php.net/manual/en/security.database.sql-injection.php) and should really use [Prepared Statements](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) instead of concatenating your queries. Specially since you're not escaping the user inputs at all! – M. Eriksson Feb 03 '17 at 22:16
  • 2
    Hash your users passwords as well. – chris85 Feb 03 '17 at 22:17
  • 2
    you're probably outputting before header but not looking for it – Funk Forty Niner Feb 03 '17 at 22:17
  • and we don't know if you did connect with the same api here – Funk Forty Niner Feb 03 '17 at 22:17
  • 2
    `header('location: login.php');` after you have outputted data should give you a `headers already sent`-error – M. Eriksson Feb 03 '17 at 22:17
  • 2
    error reporting and check for errors on the query but am betting on headers sent – Funk Forty Niner Feb 03 '17 at 22:18
  • Not working = not insert in database, no errors. Update and select work fine... – sanel Feb 03 '17 at 22:19
  • **Check................... for errors** - You say it's working; well then, ok. *bye* – Funk Forty Niner Feb 03 '17 at 22:20
  • So, have you checked the error log, or do you mean that you don't see any errors on the screen? Check that error reporting is turned on. Set it to `E_ALL` That code should definitely put stuff in your error log. Please read: [How do I get PHP errors to display?](http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) – M. Eriksson Feb 03 '17 at 22:20
  • I move headers but same, not inserting in database..., no errors??? – sanel Feb 03 '17 at 22:24
  • 1
    Did you hit the submit button? Also, where is your $con variable initialised and why are you starting a session that's not being used for anything? Oh.. and why are you letting me delete your users table? https://i.stack.imgur.com/G0ifh.png – Peter Featherstone Feb 04 '17 at 01:34
  • $con variable is in same page, session move..., still a same... – sanel Feb 04 '17 at 08:58

0 Answers0