jeaker Posted April 30, 2007 Share Posted April 30, 2007 I was wondering if there was a simple script to store and the view just a file in MySQL data base using PHP. I just want the file to be stored in the table. I do not want any information about the file stored, but just the data. I have been to a few tutorials that I have been able to locate but nothing has really helped or been what I needed. You guys always have great ideas and I was wondering if anybody could throw some my way? Tips? Tuturials? Anything? Thanks so much in advance!! Quote Link to comment https://forums.phpfreaks.com/topic/49266-solved-script-to-store-and-then-view-a-file-stored-in-mysql-using-php/ Share on other sites More sharing options...
john010117 Posted April 30, 2007 Share Posted April 30, 2007 CMS should work. Google it. There are tons of scripts out there. Quote Link to comment https://forums.phpfreaks.com/topic/49266-solved-script-to-store-and-then-view-a-file-stored-in-mysql-using-php/#findComment-241387 Share on other sites More sharing options...
jeaker Posted April 30, 2007 Author Share Posted April 30, 2007 I apologize, let me make my self a little clearer. I have a pretty firm grasp on storing the File. Which is done here... <?php $teacher=$_POST['teacher']; $semester=$_POST['semester']; $year=$_POST['year']; $course=$_POST['course']; $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); mysql_connect("db", "username", "password") or die(mysql_error()); mysql_select_db("upload") or die(mysql_error()); $query = "INSERT INTO syllabus (teacher, semester, year, course, data) VALUES ('$teacher', '$semester', '$year', '$course', '$data')"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); Print "Your information has been successfully added to the database."; ?> Data being my entry for the file. Now My script to display all of this in a table looks like this... <?php $teacher=$_POST['teacher']; $result = mysql_query("SELECT * FROM syllabus WHERE teacher='$teacher'") or die('Query failed: ' . mysql_error()); echo "<table border='1'> <tr> <th> ID </th> <th> Name </th> <th> Semester </th> <th> Year </th> <th> Course </th> <th> Syllabus Uploaded </th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['teacher'] . "</td>"; echo "<td>" . $row['semester'] . "</td>"; echo "<td>" . $row['year'] . "</td>"; echo "<td>" . $row['course'] . "</td>"; echo "<td>" . $row['data'] . "</td>"; echo "</tr>"; } echo "</table>"; ?> However I get this in my table under Syllabus Uploaded. $sql = 'INSERT INTO `teacher` (`id`, `fname`, `lname`) VALUES ('''', ''Hope'', ''ThisWorks'')'; $sql = 'INSERT INTO `teacher` (`id`, `fname`, `lname`) VALUES ('''', ''John'', ''Doe'')'; Anybody have any advice? Quote Link to comment https://forums.phpfreaks.com/topic/49266-solved-script-to-store-and-then-view-a-file-stored-in-mysql-using-php/#findComment-241399 Share on other sites More sharing options...
jeaker Posted April 30, 2007 Author Share Posted April 30, 2007 O wow, Stupid mistake on my part. When I said I was getting this... $sql = 'INSERT INTO `teacher` (`id`, `fname`, `lname`) VALUES ('''', ''Hope'', ''ThisWorks'')'; $sql = 'INSERT INTO `teacher` (`id`, `fname`, `lname`) VALUES ('''', ''John'', ''Doe'')'; Printed out in my data column. It was the acutaul contents of the text file that I uploaded... Now that I have made a complete fool out of myself. Does anyone have any ideas on what I can display in the "data" part of my table. I do not want it to print out what is in the file. Perhaps just give an indication that there is something uploaded? Also, Is there an easy way to download the file that I have uploaded into the "data" field in my database? THanks again, Quote Link to comment https://forums.phpfreaks.com/topic/49266-solved-script-to-store-and-then-view-a-file-stored-in-mysql-using-php/#findComment-241421 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.