MasterK Posted October 14, 2009 Share Posted October 14, 2009 I am a Beginner at PHP, and Need a little help with this I have a script for Inserting Videos into a Mysql Database. Currently all I have is the Tables, Which I have made it so you can chose how many to show. What I need help with is, How to create the Mysql INSERT to insert however many they chose to add... Here is my code so far... Any help/comments/tips/suggestions are welcome <table width=90%> <tr> <th colspan=6>Add New Videos </th> </tr> <tr> <td width=60>Anime</td> <td width=20>Season</td> <td width=20>Episode #</td> <td width=150>Episode Name</td> <td width=150>Video URL</td> <td width=50>Host</td> </tr> </table> <table width=90%> <form action= method=post><input type=hidden name=subm value=1> <? $num = $_GET['nm']; if($num=="") { $num = 2; } $i = 1; while($i<$num){ ?> <tr> <td><input size=10 type=text name=AnimeN<? echo"$i";?>></td> <td><input size=5 type=text name=SnNumber<? echo"$i";?>></td> <td><input size=5 type=text name=EpNumber<? echo"$i";?>></td> <td><input size=30 type=text name=EpName<? echo"$i";?>></td> <td><input size=30 type=text name=VidURL<? echo"$i";?>></td> <td> <select name=Host<? echo"$i";?>> <option value=Myspace>Myspace</option> <option value=MegaVideo>Megavideo</option> <option value=Veoh>Veoh</option> <option value=clip.vn>clip.vn</option> <option value=Other>Other</option> <option value=MP4>MP4</option> </select></td></tr> <?php $i++; } ?> <tr><td> <input type=submit class=button value="Add Video"></form></td></tr></tr></table> Link to comment https://forums.phpfreaks.com/topic/177625-multiple-mysql-inserts-point-me-in-the-right-direction/ Share on other sites More sharing options...
ialsoagree Posted October 14, 2009 Share Posted October 14, 2009 I would start by changing this: <?php <td><input size=10 type=text name=AnimeN<? echo"$i";?>></td> <td><input size=5 type=text name=SnNumber<? echo"$i";?>></td> <td><input size=5 type=text name=EpNumber<? echo"$i";?>></td> <td><input size=30 type=text name=EpName<? echo"$i";?>></td> <td><input size=30 type=text name=VidURL<? echo"$i";?>></td> ?> ...to this... <?php <td><input size=10 type=text name=AnimeN[]></td> <td><input size=5 type=text name=SnNumber[]></td> <td><input size=5 type=text name=EpNumber[]></td> <td><input size=30 type=text name=EpName[]></td> <td><input size=30 type=text name=VidURL[]></td> <td> <select name=Host[]> <option value=Myspace>Myspace</option> <option value=MegaVideo>Megavideo</option> <option value=Veoh>Veoh</option> <option value=clip.vn>clip.vn</option> <option value=Other>Other</option> <option value=MP4>MP4</option> </select></td></tr> ?> (I would also go through and add HTML quotes around your attribute settings, not having them is bad HTML). You can then use the foreach loop on one of the arrays, $_POST['AnimeN'] for example, define both the $key and $value parameters, and you can use $key to refer to all other arrays for that submission: <?php foreach ($_POST['AnimeN'] as $key => $value) { /* do stuff if you want */ $_POST['SnNumber'][$key]; // the SnNumber for the current submission /* more stuff here */ } ?> Unfortunately, you will have to do multiple inserts to the database (unless someone knows another way of doing inserts), fortunately using this method you can format all the submissions individually as you go through the loop and run the insert statement at the end of each loop. Link to comment https://forums.phpfreaks.com/topic/177625-multiple-mysql-inserts-point-me-in-the-right-direction/#findComment-936551 Share on other sites More sharing options...
MasterK Posted October 14, 2009 Author Share Posted October 14, 2009 thank you, ialsoagree. I am playing with that Code, now, trying to understand how to get it to Insert them into the databse Any other Tips/Hints/Suggestions are welcome Link to comment https://forums.phpfreaks.com/topic/177625-multiple-mysql-inserts-point-me-in-the-right-direction/#findComment-936637 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.