Update data from MYSQL, PHP to release a button

if(isset($_GET["id"])){ $sql=mysql_query("SELECT * FROM aMovie WHERE aName= '{$_GET['id']}'"); $row=mysql_fetch_object($sql); } <input type = "text" name = "name" value = "<?php echo $row->aC; ?>"/> <select name = "name" > <option value = "" <?php echo ($row->aC== "Deadpool") ? 'selected = "selected"': '';?>">Deadpool</option> <option value = "" <?php echo ($row->aC == "BATMAN VS SUPERMAN") ? 'selected = "selected"': '';?>">BATMAN VS SUPERMAN</option> </select> 

Suppose aMovie is my table name, and my table has aName and and aC. However, I would like to display aName that matches aC ["Deadpool" or "Batman Vs Superman"] and display it in the drop-down list. It works only for the input type, but not for the drop-down menu button.

+5
source share
4 answers

Your <select> should look like this:

 <select name = "name" > <option value="Deadpool" <?=($rows->aC == "Deadpool" ? 'selected="selected"': '')?>>Deadpool</option> <option value="BATMAN VS SUPERMAN" <?=($rows->aC == "BATMAN VS SUPERMAN" ? 'selected="selected"': '')?>>BATMAN VS SUPERMAN</option> </select> 

selected="selected" will be used outside the value attribute.

UPDATE:

As @ Maninderpreet-Singh mentioned, you also need to change $row to $rows .

+3
source

try to change

 <option <?php echo($row->aC== "Deadpool") ? 'selected = "selected"': '';?> value="<?php echo $row->aC;?>">Deadpool</option> 
+1
source

try with this and you use another input variable

 <input type = "text" name = "name" value = "<?php echo $rows->aC; ?>"/> 

$row and $rows are different

  <option value = "<?php echo $row->aC; ?>" <?php echo ($row->aC == "Deadpool") ? 'selected':'';?>">Deadpool</option> <option value = "<?php echo $row->aC; ?>" <?php echo ($row->aC == "BATMAN VS SUPERMAN") ? 'selected': '';?>">BATMAN VS SUPERMAN</option> 
+1
source
 <input type = "text" name = "name1" value = "<?php echo $rows->aC; ?>"/> <select name = "name2" > <option value = " <?php echo($row->aC); ?>" <?php echo($row->aC=="Deadpool")?'selected': '';?>>Deadpool</option> <option value = " <?php echo($row->aC);?>" <?php echo($row->aC == "BATMAN VS SUPERMAN")?'selected': '';?>>BATMAN VS SUPERMAN</option> </select> 
+1
source

Source: https://habr.com/ru/post/1246931/


All Articles