Wojtek
Wojtek

Reputation: 3

data from droplist to database mysql

I need advice, what i did wrong and this code not working. In short I have droplist menu with data read from mysql database and I want this data what user selected put in to another table/row in db. with present code I received only NULL value in inserted row... some I assume maybe something wrong with syntax, I tried search similar topic and tried different way but result is same :| This is my code :

get function and form

   <br><br>
<?php
include 'connectdb.php';
$sql="select * from persons";
$result=mysqli_query($con,$sql); 

while ($row=mysqli_fetch_array($result)) { 

    $id=$row["id"]; 
    $name=$row["name"]; 
    $name_done.="<OPTION VALUE=\"$id\">".$name; 
} 

?>  
<form action="insert.php" method="post">
<SELECT name="name_done" id="nane_done"> 
<OPTION VALUE=0>Choose Your name : 
<?=$name_done?> 
</SELECT> <br>
RFC: <input type="text" name="number"><br>
Date: <input type="text" id="datepicker" name="date">
<input type="submit" value="submit" />
</form>

And Insert

<?php
include 'connectdb.php';

$name_done = $_POST['nane_done'];
mysqli_query($con,"INSERT INTO rfc(name_done) VALUES (.$name_done)");

---- below working OK----

$sql = "INSERT INTO rfc(number,date) 
VALUES
('$_POST[number]','$_POST[date]')";

if (!mysqli_query($con,$sql,$name_done))
  {
  die('Error: ' . mysqli_error($con));
  }
echo "RFC added";
mysqli_close($con);

?>

Upvotes: 0

Views: 59

Answers (1)

Grim...
Grim...

Reputation: 16953

You have a typo - "nane_done" rather than "name_done" in this line: $name_done = $_POST['nane_done'];.

Upvotes: 1

Related Questions