0

In below image , Once we click on "submit" button in third column , I want to copy the tracking id from Table 2's column to Table 1's column....

Table orders

enter image description here

displayed tracking id" in 4th column

enter image description here

I saved order information in table orders [ Table 1 ]

enter image description here

I saved tracking ids in table awbno [ Table 2 ] & in column tracking_two

enter image description here

track.php

<?php

$con = mysqli_connect("localhost","root","","do_management4");

$result = mysqli_query($con,"SELECT * FROM orders");

echo "<table border='1'>
<tr>
<th>order</th>
<th>payment</th>
<th>generate</th>
<th>tracking id</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
$id = $row['id'];
echo "<tr>";
echo "<td>" . $row['order_id'] . "</td>";
    echo "<td>" . $row['payment_type'] . "</td>";

    echo "<td>";
    if (empty($row['tracking_one'])) {
        echo "<form method='post' action='call.php'>";
        echo "<input type ='hidden' name='id' value='$id'>
          <input type='submit'>
          </form>";
    }
    echo "</td>";
echo "<td>" . $row['tracking_one'] . "</td>";

echo "</tr>";
}
echo "</table>";

mysqli_close($con);

?>

call.php

<?php

$con = mysqli_connect("localhost","root","","do_management4");
$result = mysqli_query($con,"SELECT * FROM orders");

$id = $_POST['id']; 
$r = ""; 

$sql = $con->query("update orders set tracking_one = '$r' WHERE id ='$id'");
mysqli_close($con);

?>

I did't found any particular query in google, What query will help me ?

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • `$r` is an empty string the update statement set `tracking_one` to empty – Masivuye Cokile Nov 19 '18 at 13:05
  • @MasivuyeCokile Thanks for reply, yes, i am not getting what query to post, i kept it empty...... –  Nov 19 '18 at 13:06
  • How come you don't perform a JOIN on the tables so you don't need to click the generate button in the first place? – Matthias Bö Nov 19 '18 at 13:18
  • @MatthiasBö Thanks for reply, we have 100 rows in `table2` & 10 rows in `table1`..... is there any other way ? –  Nov 19 '18 at 13:20
  • Side note: `
    ` cannot be made a child of ``.
    – Funk Forty Niner Nov 19 '18 at 13:21
  • @FunkFortyNiner Thanks for reply , means if i use
    inside will not work in my case ? I dont know much about this..... but i used `$r` to generate random numbers before & it worked fine for me, or did i misunderstood your statement ?
    –  Nov 19 '18 at 13:26
  • [This answer](https://stackoverflow.com/a/5967613/1415724) in another question explains it. – Funk Forty Niner Nov 19 '18 at 13:32
  • @FunkFortyNiner Thanks for the link, i will check it.... –  Nov 19 '18 at 13:34
  • Welcome. That could be contributing to the problem. Look at your HTML source and you can see what is being populated (or not) and how. If something fails, enable error reporting and error checking on the query. What you're trying to pull in for data in the form, is probably a GET method for the id rather than POST. – Funk Forty Niner Nov 19 '18 at 13:36

1 Answers1

0

Your query should be something like this

$sql = $con->query("update orders set tracking_one = (select tracking_two from awbno WHERE id =$id)");
  • Thanks , I tried like `$sql = $con->query("update orders set tracking_one = select tracking_two from awbno WHERE id ='$id' ");` , is it correct ? because i got result as [link](http://sbdev1.kidsdial.com/ecom1/ekart/track.php) –  Nov 19 '18 at 13:52
  • yes, you can check which id you are sending. If that transaction id is updated then query is working fine – Yash Fatnani Nov 20 '18 at 09:11
  • means like this : `$sql = $con->query("update orders set tracking_one = select tracking_two from awbno WHERE id =1 ");` ? –  Nov 20 '18 at 09:13
  • yes check id = 1 in table awbno which transaction id you see their same should be updated in orders table – Yash Fatnani Nov 20 '18 at 09:15
  • I tried that code, but i got same result as before [here](http://sbdev1.kidsdial.com/ecom1/ekart/track.php) , also as i mentioned in question, there is `tracking id : 14105818000000` for id :1 in `awb table`.... but still i got same result.... –  Nov 20 '18 at 09:18
  • Or is it possible to do other way ? means once we click on button , copy the values present in `table 1- orders` to `table 2 - awbno`.... –  Nov 20 '18 at 09:24
  • id field in order and id field in awb table has any relation? – Yash Fatnani Nov 20 '18 at 09:24
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/183935/discussion-between-vickey-colors-and-yash-fatnani). –  Nov 20 '18 at 09:25
  • Then how do both tables relate each other? which value is to updated in table 1 – Yash Fatnani Nov 20 '18 at 09:36