madness69 Posted May 2, 2013 Share Posted May 2, 2013 Hi there, im creating a form that i can add and clone the inputs in my form, is for a hostel site, the client needs to add many seasons date, name , type of season, this type of info, so the problem is in my code it creates but create 2 more records in database whit blank info, am i doing somethign wrong? Above is my code: The php action code: $title_season = $_POST['title_season']; $type_season = $_POST['type_season']; $date_begin = $_POST['date_begin']; $date_final = $_POST['date_final']; $price = $_POST['price']; $all_info = array($title_season,$type_season,$date_begin,$date_final,$price); for ($i=0; $i<sizeof($all_info);$i++){ $sql_insert=mysql_query("INSERT INTO seasoninfo(title_season,type_season,date_begin,date_final,price)VALUES('$title_season[$i]','$type_season[$i]','$date_begin[$i]','$date_final[$i]','$price[$i]')"); } Form: <form method="POST" id="SignupForm" action="preco_epoca.php"> <fieldset> <style type="text/css"> .remove {color:#cc0000} .input{ border: solid 1px #006699; padding:3px} </style> <script type="text/javascript" src="reCopy.js"></script> <script type="text/javascript"> $(function(){ var removeLink = ' <a class="remove" href="#" onclick="$(this).parent().slideUp(function(){ $(this).remove() }); return false">remover</a>'; $('a.add').relCopy({ append: removeLink}); }); </script> <table width="692" border="0"> <tr> <td width="309">Title</td> <td width="120">Seasion</td> <td width="65"> Date Begin</td> <td width="65"> Data Final</td> <td width="111"> Price;</td> </tr> <tr class="clone"> <td><input id="Email" name="title_season[]" type="text" /></td> <td><select name="type_season[]"> <option selected="selected">Seleccione</option> <option>Epoca Baixa</option> <option>Epoca Media</option> <option>Epoca Alta</option> </select></td> <td><input type="text" name="date_begin[]" style="width: 75px;margin-left:5px;" onfocus="this.value=''" value="Ano-Mês-Dia" /></td> <td><input type="text" name="date_final[]" style="width: 75px;margin-left:5px;" onfocus="this.value=''" value="Ano-Mês-Dia" /></td> <td><input type="text" name="price[]" style="width: 30px;margin-left:5px;" class="data" id="valor_epoca" /></td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td><a href="#" class="add" rel=".clone"><img border="0" src="images/add.png" width="18" height="14" alt="add"> Add More Fields</a></td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> </table> </fieldset> <fieldset> </fieldset> <fieldset> </fieldset> <p> </br> <input name="id_utilizador" type="hidden" value="<?php echo $id_hostel?>"> <input name="inserir" class="submter_estilo" type="submit" value="SUBMITE"> </p> <br> </form> Quote Link to comment Share on other sites More sharing options...
akphidelt2007 Posted May 2, 2013 Share Posted May 2, 2013 Sizeof($all_info) will always be 5 because you are creating the array with 5 other arrays. Do sizeof($title_season) and don't worry about the $all_info Quote Link to comment Share on other sites More sharing options...
madness69 Posted May 2, 2013 Author Share Posted May 2, 2013 Sizeof($all_info) will always be 5 because you are creating the array with 5 other arrays. Do sizeof($title_season) and don't worry about the $all_info Thanks fot the response, it doesnt do nothing, doesnt insert nothing. Quote Link to comment Share on other sites More sharing options...
akphidelt2007 Posted May 2, 2013 Share Posted May 2, 2013 Thanks fot the response, it doesnt do nothing, doesnt insert nothing. So what debugging did you try to figure out why? When you do print_r($title_season) what does it show you? Quote Link to comment Share on other sites More sharing options...
madness69 Posted May 2, 2013 Author Share Posted May 2, 2013 sorry, afterall your first solution worked, is everything working well thanks a lot , one more question, in this link. http://tiny.cc/6hadww I use the same functionality of adding input fields, but the problem is the input fields that are cloned the datepicker doesnt work, could you take a look? Quote Link to comment Share on other sites More sharing options...
akphidelt2007 Posted May 2, 2013 Share Posted May 2, 2013 sorry, afterall your first solution worked, is everything working well thanks a lot , one more question, in this link. http://tiny.cc/6hadww I use the same functionality of adding input fields, but the problem is the input fields that are cloned the datepicker doesnt work, could you take a look? That's on the javascript side. You'd have to figure out what triggers the calendar and why is the trigger only recognizing the first input. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.