Jump to content

irtrsh

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Everything posted by irtrsh

  1. data type for the 1st colum is Integer, 2nd & 3rd one is VARCHAR....
  2. Hi I am new to this forum and also new in PHP/MySQL world. I just stuck in taking the check boxes value to MySQL table. I have got a form, there is 3 check box to get the input from the user and stored them to the database. but when I select the values (check box) from the form, it takes all the values and put it in the same column of the table instead of putting them separately. suppose I've the the check box called police, firstname and lastname and when I select all of them it should put the values in the table in police, firstName & lastname column respectively. here is the code.... <html> <head> </head> <body> <form action="rezach1.php" method="post"> <p> please vote for that...<br /> <input type="checkbox" name="form[]" value=999 />police<br /> <input type="checkbox" name="form[]" value="Name" />firstname<br /> <input type="checkbox" name="form[]" value="family" />lastname<br /> </p> <input type="submit" name="formSubmit" value="Submit" /> </form> </body> </html> and this is my php code <?php # DATABASE configuration ######################################### $hostname = "foot.doc.ac.uk"; //server $db_user = "rafor"; // change to your database password $db_password = "gher"; // change to your database password $database = "rafor"; // provide your database name $db_table = "rez"; // leave this as is # THIS CODE IS USED TO CONNECT TO THE MYSQL DATABASE ###################################### $db = mysql_connect($hostname, $db_user, $db_password); mysql_select_db($database,$db); ?> <html> <head> <title> Insert Data Into MySQL </title> </head> <body> <?php if($_POST['formSubmit'] != "") { $val = $_POST['form']; if(is_null($val)) { echo("<p>You didn't select any thing.</p>\n"); } else { // echo("<p>You selected door(s): "); for($i=0; $i < count($val); $i++) { echo '<br />'; echo($val[$i] . " "); $val_array = $_POST['form']; foreach ($val_array as $form) { $source .= $form.", "; } $val = substr($source, 0, -2); for ($j=0;$j<count($val_array);$j++) { $num=$val_array[$j]; echo '<br />'; print ("$num "); $sql = "INSERT INTO $db_table(ID, Name, Status) values ('".mysql_real_escape_string(stripslashes($val))."','".mysql_real_escape_string(stripslashes($val))."','".mysql_real_escape_string(stripslashes($val))."')"; } if($result = mysql_query($sql ,$db)) { echo '<h1>Thank you</h1>Your information has been entered into our database<br><br>'; } else { echo "ERROR: ".mysql_error(); } } echo("</p>"); } exit(); } ?> can anyone please help me to sort this out and tell me where is the problem? thank you irtrsh
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.