0

I have created one IMS in that I am trying to fetch data from one table from the database and display it in drop-down form to another page. In the database, I have created one table named a party in that table one column named party_name is available and I have to fetch that column data to my order page. Below is my Code. If anyone knows a solution than please help.

<select name="party[]" style="width:100%;" required>
   <?php
     $result=mysql_query("SELECT * FROM partys");
     while ($row = mysql_fetch_array($result)) {
   ?>
   <option value="<?php echo $row['id'];?>"><?php echo $row['party_name'];?></option>
   <?php
    }
   ?>
</select>
Grant
  • 2,413
  • 2
  • 30
  • 41

1 Answers1

0

Firstly: mysql extension is deprecated, you should use at least mysqli_*:

Secondly: try the below example, replacing the database connection string variables with your database credentials:

<select name="party[]" style="width:100%;" required>
  <option value="">-- Please select --</option>
<?php
  $dbc = mysqli_connect('localhost', 'userName', 'password', 'databaseName')
    or die('Error connecting to MySQL server.');
  $query = "SELECT * FROM partys";
  $result = mysqli_query($dbc, $query);
  while ($row = mysqli_fetch_array($result)) {
?>
  <option value="<?php echo $row['id'];?>"><?php echo $row['party_name'];?></option>
<?php } ?>
</select>
Grant
  • 2,413
  • 2
  • 30
  • 41
  • Still blank drop down is coming –  Apr 04 '18 at 13:44
  • Did you add your database connection credentials? What are the table columns called? – Grant Apr 04 '18 at 13:45
  • Can you cut and paste the EXACT table Name and the EXACT column names from that table? – Grant Apr 04 '18 at 13:51
  • It worked perfectly but right now issue i am facing is i unable to change value from drop down(in partys table 3 currently three records are available) by default it is selecting first value from table –  Apr 04 '18 at 14:09
  • Can you show me the HTML that comes back for the query? – Grant Apr 04 '18 at 14:15
  • Add this below the – Grant Apr 04 '18 at 14:19
  • @RuchirShah - please accept my answer if you have come right – Grant Apr 04 '18 at 14:44
  • @RuchirShah - my pleasure, can you please accept my answer as the solution Thanks! – Grant Apr 05 '18 at 14:26