rbrunner Posted January 8, 2007 Share Posted January 8, 2007 I am having trouble uploading a text file with 3 different variable in it and inputting it into a sql database. Using PHP Can any one help. Quote Link to comment https://forums.phpfreaks.com/topic/33336-uploading-a-texted-file-and-inputting-data-into-a-data-base/ Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 There are plenty of tutorials.Upload the file, then read the contents into a string, then query your database. If you have already written some code and it's not working, post the code and we will help. Otherwise, you need to get started by reading the tutorials. Quote Link to comment https://forums.phpfreaks.com/topic/33336-uploading-a-texted-file-and-inputting-data-into-a-data-base/#findComment-155754 Share on other sites More sharing options...
rbrunner Posted January 8, 2007 Author Share Posted January 8, 2007 if (isset($_POST['submit'])) { // Handle the form. $lines = file($_FILES['uploadedfile']['tmp_name']); foreach ($lines = $line) $file = $line $file = trim($file); $file = ltrim($file); $query = "insert into group_list (phone_number, first_name, last_name) values ('$var0', '$var1', '$var2')";}<form action="getfile.php" method="post" enctype="multipart/form-data"> <span class="bold-font-less">Group Name:</span> <input TYPE="TEXT" NAME="group_name" SIZE="30"><br> <br> <iinput type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="userfile" type="file" class="box" size="40" id="userfile"><br /> <br> <br /> <input TYPE="submit" name="submit" VALUE="Add this Group!"></form> Quote Link to comment https://forums.phpfreaks.com/topic/33336-uploading-a-texted-file-and-inputting-data-into-a-data-base/#findComment-155761 Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 Okay, so you're stuck on how to get those $vars out of the $file? Maybe you need to look at the explode() function.http://php.net/explodeI should have specified that in addition to posting code you'll need to tell us what doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/33336-uploading-a-texted-file-and-inputting-data-into-a-data-base/#findComment-155773 Share on other sites More sharing options...
rbrunner Posted January 8, 2007 Author Share Posted January 8, 2007 if (isset($_POST['submit'])) { // Handle the form. $lines = file($_FILES['uploadedfile']['tmp_name']); foreach ($lines = $line{ $file = $line $array = explode (",",$file); Now for some reason it says parse error unexpected T_variable on the last line. Quote Link to comment https://forums.phpfreaks.com/topic/33336-uploading-a-texted-file-and-inputting-data-into-a-data-base/#findComment-155859 Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 You're missing a ) in your foreach and a ; in the line below it. Quote Link to comment https://forums.phpfreaks.com/topic/33336-uploading-a-texted-file-and-inputting-data-into-a-data-base/#findComment-155867 Share on other sites More sharing options...
rbrunner Posted January 8, 2007 Author Share Posted January 8, 2007 <?php session_start();$uid= $_SESSION['username'];$a=$_SESSION['accesslevel'] ; require_once ('mysql_connect.php'); // Connect to the db. if (isset($_POST['submit'])) { // Handle the form. $lines = file($_FILES['uploadedfile']['tmp_name']); foreach ($lines = $line){ [color=purple][/color] it says here that there is and unexpected ')'[color=black][/color] $file = $line; $array = explode (",",$file); $query = "insert into group_list (phone_number, first_name, last_name) values ('$var0', '$var1', '$var2')";} Quote Link to comment https://forums.phpfreaks.com/topic/33336-uploading-a-texted-file-and-inputting-data-into-a-data-base/#findComment-155874 Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 Oh your foreach syntax is wrong.foreach($array AS $key=>$value)orforeach($array AS $value) Quote Link to comment https://forums.phpfreaks.com/topic/33336-uploading-a-texted-file-and-inputting-data-into-a-data-base/#findComment-155880 Share on other sites More sharing options...
rbrunner Posted January 8, 2007 Author Share Posted January 8, 2007 thanks that helped. When I am doing this do I need to have it go to a different page to have it input it into the database? Quote Link to comment https://forums.phpfreaks.com/topic/33336-uploading-a-texted-file-and-inputting-data-into-a-data-base/#findComment-155948 Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 Why would you need to do that?Before asking if you can or can't do something, it's always best to TRY first. Quote Link to comment https://forums.phpfreaks.com/topic/33336-uploading-a-texted-file-and-inputting-data-into-a-data-base/#findComment-155952 Share on other sites More sharing options...
rbrunner Posted January 8, 2007 Author Share Posted January 8, 2007 the reason I asked is that my boss said that it wasn't possible to do it on one page. so to do it on 2. Quote Link to comment https://forums.phpfreaks.com/topic/33336-uploading-a-texted-file-and-inputting-data-into-a-data-base/#findComment-155955 Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 Bosses ALWAYS know what they are talking about. Fo sho. Quote Link to comment https://forums.phpfreaks.com/topic/33336-uploading-a-texted-file-and-inputting-data-into-a-data-base/#findComment-155958 Share on other sites More sharing options...
rbrunner Posted January 8, 2007 Author Share Posted January 8, 2007 <?php session_start();$uid= $_SESSION['username'];$a=$_SESSION['accesslevel'] ; require_once ('mysql_connect.php'); // Connect to the db.?><form action="getfile.php" method="post" enctype="multipart/form-data"> <span class="bold-font-less">Group Name:</span> <input TYPE="TEXT" NAME="group_name" SIZE="30"><br> <br> <input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="userfile" type="file" class="box" size="40" id="userfile"><br /> <br> <br /> <input TYPE="submit" name="submit" VALUE="Add this Group!"></form><?ob_end_flush();?> this is my first page it works great I hope.My second page is<html><head><title>Process Uploaded File</title></head><body><?php $message = NULL; // Create an empty new variable. if (isset($_POST['submit'])) { // Handle the form. if (empty($_POST['uploadedfile'])){ $uf = FALSE; $message .= '<p>You for got to enter a file to upload!</p>'; } else { $uf = TRUE $lines = file($_FILES['uploadedfile']['tmp_name']); <<<<AND HERE IS WHERE I GET A T_VARIABLE ERROR foreach ($lines as $file){ $array = explode (",",$file); $query = "insert into group_list (phone_number, first_name, last_name) values ('$var0', '$var1', '$var2')";} // Check for a class name. if (empty($_POST['group_name'])) { $gn = FALSE; $message .= '<p>You forgot to enter a Group Name!</p>'; } else { $gn = escape_data($_POST['group_name']); } if ($gn) { // If everything's OK. // add to database... $query = "insert into group_name (group_name) values ('$gn')"; $result = @mysql_query ($query); // Run the query.if (mysql_affected_rows() >0) { // Records added so update the aval field echo '<font color="red">', 'The Group was Added', '</font>'; //now lets upload the file }}}}?></body></html> Quote Link to comment https://forums.phpfreaks.com/topic/33336-uploading-a-texted-file-and-inputting-data-into-a-data-base/#findComment-155966 Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 Use Code tags. Quote Link to comment https://forums.phpfreaks.com/topic/33336-uploading-a-texted-file-and-inputting-data-into-a-data-base/#findComment-155973 Share on other sites More sharing options...
rbrunner Posted January 8, 2007 Author Share Posted January 8, 2007 which code tag do you mean??? Quote Link to comment https://forums.phpfreaks.com/topic/33336-uploading-a-texted-file-and-inputting-data-into-a-data-base/#findComment-155981 Share on other sites More sharing options...
Jessica Posted January 8, 2007 Share Posted January 8, 2007 The button with the # on it. Quote Link to comment https://forums.phpfreaks.com/topic/33336-uploading-a-texted-file-and-inputting-data-into-a-data-base/#findComment-155986 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.