mysql - How to pass variables from one PHP file to another using HTML links? -


    //db connection    $sql = "select `city`,`country` infotab";    $result = $conn->query($sql);     while ($row = $result->fetch_assoc()) {      echo  $row["city"].$row["country"]"<a href='order.php'>order</a>"; } 

table output:

http://imgur.com/jh2vzbf

this code select data. additionally, there reference order.php on every line. when user clicks on reference( <a href> clause), opens order.php , there need know row user selected work these data.

change code to:

while ($row = $result->fetch_assoc()) {              echo  $row["city"] . $row["country"] . "<a href='order.php?city=" . $row["city"] . "&country=" . $row["country"] . "'>order</a>"; } 

in order.php can access these values using $_get["city"] , $_get["country"] variables contain values <a href> link on previous page. example, running echo $_get["city"]; output city name.

edit: @rizier123 pointed out, using unique id might more prone errors in case database contains more 1 entry same city or country. should consider introducing id in table structure , using in link order.php.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -