-4

I have typed the code but it shows the error in querying.

<?php
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$class=$_POST['class'];
$gen=$_POST['gender'];
$email=$_POST['email'];
$dbc= mysqli_connect('localhost','sam','xxx','student') or die('error in mysql');           
$query="INSERT INTO student(firstname,lastname,class,gender,email)"
    ."VALUES('$firstname','lastname','class','gen','email')";
$result= mysqli_query($dbc,$query) or die('error in querying');
mysqli_close($dbc);
echo 'your name:'.$name.'<br>';
echo 'your class:'.$class.'<br>';
echo 'your email:'.$email.'<br>';
echo 'your gender:'.$gen.'<br>';
?>
scragar
  • 6,764
  • 28
  • 36

2 Answers2

1

It should be:

$query="INSERT INTO student(firstname,lastname,class,gender,email)"
    ." VALUES('$firstname','lastname','class','gen','email')";

with space before VALUES.

I don't know if you want to insert other variables values into database or just put strings here for test only, so maybe you wanted also:

$query="INSERT INTO student(firstname,lastname,class,gender,email)"
    ." VALUES('$firstname','$lastname','$class','$gen','$email')";

What you want to do are the basics of PHP. So look at PHP manual to learn how to use variables and mysqli

In addition this code is very unsafe. Read more about SQL Injection

Community
  • 1
  • 1
Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
0

try the below code it will work

$query="INSERT INTO student(firstname,lastname,class,gender,email) VALUES('$firstname','$lastname','$class','$gen','$email')";
Ajit Singh
  • 1,132
  • 1
  • 13
  • 24