# Solved: mysqli dropdown



## kirkwebsites (Sep 10, 2011)

Hi, the project is to create a dropdown (using mysqli) which displays the selected record 
and updates a field (lastused - the current date)in that record. Nothing happens when I 
click the submit button. Any help?


```
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Select email to view
[email protected]
paypal 
ebay

[CENTER]
```


```
<?php  
$lastused = (isset($_POST['lastused']))?1:0;   
$target = (isset($_POST['target']))?1:0;
$id = (isset($_POST['id'])) ? mysqli_real_escape_string($dbconnect, $_POST['id']) : '';   
$dbconnect = mysqli_connect('localhost','root','cookie')or die(mysqli_error($dbconnect));
$result = mysqli_query($dbconnect, "SELECT * FROM emailtbl");
    if($result === FALSE) { die(mysql_error()); }
    echo date('m/d/y');
// if($target=="email"){$target=$username;}
// $lastused = $row['CURDATE()']; 
$lastused = date('Y-m-d');
  ?>
  [HTML][TABLE]
   [TR]  
    [TH]target[/TH]
  [TH]username[/TH]
  [TH]password[/TH]
  [TH]emailused[/TH]
  [TH]lastused[/TH]
  [TH]purpose[/TH]
  [TH]saved[/TH] 
  [/TR][/HTML]
<?php

 while($row = mysql_fetch_array($result))  
   { 
echo "[TR]";
echo "[TD]" . $row['target'] . "[/TD]";
echo "[TD]" . $row['username'] . "[/TD]";
echo "[TD]" . $row['password'] . "[/TD]";
echo "[TD]" . $row['emailused'] . "[/TD]";
echo "[TD]" . $row['lastused'] . "[/TD]";
echo "[TD]" . $row['purpose'] . "[/TD]";
echo "[TD]" . $row['saved'] . "[/TD]";
 echo "[/TR]";
 echo "[/TABLE]

";
if (!empty($_POST['update_lastused']))
  { $update = mysqli_query($dbconnect, "UPDATE emailtbl SET lastused = '$lastused' WHERE id ='$id");
       if($update == false)
       { die("UPDATE FAILED: ".mysqli_error($dbconnect)); }
       echo "Success!";
  }
    else { echo "oops!"; }
  }
?>
```


```

```


----------



## kirkwebsites (Sep 10, 2011)

After a lot of research, I'm submitting new code for the MYSQLi project. 
I get the box & submit button but clicking the submit doesn't update value. 
<!DOCTYPE>Set taxrate

<?php
$con=mysqli_connect("localhost","root","cookie","homedb");
//============== check connection
if(mysqli_errno($con))
{echo "Can't Connect to mySQL:".mysqli_connect_error();}
else
{echo "Connected to mySQL
";}
//=============================
//This creates the drop down box
echo "";
echo ''.'---select locale/taxrate ---'.'';
$query = mysqli_query($con,"SELECT taxrate FROM numbers");
$query_display = mysqli_query($con,"SELECT * FROM numbers");
while($row=mysqli_fetch_array($query))
{ echo "".$row['taxrate']
.'';}
echo '';
?>

<?php
$id='';
$taxrate=''; 
$con=mysqli_connect("localhost","root","cookie","homedb");
if(mysqli_errno($con))
{echo "Can't Connect to mySQL:".mysqli_connect_error();}
if(isset($_POST['taxrate']))
{
$name = $_POST['taxrate'];
$fetch="SELECT taxrate FROM numbers WHERE taxrate = '".$name."'";
$result = mysqli_query($con,$fetch);
if(!$result)
{echo "Error:".(mysqli_error($con));}
//display the table
echo '
'. 'Tax Menu'. ''.'
'.'taxrate'.'$data[0]
'.'
'.'
'.'
';
//while($data = mysqli_fetch_row($fetch))
while($data=mysqli_fetch_row($result))
{echo ("
");}
echo ''.'
'.'
'.'
'.'
';
echo '
'.'
'.'
'.'';

mysqli_query($con,"UPDATE numbers SET taxrate='$taxrate' WHERE id = '$id'");
mysqli_close($con);
}
?>​


----------

