-2

when I use postman agent to pass the data into the database it prompt error in the code but I cant figure out what is the error

insert1.php

<?php
    $CN=mysql_connect("localhost","root","");
    $DB=mysqli_select_db($CN,"iostest");
    
    $name=$_POST['name'];
    $email=$_POST['email'];
    $password=$_POST['password']
    
    $IQ="insert into scan(name,email,password) values('$name','$email','$password')";
    
    $R=mysql_query($CN,$IQ);
    
    if($R)
    {
        $Message="succeddful"
    }
    else
    {
        $Message="error"
    }
    
    echo($Message);
?>

the error: Parse error: syntax error, unexpected variable "$IQ" in D:\xammp\htdocs\api\insert1.php on line 9

in this line

$IQ="insert into scan(name,email,password) values('$name','$email','$password')";
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
d.chan
  • 136
  • 9
  • 1
    `mysql_*` functions are deprecated! Please read [Why shouldn't I use mysql_* functions in PHP?](https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php?noredirect=1&lq=1) – brombeer Jun 15 '22 at 05:27

3 Answers3

0

You are missing semicolon ; in line 7, 15, and 19.

Refer below:

$password=$_POST['password'];
$Message="succeddful";
$Message="error";
Ejardy
  • 101
  • 1
  • 4
  • 14
-1

Use this:

mysqli_query($CN, $IQ);

this will may work

-1

Things to check:

  • You are missing multiple semicolons in your code
  • You are mixing mysql and mysqli in your code (use mysqli)
  • You are wide open to SQL injects
slaakso
  • 8,331
  • 2
  • 16
  • 27