Jump to content

Help with upload form..


MDanz

Recommended Posts

<?php // Create MySQL login values and

// set them to your login information.

$username = "username";

$password = "password";

$host = "localhost";

$database = "database";

 

// Make the connect to MySQL or die

// and display an error.

$link = mysql_connect($host, $username, $password);

if (!$link) {

    die('Could not connect: ' . mysql_error());

}

 

// Select your database

mysql_select_db ($database);

 

// Make sure the user actually

// selected and uploaded a file

if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {

 

      // Temporary file name stored on the server

      $tmpName  = $_FILES['image']['tmp_name']; 

     

      // Read the file

      $fp      = fopen($tmpName, 'r');

      $data = fread($fp, filesize($tmpName));

      $data = addslashes($data);

      fclose($fp);

     

 

      // Create the query and insert

      // into our database.

      $query = "INSERT INTO upload ";

      $query .= "(image) VALUES ('$data')";

 

      $results = mysql_query($query, $link);

     

      // Print results

      print "Thank you, your file has been uploaded.";

     

}

else {

  print "No image selected/uploaded";

}

 

// Close our MySQL Link

mysql_close($link);

?>

 

 

ok i did a php tutorial for image upload but i need more than an image uploaded.

 

In the databse i have these fields.

 

Image, hyperlink, currency, name, info, ID, keywords.

 

Can i have help on inserting these into my database from the upload form.

Image is already done, how do i add the other 4(hyperlink, currency, info, name and keywords).. I've set them up in upload as text fields. Just how do i add them to this code. So when i submit they all go as one entry

 

Link to comment
https://forums.phpfreaks.com/topic/168739-help-with-upload-form/
Share on other sites

hi

 

ok, i have a page upload.php and on that page originally it was just an image upload page. i have now added the text fields(hyperlink, currency, info, name and keywords).  The code i posted is insert.php, which inserts the data from upload.php into mysql.  So far it only does image upload.  I need to know how to get the new text fields added to also insert into the database. 

 

happens in this part of the code

 

// Create the query and insert

      // into our database.

      $query = "INSERT INTO upload ";

      $query .= "(image) VALUES ('$data')";

 

you can just do anyname as an example for textfields

<?php

$hyperlink = $_POST['hyperlink'];
$currency = $_POST['currency'];
$name = $_POST['name'];
$info = $_POST['info'];
$keywords = $_POST['keywords'];

$sql = "INSERT INTO `table_name` (`hyperlink`,`currency`,`name`,`info`,`keywords`) VALUES ('$hyperlink','$currency','$name','$info','$keywords')";

$query = @mysql_query($sql);
if($query){ print "Your image details have been uploaded to the data"; } else { print "error"; }

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.