I am trying to update the price of my product based on ID. ID and price both are string.My code is
$result = mysqli_query($con,"SELECT id FROM `TABLE 1` ");
while($row = mysqli_fetch_array($result))
if(strcmp($row['id'],$v)==0)//id exists in database=> update
mysqli_query($con,"UPDATE `TABLE 1` SET `price`=".$cols[$i]." WHERE `id`=$v");
Where cols is my multidimensional array. It update the record correctly whose type is integer but not those are String.But product with id 101-1 not updated correctly.Where I am missing?
If $v or $cols[$i] is the String that is not updating correctly,
WHERE `id`='$v' `price`='".$cols[$i]."'
You need to use ' ' around a string in the query.
Product id is a primary key and integer and it doesn't support the
101-1 value, from 101-1 which one is id related I mean 101 0r 1, in that use use split with
- and use that.
Can you replace this from existing code,
$price = trim($cols[$i]); mysqli_query($con,"UPDATE `TABLE 1` SET `price`='".$price."' WHERE `id`='".$v."' ");