Member Avatar for Silfro

Hello I got one problem. I have a site where people can add movies.

Its possible to add up to 10 different hosts.

Every host can have up to 2 parts.

html

<TABLE>      
            <TR><TD width=120>Hoster*:</TD>
                <TD>
                    <SELECT class="interfaceforms" name="addmovie[][hoster]"><OPTION value="">Please select</OPTION>
                    <?PHP
                        foreach($hoster_list AS $aKey => $aValue) {
                        echo'<option value="'.$aKey.'">'.$aValue.'</option>';
                        }
                    ?>
                    </SELECT>
                </TD>
            </TR>
            <TR>
                <TD> 
                    <BR><a href="#" onClick="document.getElementById('addhoster2').style.display='';return false;">>Add hoster<</a>
                </TD>
                <TD>
                    Part 1: <INPUT class="interfaceforms" type="text" name="addmovie[][part]"> link or embed code<BR>
                    Part 2: <INPUT class="interfaceforms" type="text" name="addmovie[][part]"><BR>
                </TD>
            </TR>
        </TABLE>

        <TABLE id="addhoster2" style="display:none;">    
            <TR>
            <TD width=120>Hoster*:</TD>
                <TD>
                    <SELECT class="interfaceforms" name="addmovie[][hoster]"><OPTION value="">Please select</OPTION>
                    <?PHP
                        foreach($hoster_list AS $aKey => $aValue) {
                        echo'<option value="'.$aKey.'">'.$aValue.'</option>';
                        }
                    ?>
                    </SELECT>
                </TD>
            </TR>
            <TR>
                <TD> 
                    <BR><a href="#" onClick="document.getElementById('addhoster3').style.display='';return false;">>Add hoster<</a>
                </TD>
                <TD>
                    Part 1: <INPUT class="interfaceforms" type="text" name="addmovie[][part]"> link or embed code<BR>
                    Part 2: <INPUT class="interfaceforms" type="text" name="addmovie[][part]"><BR>
                </TD>
            </TR>
        </TABLE>

        <TABLE id="addhoster3" style="display:none;">    
            <TR>
            <TD width=120>Hoster*:</TD>
                <TD>
                    <SELECT class="interfaceforms" name="addmovie[][hoster]"><OPTION value="">Please select</OPTION>
                    <?PHP
                        foreach($hoster_list AS $aKey => $aValue) {
                        echo'<option value="'.$aKey.'">'.$aValue.'</option>';
                        }
                    ?>
                    </SELECT>
                </TD>
            </TR>
            <TR>
                <TD> 
                    <BR><a href="#" onClick="document.getElementById('addhoster4').style.display='';return false;">>Add hoster<</a>
                </TD>
                <TD>
                    Part 1: <INPUT class="interfaceforms" type="text" name="addmovie[][part]"> link or embed code<BR>
                    Part 2: <INPUT class="interfaceforms" type="text" name="addmovie[][part]"><BR>
                </TD>
            </TR>
        </TABLE>

code

    if(isset($_POST['submit']) && $_POST['submit']=="Add") {

          $result        = $_POST["addmovie"];

          if (count($result > 0))
            $new = array();
            foreach ($result as $key => $value)
            {
            $new[] = "('" . $value["hoster"] . "', '" . $value["part"] . "', '" . $value["part"] . "')";
            }

            if (count($new) > 0)
            {
            $query = mysql_query("INSERT INTO topmovies.movies2 (hoster, part_1, part_2) VALUES " . implode(', ', $new));
            if ($query)
            {
                echo 'SUCCESS';
            }
            else
            {
                echo 'FAILED';
            }
            }


    }

Picture homepage:
http://s14.directupload.net/images/130805/ti4fwh7c.jpg

Picture database( so you see the problem )
http://s7.directupload.net/images/130805/n3kou9zo.jpg

As you see, the part are not on the same row as the hoster and there should be only 1 row each host and not 2

Would be happy if someone can help out :)

Member Avatar for Silfro

Hey sorry for second post but ive managed to get it to work to 99%.. I got 1 problem left..

He ALWAYS make 3 querys even when the second and third hoster ist empty he do 3 querys.. How can I fix it?

html

<TABLE>      
            <TR><TD width=120>Hoster*:</TD>
                <TD>
                    <SELECT class="interfaceforms" name="addmovie[0][hoster]"><OPTION value="">Please select</OPTION>
                    <?PHP
                        foreach($hoster_list AS $aKey => $aValue) {
                        echo'<option value="'.$aKey.'">'.$aValue.'</option>';
                        }
                    ?>
                    </SELECT>
                </TD>
            </TR>
            <TR>
                <TD>&nbsp;
                    <BR><a href="#" onClick="document.getElementById('addhoster2').style.display='';return false;">>Add hoster<</a>
                </TD>
                <TD>
                    Part 1: <INPUT class="interfaceforms" type="text" name="addmovie[0][part]"> link or embed code<BR>
                    Part 2: <INPUT class="interfaceforms" type="text" name="addmovie[0][part2]"><BR>
                </TD>
            </TR>
        </TABLE>

        <TABLE id="addhoster2" style="display:none;">    
            <TR>
            <TD width=120>Hoster*:</TD>
                <TD>
                    <SELECT class="interfaceforms" name="addmovie[1][hoster]"><OPTION value="">Please select</OPTION>
                    <?PHP
                        foreach($hoster_list AS $aKey => $aValue) {
                        echo'<option value="'.$aKey.'">'.$aValue.'</option>';
                        }
                    ?>
                    </SELECT>
                </TD>
            </TR>
            <TR>
                <TD>&nbsp;
                    <BR><a href="#" onClick="document.getElementById('addhoster3').style.display='';return false;">>Add hoster<</a>
                </TD>
                <TD>
                    Part 1: <INPUT class="interfaceforms" type="text" name="addmovie[1][part]"> link or embed code<BR>
                    Part 2: <INPUT class="interfaceforms" type="text" name="addmovie[1][part2]"><BR>
                </TD>
            </TR>
        </TABLE>

        <TABLE id="addhoster3" style="display:none;">    
            <TR>
            <TD width=120>Hoster*:</TD>
                <TD>
                    <SELECT class="interfaceforms" name="addmovie[2][hoster]"><OPTION value="">Please select</OPTION>
                    <?PHP
                        foreach($hoster_list AS $aKey => $aValue) {
                        echo'<option value="'.$aKey.'">'.$aValue.'</option>';
                        }
                    ?>
                    </SELECT>
                </TD>
            </TR>
            <TR>
                <TD>&nbsp;
                    <BR><a href="#" onClick="document.getElementById('addhoster4').style.display='';return false;">>Add hoster<</a>
                </TD>
                <TD>
                    Part 1: <INPUT class="interfaceforms" type="text" name="addmovie[2][part]"> link or embed code<BR>
                    Part 2: <INPUT class="interfaceforms" type="text" name="addmovie[2][part2]"><BR>
                </TD>
            </TR>
        </TABLE>

code:

$result        = $_POST["addmovie"];

          if (count($result > 0))
            $new = array();
            foreach ($result as $key)
            {
            $new[] = "('" . $key["hoster"] . "', '" . $key["part"] . "', '" . $key["part2"] . "')";
            }

            if (count($new) > 0)
            {
            $query = mysql_query("INSERT INTO topmovies.movies2 (hoster, part_1, part_2) VALUES " . implode(', ', $new));
            if ($query)
            {
                echo 'SUCCESS';
                print_r($new);
            }
            else
            {
                echo 'FAILED';
            }
            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.