-1

Hello i have a syntax error in my code which is

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\project\addProduct.php on line 43

here is My code

mysqli_query($db_connect, "INSERT INTO `product` (`pname`, `pid`, `disc`, `price`, `size`, `tage`, `remarks`, `catid`, `img1`, `img2`, `img3`)
                values('$_POST[pname]','$_POST[pid]','$_POST[pdisc]','$_POST[pprice]','$_POST[page]','$_POST[prem]','$_POST[psize]' ,'$_POST[pcat]',
                '$_FILES['img1']['name']','$_FILES['img2']['name']','$_FILES['img3']['name']')");
Qirel
  • 25,449
  • 7
  • 45
  • 62
juju
  • 1
  • 1
  • 2
    **WARNING:** When using `mysqli` you should be using [parameterized queries](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and [bind_param](http://php.net/manual/en/mysqli-stmt.bind-param.php) to add user data to your query. DO NOT use string interpolation or concatenation to accomplish this because you have created a severe [SQL injection bug](http://bobby-tables.com/). **NEVER** put `$_POST`, `$_GET` or **any** user data directly into a query, as it can be very harmful if someone seeks to exploit your mistake. – Blue May 21 '17 at 13:41

1 Answers1

1

To solve your current issue, remove the single quotes from your $_FILES array:

mysqli_query($db_connect, "INSERT INTO `product` (`pname`, `pid`, `disc`, `price`, `size`, `tage`, `remarks`, `catid`, `img1`, `img2`, `img3`)
                values('$_POST[pname]','$_POST[pid]','$_POST[pdisc]','$_POST[pprice]','$_POST[page]','$_POST[prem]','$_POST[psize]' ,'$_POST[pcat]',
                '$_FILES[img1][name]','$_FILES[img2][name]','$_FILES[img3][name]')");

To solve your main problem, read this.

Blue
  • 22,608
  • 7
  • 62
  • 92