-2
$marka = $_POST['marka'];
$model = $_POST['model'];
$godiste = $_POST['godiste'];
$cena = $_POST['cena'];

$query = "INSERT INTO `auto` (`id`, `marka`, `model`, `godiste`, `cena`) VALUES (NULL, '$marka', '$model', '$godiste', '$cena');"

if(mysqli_query($connection,$query)) {
    echo "New record created";
} else {
    echo "Error: " . $query . "<br>" . mysqli_error($connection);
}

I can't find what is problem here:

Parse error: syntax error, unexpected 'if' (T_IF) in C:\wamp\www\autoplac\forma.php on line 16

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
BanDox
  • 1
  • 2

3 Answers3

1

Do not stuff user-input values into query strings. The usual reason given is SQL injection -- and that is an important reason. An even better reason is that you can get unexpected syntax errors, because the content of the string interferes with the rest of the query.

It is easy enough to use parameters. Start with mysqli_prepare(). Here is a place in the documentation to start.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • 1
    This is really a suggestion/comment. The actual issue here is the misplaced semi-colon in `'$cena');"` causing the parse error. `Parse error: syntax error, unexpected 'if' (T_IF)...` – Funk Forty Niner Nov 19 '16 at 15:54
0

You forgot the semicolon AFTER the Double cuote in the query sentence

-1

Missing ; on end of line

$query = "INSERT INTO `auto` (`id`, `marka`, `model`, `godiste`, `cena`) VALUES (NULL, '$marka', '$model', '$godiste', '$cena');"

should be

$query = "INSERT INTO `auto` (`id`, `marka`, `model`, `godiste`, `cena`) VALUES (NULL, '$marka', '$model', '$godiste', '$cena');";
sajushko
  • 418
  • 4
  • 13