2

I want to submit drop-down with dynamic value. I concatenate all variables inside the string but data not submit any one help me how is it done

if(isset($_POST['submit'])){
     $name = $_POST['name'];
     $value1 = $_POST['value1'];
     $value2 = $_POST['value2'];


        $data = "<select name=''$name''>";
        $data .="<option>Selet data</option>";
        $data .="<option value='**$value1**'> **$value1**</option>";
        $data .="<option value='**$value2**'> **$value2**</option>";
        $data .="</select>";

        mysql_query("insert into options (value) values ('".$data."')");
    }

With variable string not submit in to the database.

HTML is below

<form action="" method="POST">

        <input type="text" name="name">
        <input type="text" name="value1">
        <input type="text" name="value2">
        <input type="submit" name="submit">

</form>
17
  • 1
    show us please the full code and your html part... btw dont use mysql_ functions they are deprecated since php 5.5.0 Commented Dec 7, 2016 at 12:21
  • You want to insert the whole shebang, including HTML tags? Or just the values? Commented Dec 7, 2016 at 12:22
  • Do query the database for errors. $data WILL contain illegal characters in the context of your query. Commented Dec 7, 2016 at 12:22
  • "How it is done" is to use prepared statements and query parameters. What you're building here is one great big SQL syntax error. mysql_error() is undoubtedly telling you about the problem, you should check that for errors. While not necessarily a duplicate, this would be a great place for you to start: stackoverflow.com/questions/60174/… Commented Dec 7, 2016 at 12:22
  • Check your table field strength Commented Dec 7, 2016 at 12:23

1 Answer 1

0

Check with below:

    if(isset($_POST['submit'])){
     $name = $_POST['name'];
     $value1 = $_POST['value1'];
     $value2 = $_POST['value2'];

        $data = "<select name='$name'>";
        $data .="<option>Selet data</option>";
        $data .="<option value='**$value1**'> **$value1**</option>";
        $data .="<option value='**$value2**'> **$value2**</option>";
        $data .="</select>";

        if(!mysql_query("insert into options (`value`) values (".json_encode($data).")")) {
          echo("Error description: " . mysql_error());
        }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.