php - how to get value of a <select> without <form> HTML markup -


i never put thought on how data submitted without using <form> . focused on design of form.

now, im having trouble trying send post data without having <form> markup. im using bootstrap framework.

also, how values in <select> markup submitted. below html , php code.

below html

<div id="box1">    <input name="fname" type="text" placeholder="name"> </div>  <div id="box2">    <select id="food" name="food">        <option value="meat" name="nmeat">   meat  </option>        <option value="fruit" name="nfruit"> fruit </option>     </select> </div>  // ^ above code in jquery conditional statement // when user select meat, <select id="meat"> display else fruit   <div id="box3">    <!--meat-->    <select id="meat" name="topic">        <option value="hotdog" name="nhotdog">   hotdog     </option>        <option value="sausage" name="nsausage"> sausage    </option>     </select>      <!--fruit-->     <select id="fruit" name="topic">        <option value="apple" name="napple">   apple   </option>        <option value="grapes" name="ngrapes"> grapes  </option>     </select>   </div>  <div id="box4">    <textarea name="desc" rows="5" class="span11" placeholder="description"></textarea>    <button name="submit" class="btn btn-large btn-block btn-primary" type="button">submit</button>  </div> 

below php im having hardtime making correct syntax in php, specially if values being submitted not in <form>

<?php     if ( isset( $_post['submit'] ) ) {         $name = $_post["fname"];   //box1         $gender =$_post["gender"]; //box2         $topic =$_post["topic"];   //box3         $desc =$_post["desc"];     //box4         //echo $msg;         $sql = "insert z_form (name) values ('".$msg."')";         mysql_query( $sql );     } else {         echo "error";     }  ?> 

just use <form> tag, really. post method requires <form> tag. don't see valid reasons exclude <form tags form.

now, im having trouble trying send post data without having markup. im using bootstrap framework.

bootstrap doesn't restrict using <form> tags. :)

wrap form in <form tags, follows:

<form action="somefile.php" method="post" name="myform">  <!-- form code here -->  </form> 

also, change button from:

<button name="submit" class="btn btn-large btn-block btn-primary" type="button">submit</button> 

to:

<input type="submit" name="submit" value="submit" class="btn btn-large btn-block btn-primary"/> 

and finally, in php code, you're doing:

$gender =$_post["gender"]; 

but there's no input field name attribute gender. either should create 1 input field name, or remove definition script.

that should fix issues. cheers!


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -