Rkboss Rkboss - 4 months ago 14
PHP Question

How do I get 'id' from database to update a particular row?

I am trying to update a row which is already in database, and i am using above code for that but it gives me error as 'undefined id', so how can i do this.....please help me!!!

if(isset($_POST['sub']))
{
$getid="select id from login";
$res=mysql_query($getid);
$ids=$_GET[$row['id']];

$about=$_POST['desc'];
$pri=$_POST['price'];
$ride=$_POST['fly'];
$city=$_POST['ct'];

$flt="";
foreach($ride as $entry){
$flt .= $entry.",";
}
$ct="";
foreach($city as $entry){
$ct .= $entry.",";
}

$query ="UPDATE login SET rides='$flt',price=$pri,about='$about',city='$ct' WHERE id='$ids'";

$result = mysql_query($query);
echo $result;
if(!$result) {
echo '<script language="javascript">';
echo 'alert("something went Wrong...:(");
location.href="edit.php"';
echo '</script>';
}
else{
echo '<script language="javascript">';
echo 'alert("successfully updated!!!");
location.href="edit.php"';
echo '</script>';
}
}

Answer
$res=mysql_query($getid); $ids=$_GET[$row['id']];

You need to fetch the id by executing and fetching If you want all ids then you must store it in array and then implode it or concatenate in a single variable then use it in where condition of update query use IN clause