Jump to content

Uploading a texted file and inputting data into a data base


rbrunner

Recommended Posts

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

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

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/explode

I should have specified that in addition to posting code you'll need to tell us what doesn't work.
Link to comment
Share on other sites

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

<?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')";
}
Link to comment
Share on other sites

<?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>
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.