TAViX Posted February 16, 2009 Share Posted February 16, 2009 I'm having a very hard time to create a script that uploads all the data from a table into the database. Now the table can have from 1 to 999 entries, and I only can upload 1 entry. How do I do to upload all of the entryes at once??? Thanks. <?php require_once('../Connections/DB_rev00.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_DB_rev00, $DB_rev00); $query_Batch_in = "SELECT trainee_code, comp_code, sur_name, given_name, middle_name, nickname FROM passport_info"; $Batch_in = mysql_query($query_Batch_in, $DB_rev00) or die(mysql_error()); $row_Batch_in = mysql_fetch_assoc($Batch_in); $totalRows_Batch_in = mysql_num_rows($Batch_in); ?><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Batch Member Input</title> <style type="text/css"> <!-- #title { position:absolute; left:150px; top:82px; width:742px; height:154px; z-index:1; } body { background-repeat: no-repeat; } #apDiv1 { position:absolute; left:150px; top:163px; width:699px; height:272px; z-index:2; } .style5 {font-size: smaller; font-weight: bold; } .style8 {font-weight: bold} #apDiv2 { position:absolute; left:128px; top:182px; width:727px; height:164px; z-index:3; } #apDiv3 { position:absolute; left:149px; top:637px; width:725px; height:631px; z-index:4; } .style10 { font-size: small; font-family: Verdana, Arial, Helvetica, sans-serif; } .style12 {color: #2A0055} #list_tbl1 { position:absolute; left:148px; top:503px; width:726px; height:174px; z-index:4; } #tbl01 { position:absolute; left:147px; top:503px; width:730px; height:508px; z-index:4; } #apDiv4 { position:absolute; left:148px; top:504px; width:744px; height:484px; z-index:4; } .style14 {color: #000000} .style16 {color: #000000; font-weight: bold; } #apDiv5 { position:absolute; left:17px; top:219px; width:105px; height:66px; z-index:5; } #apDiv6 { position:absolute; left:127px; top:442px; width:742px; height:196px; z-index:4; } #apDiv7 { position:absolute; left:102px; top:730px; width:725px; height:191px; z-index:4; } --> </style> </head> <body> <div id="apDiv2"> <p> <style type="text/css"> body{ font-size:10pt; font-family:Arial,Tahoma,Verdana; color:#555; } table{ background:#777; border:1px solid #cfcfcf; } td,th { background:#fff; padding:10px; } td { font-size:10pt; } form ul { list-style-type:none; width:250px; } form ul li { margin-top:1px; padding:10px; height:30px; border:1px solid #999; } strong.err { color:#930; display:block; margin:5px 0px; } #tab2 { margin-bottom:5px; } #tab2 input{ border:0px; background:none; } </style> </p> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p> <?php error_reporting(0); $batch = $_POST['batch_nr']; // Get batch textbox $person = $_POST['person_nr']; // Get person textbox ?> </p> <table width="177" border="1" cellpadding="2" cellspacing="1" bordercolor="#2A0000"> <tr> <th width="119" align="left" bordercolor="#6E0067" bgcolor="#2A00AA" scope="row"><span class="style12">バッチ番号</span></th> <td width="41" align="center"><input name="batch_nr" type="text" id="batch_nr" value="<?php echo $batch; ?>" size="2" maxlength="3"></td> </tr> <tr> <th align="left" bordercolor="#6E0067" bgcolor="#2A00AA" scope="row"><span class="style12">バッチ人数</span></th> <td align="center"><input name="person_nr" type="text" id="person_nr" value="<?php echo $person; ?>" size="2" maxlength="3"></td> </tr> </table> <p class="style10">上記の条件でバッチメンバー登録表作成します </p> <p> <input type="submit" name="submit1" value="実行"> </p> </form> </div> <div id="tbl01"> <?php if (isset($_POST['submit1'])) { $person = (int)$person; if($batch==''||$person=='') echo "<strong class='err'>Please ensure that \"Person nr.\" is a number</strong>"; else { ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <p class="style10">バッチメンバー登録表 </p> <span class="style10">「名前」、「ニックネーム」、「配属先会社コード」を入力してください</span> <table width="730" height="99" border="1" cellpadding="2" cellspacing="1" bordercolor="#2A0000" id="tab02"> <tr> <th width="100" scope="col"><span class="style14">研修生番号</span></th> <th colspan="3" scope="col"><span class="style14">名前</span></th> <th width="108" scope="col"><span class="style14">ニックネーム</span></th> <th width="158" scope="col"><p class="style14">配属先会社コード</p></th> </tr> <tr> <td align="center"><span class="style16">Trainee code</span></td> <td width="95" align="center"><span class="style16">Sur Name</span></td> <td width="122" align="center"><span class="style16">Given Names</span></td> <td width="102" align="center"><span class="style16">Middle Name</span></td> <td align="center"><span class="style16">Nickname</span></td> <td align="center"><span class="style16">Company Code</span></td> </tr> <?php for($i=1;$i<=$person;$i++) { echo " <tr> <td align='center'><input type='text' name='tc[]' value='{$batch}00{$i}' size='3' maxlength='3'></td> <td align='center'><input type='text' name='sn[]' size='7'></td> <td align='center'><input type='text' name='gn[]' size='7'></td> <td align='center'><input type='text' name='mn[]' size='7'></td> <td align='center'><input type='text' name='nn[]' size='7'></td> <td align='center'><input type='text' name='cc[]' size='4'></td> </tr> "; } echo " </table> <input type='submit' name='submit2' value='Insert'> </form> "; } } if (isset($_POST['submit2'])) { // How to insert all the data from the texboxes in the mysql table??? echo " I need here to upload the data in the MySQL database table "; } ?> </body> </html> <?php mysql_free_result($Batch_in); ?> Link to comment https://forums.phpfreaks.com/topic/145378-upload-multiple-data-to-an-mysql-database/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.