0

Im trying to insert data into my database, it works when i dont use the $_POST['wagee'], but I cant get it to work pulling data from my form. Any help is greatly appreciated. Thank you!

here is the error I get:

You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near ' '2')' 
at line 2

This is my code:

<?php 

$message = ""; 

if(isset($_POST['addhoursbutton']))
{
   addwage();
} 

function addwage() {
include 'components/sql/config.php';

$sqlupdateincome = "INSERT INTO income (username, projectname, hourlywage, totalhours)
VALUES ('John', 'Ochrom Test', ". $_POST['wagee'] .", '2')";

if ($conn->query($sqlupdateincome) === TRUE) {
    echo "New record created successfully";
} else {
     echo  "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
}
?>
Nimeshka Srimal
  • 8,012
  • 5
  • 42
  • 57
  • Well, not knowing what the form looks like, should the POST array reference be `wages` instead of `wagee`? – Paul T. Jul 07 '18 at 03:47
  • hahaha yes, i spelt it like that for testing reason. Sometimes I try changing the words around just in case it has to do with anything being repeated – Sebastian Shearer Jul 07 '18 at 09:26

1 Answers1

1

I think you missed the quotes around the value.

It should be '". $_POST['wagee'] ."'

$sqlupdateincome = "INSERT INTO income (username, projectname, hourlywage, totalhours)
VALUES ('John', 'Ochrom Test', '". $_POST['wagee'] ."', '2')";

It's not recommended to use user inputs directly in your queries though. I hope this is only for learning purposes.

Nimeshka Srimal
  • 8,012
  • 5
  • 42
  • 57