Jump to content

phpbnoobb23

Members
  • Posts

    12
  • Joined

  • Last visited

phpbnoobb23's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I was wondering if there is a way to add an progress bar to this script that uploads files to a sql database <!DOCTYPE html> <head> <title>MySQL file upload</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body> <form action="add_file.php" method="post" enctype="multipart/form-data"> <input type="file" name="uploaded_file"><br> <input type="submit" value="Upload file"> </form> <p> <a href="list_files.php">See all files</a> </p> <p> <a href="search.php">Search Database</a> </p> </body> </html> If so, how would i go about doing that?
  2. Thanks A lot guys. I appreciate all the help and input from everyone. Special thanks to Ch0cu3r for being extra patient. My problem is now solved.
  3. I edited my reply. The file names are being list. My error was that i added an (s) at the end of row, So it did not fetch the file names. My real problem now is i'm still getting the "Invalid filename given" error when I press submit.
  4. that fixed the problem and the only error i'm getting now is : Invalid filename given when i do query from search.php My script for search.php looks like this : <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta name="generator" content="Adobe GoLive" /> <title>File Select</title> <!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. We recommend that you do not modify it.--><script>var __adobewebfontsappname__="dreamweaver"</script><script src="http://use.edgefonts.net/aguafina-script:n4:default.js" type="text/javascript"></script> </head> <body> <div id="title"> <h3 align="center">File Upload</h3> </div> <form action="result.php" method="post" name="fileID" target="_self" class="inp" AUTOCOMPLETE="ON"> <h1> <!--Input file name--> <label for="fileID">File Name: </label> <input type="text" name='file1' id='sampleID' list="samp"> </input><br> <datalist id="samp"> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta name="generator" content="Adobe GoLive" /> <title>File Select</title> <!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. We recommend that you do not modify it.--><script>var __adobewebfontsappname__="dreamweaver"</script><script src="http://use.edgefonts.net/aguafina-script:n4:default.js" type="text/javascript"></script> </head> <body> <div id="title"> <h3 align="center">File Upload</h3> </div> <form action="result.php" method="post" name="fileID" target="_self" class="inp" AUTOCOMPLETE="ON"> <h1> <!--Input file name--> <label for="fileID">File Name: </label> <input type="text" name='file1' id='sampleID' list="samp"> </input><br> <datalist id="samp"> <?php $db = new mysqli('localhost', 'root', '', 'test_db'); $query = $db->query("SELECT * FROM `file` ORDER BY `file`.`name` ASC LIMIT 0 , 30"); while($row = $query->fetch_assoc()){ $File_name = $row['name']; echo "<option value=$File_name>$File_name/option> <br>"; } ?> </datalist> <input type="submit" class="button"> </form> </body> </html>
  5. It seems to work fine, but i get an error that says: Warning: mysqli_query() expects at least 2 parameters, 1 given in /home/u293130761/public_html/result.php on line 10 Invalid filename given. I understand that the query is for the file name and size, but when i query the file name in search.php I get the error above.
  6. Please excuse my confusion with some of the reading. I tried to cut my code down based on the new mysqli. I do hope I wrote the correct functions. <?php $db = new mysqli('localhost', 'root', '', 'test_db'); if($db->connect_errno > 0){ die('Unable to connect to database [' . $db->connect_error . ']'); } $File_name->real_escape_string($File_name); $result = mysqli_query("SELECT name, size FROM `file` WHERE name='$File_name' "); if(($result->num_rows) = 1) { list($name, $size) = $result -> fetch_row (); echo "The file size for <i>$name</i> is <b>$size</b>"; // output info } else { echo 'Invalid filename given'; //error } $db->close(); ?>
  7. The script below should suffice, correct? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Result Summary</title> <link href="CSS/oneColLiqCtrHdr.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="container"> <p> <?php $File_name = htmlspecialchars($_POST['File_name']); $File_name = mysql_real_escape_string($File_name); // sanitize $db = new mysqli('localhost', 'root', '', 'test_db'); If (strlen($File_name) == 0) { $$result = mysql_query("SELECT name, size FROM `file` WHERE name='$File_name' "); // use it in the query, fetch the file size for the file. WHILE ($rows = mysql_fetch_array($query)): $size = $rows['size']; if(mysql_num_rows($result)) { list($name, $size) = mysql_fetch_row($result); // populate variables with the file name and size echo "The file size for <i>$name</i> is <b>$size</b>"; // output info } else { echo 'Invalid filename given'; } ?> </p> <div class="footer"> <p>Results ©2014</p> <!-- end .footer --></div> <!-- end .container --></div> </body> </html>
  8. The mysql_* functions work fine. I've used them in the past to run little tests and it worked fine.
  9. So, it would look something like this? <?php $dbLink = new mysqli('localhost', 'root', '', 'test_db'); $File_name = mysql_real_escape_string($File_name); // sanitize $result = mysql_query("SELECT name, size FROM `file` WHERE name='$File_name' "); // use it in the query, fetch the file size for the file. if(mysql_num_rows($result)) { list($name, $size) = mysql_fetch_row($result); // populate variables with the file name and size echo "The file size for <i>$name</i> is <b>$size</b>"; // output info } else { echo 'Invalid filename given'; } ?> what about the forms? how would I place them to fetch the file name and then submit to output on the results page? I'm sorry just really new to this.
  10. Yes, so when i press submit I would like to pull the file size information from the table. I have tried something like this: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>GeneSeq -- Result Summary</title> <link href="CSS/oneColLiqCtrHdr.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="container"> </p></div> <p> <table width="95%" align="center" class="tableBorder" name="results" cellpadding="5px"> <thead align="center" > <th width="5%" class='content'>File_Size</th> </thead> <?php $File_name = htmlspecialchars($_POST['File_name']); $connect = mysql_connect('localhost', 'root', ''); mysql_select_db("test_db"); If (strlen($File_name) == 0) { $query = mysql_query("SELECT * FROM `file` ORDER BY `file`.`size` ASC LIMIT 0 , 30 "); WHILE ($rows = mysql_fetch_array($query)): $size = $rows['size']; if (strlen($File_name) == 0) echo "No file by that name."; $File_Size = preg_replace("/_[0-9]{0,5}$/", "",$size); echo "<tr width=60% class='content'>"; echo "<td class='content'>$size<br></td></tr>"; endwhile; ?> </table> </p> <!-- end .content --></div> <div class="footer"> <p>Example ©2013</p> <!-- end .footer --></div> <!-- end .container --></div> </body> </html> I'm extremely new to this, so it looks sloppy. I tried putting some stuff together, but it does not work. I get this error: Parse error: syntax error, unexpected $end in /home/u293130761/public_html/result.php on line 52
  11. Hello, I seem to have some problem with my script that has a goal of outputting data about the file size when a filename is queried. The sql table name is file The table columns are as followed: id | name | mime | size The file name is stored in name. The script that i have that gets the file name is: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta name="generator" content="Adobe GoLive" /> <title>File Select</title> <!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. We recommend that you do not modify it.--><script>var __adobewebfontsappname__="dreamweaver"</script><script src="http://use.edgefonts.net/aguafina-script:n4:default.js" type="text/javascript"></script> </head> <body> <div id="title"> <h3 align="center">File Upload</h3> </div> <form action="result.php" method="post" name="fileID" target="_self" class="inp" AUTOCOMPLETE="ON"> <h1> <!--Input file name--> <label for="fileID">File Name: </label> <input type="text" name='file1' id='sampleID' list="samp"> </input><br> <datalist id="samp"> <?php $connect = mysql_connect('localhost', 'root', ''); mysql_select_db("test_db"); $query = mysql_query("SELECT * FROM `file` ORDER BY `file`.`name` ASC LIMIT 0 , 30"); WHILE ($rows = mysql_fetch_array($query)): $File_name = $rows['name']; echo "<option value=$File_name>$File_name/option> <br>"; endwhile; ?> </datalist> <input type="submit" class="button" > </form> </body> </html> As you can see, I got the file name, but I just can't figure out how to display the file size. The file size is store in size. Just to clarify, I need to search a file name in the database and then output the file size also stored in the database under the same table name "file."
×
×
  • 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.