MySQL Forums
Forum List  »  PHP

Select and Update in one query same table
Posted by: Munir Hossain
Date: July 12, 2020 04:35AM

Want to select 2 fields value from a table with where clouse and same time want to update a field from that table in this api

table01
=========
username password device_id code
1234567565 1234512345 0 hhhjjjkkk
1234567890 1246312345 2222 hhhjjjkkk
5445548574 1254512345 0 hhhjjjkkk
5474447543 6234512345 5675755 hhhjjjkkk


<?php
$code = $_GET["c"];
$device_1d = $_GET["di"];
header("Content-Type: text/xml");
$xmlBody = '<?xml version="1.0" encoding="UTF-8"?>';
mysql_connect("localhost","root","mypassword") or die (mysql_error());
mysql_select_db("kotha210") or die ("no database");

//$sql=mysql_query("select username,password from table01 where device_id = '0'"); // THIS QUERY GIVING ME USERNAME AND PASSWORD WITH NO ERROR BUT WANT TO UPDATE THE DEVICE_ID WITH GIVEN $device_1d FIELD. BUT CAN'T FIGURE OUT HOW TO DO IT.

$sql=mysql_query("START TRANSACTION;SELECT username,password FROM table01 WHERE device_id = '0' FOR UPDATE;UPDATE table01 SET device_id = '$device_1d' WHERE username = '??????';COMMIT");


while($row = mysql_fetch_array($sql)){
$username1 = $row["0"];
$secret1 = $row["1"];
$xmlBody .= '
<info>
<username>' . "$username1" . '</username>
<Password>'."$secret1".'</Password>
</info>';
}
echo $xmlBody; // output the gallery data as XML file for flash
?>

Munir Hossain

Options: ReplyQuote


Subject
Written By
Posted
Select and Update in one query same table
July 12, 2020 04:35AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.