0

the code is as under.....The Error is Invalid Query. and it is not Updating the table in database. Anyone help please..

<?php
include "connection.php";
$selecteditem=$_POST['salesitem'];
$name=$_POST['name'];
$type=$_POST['type'];
$purchasePrice=$_POST['purchase'];
$salePrice=$_POST['sale'];
$iteminPack=$_POST['nofiteminpack'];
$location=$_POST['location'];
$GenName=$_POST['genric'];
$norcotics=$_POST['radio1'];
$stockinHand=$_POST['stockInHand'];
$conn= mysql_connect("localhost","root","");
mysql_select_db("alkausar",$conn);
$qr2="UPDATE `item` SET name=$name,type=$type,pPrice=$purchasePrice,sPrice=$salePrice,Iteminpack=$iteminPack,location=$location,genricName=$GenName,norcotics=$norcotics,stockInHand=$stockinHand WHERE name='$selecteditem'";
$qr3=mysql_query($qr2);
echo $qr3;
if(!$qr3){
            die('Invalid Query:'.mysql_error());
            }
?>
xNeyte
  • 612
  • 4
  • 18
  • 4
    String values needs to be in quotes `name='$name',type='$type'....` better use Prepared Statement. – Abhik Chakraborty May 22 '15 at 12:03
  • you need to do like this `name='$name'`. you missed single quotes.Please update and try. – Krishna38 May 22 '15 at 12:03
  • 1
    Please, stop using mysql functions, it is deprecated and will not work in the future. Use PDO or mysqli instead, and check at prepared statement. – xNeyte May 22 '15 at 12:05
  • print the query on front and execute on back end directly..you will come to know more by prcatical – lakshman May 22 '15 at 12:08

1 Answers1

0

You should put all inputs in '

$qr2="UPDATE `item` SET
name='$name',
type='$type',
Price='$purchasePrice',
sPrice='$salePrice',
Iteminpack='$iteminPack',
location='$location',
genricName='$GenName',
norcotics='$norcotics',
stockInHand='$stockinHand'
WHERE name='$selecteditem'";

Depending on what you have in $_POST this could already solve your problem.

If not, echo $qr2 and try to run in the the DB manually and see if you get an error message.

Falko
  • 17,076
  • 13
  • 60
  • 105
DocRattie
  • 1,392
  • 2
  • 13
  • 27