-1

i am looking to fetch data from database stored in value form.As when i am treid to echo value it displays value which i don't want.

so when i echo country it displays AX where i am looking for Aland Islands is value is stored in database.

      <form action="reg_page.php" id="regform">
    Username:<input type="text" name="username">
      Password:<input type="text" name="password">
    Confirm Password:<input type="text" name="conpassword">
    Country:    
   <select id="city" name="city" required>
      <option value="AX">Aland Islands</option>

    <input type="submit">
  </form>

include("db.php"); // include the connection object from the DBConnection.php 
if ($_SERVER['REQUEST_METHOD'] == 'POST') { 
    $inUsername = $_POST["username"]; 
    $inPassword = $_POST["password"]; 
    $encryptPassword = password_hash($inPassword, PASSWORD_DEFAULT); 
    $inCountry = $_POST["city"]; 
    $stmt = $db->prepare("INSERT INTO users(username,password,center) VALUES(?, ?,?)"); 
    $stmt->bind_param("sss", $inUsername , $encryptPassword, $inCountry); 
    $stmt->execute(); 
    $result = $stmt->affected_rows; 
    $stmt -> close(); 
    $db -> close(); 
    if($result > 0)
lrvanjan
  • 59
  • 7
  • 2
    please show how you store to database, also how you send send the form to php. Because it's more a matter of what you safe than what you echo.. – Jeff Apr 15 '18 at 10:43
  • sidenote: having an element-id with a space in it might not always work. (and til now you don't have that element anyway) – Jeff Apr 15 '18 at 10:45
  • 1) That is a dropdown. 2) the select tag does not have an ID 3) only the select tag can have an ID – RiggsFolly Apr 15 '18 at 10:46
  • another possibility would be to keep 'AX' in db and have a reference table (or array) that then maps to "Aland Island" – Jeff Apr 15 '18 at 10:46
  • please add the code to your question, don't paste it as comment. tahnks! – Jeff Apr 15 '18 at 10:47
  • **Can you read code in a comment?** Most of us cannot. Please [edit](https://stackoverflow.com/posts/49841004/edit) your question and add the code to that correctly formatted – RiggsFolly Apr 15 '18 at 10:48
  • ok.so how to proceed further those answer doesnt help me – lrvanjan Apr 15 '18 at 10:53
  • **COUNT** your column names and then count your `?` parameters – RiggsFolly Apr 15 '18 at 10:54
  • ___ok.so how to proceed further those answer doesnt help me___ Well you chnaged your question completely since the question was closed. So I will reopen it so someone can close it as a TYPO – RiggsFolly Apr 15 '18 at 10:55
  • And now you changed it again!!!!! I give up – RiggsFolly Apr 15 '18 at 10:57
  • If you dont show us the ACTUAL code you are running HOW can we try and help you!!! – RiggsFolly Apr 15 '18 at 10:58
  • @RiggsFolly Sir changed code sorry for so much editing – lrvanjan Apr 15 '18 at 11:22

1 Answers1

0

Here's my suggestions.
In an ideal world you would have an extra database table that holds city-keys and the responding city names.

// fiktive Table Cities with dummy values
id    |  Short |  Name
--------------
24    |  VIE   |  "Vienna"
53    |  AX    |  "Aland Islands"
....

You would then store the id or the key in table users. When you then get the data you'd do a join on both tables.

A more simple (but not a good final) solution would be to "store" those pairs hardcoded as array, which you could reference when you output it:

// array with cities you need
$cities = Array("AX"=>"Aland Island", "VIE"=>"Vienna", ....);

// data coming from database
$cityCode = "AX"; 
// would be something like 
$cityCode = $row['city'];

// then you can do:
echo $cities[$cityCode]; // will output "Aland Island"
Jeff
  • 6,895
  • 1
  • 15
  • 33