MDanz Posted August 4, 2009 Share Posted August 4, 2009 <?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 More sharing options...
phpSensei Posted August 4, 2009 Share Posted August 4, 2009 Explain where these come from hyperlink, currency, name, info, keywords. whats info? is name the name of the file? currency? info? keywords from the form? Link to comment https://forums.phpfreaks.com/topic/168739-help-with-upload-form/#findComment-890249 Share on other sites More sharing options...
MDanz Posted August 4, 2009 Author Share Posted August 4, 2009 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 Link to comment https://forums.phpfreaks.com/topic/168739-help-with-upload-form/#findComment-890256 Share on other sites More sharing options...
phpSensei Posted August 4, 2009 Share Posted August 4, 2009 <?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"; } ?> Link to comment https://forums.phpfreaks.com/topic/168739-help-with-upload-form/#findComment-890258 Share on other sites More sharing options...
MDanz Posted August 4, 2009 Author Share Posted August 4, 2009 thx alot.. i'll try it out Link to comment https://forums.phpfreaks.com/topic/168739-help-with-upload-form/#findComment-890261 Share on other sites More sharing options...
phpSensei Posted August 4, 2009 Share Posted August 4, 2009 thanks alot.. i'll try it out Okay but make sure you implement this code, not just copy paste it to your script. Link to comment https://forums.phpfreaks.com/topic/168739-help-with-upload-form/#findComment-890268 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.