Jump to content

Problems in my For and Multiple values


madness69

Recommended Posts

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>
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.