Jump to content

Morthian

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Everything posted by Morthian

  1. I have a script that will upload a file and store its information in a database based on POST data. The script will set a variable to either a success message or an error message, depending on whether the upload was successful or not. The message variable will then be outputted to the user. The problem here is that if a user successfully uploads a file and then clicks back or refresh in the browser, the "You are trying to view a page that contains POSTDATA" dialog will appear. If the user simply clicks OK on this dialog, the file will be re-uploaded and a duplicate of the submission's record will be created. The only way I know to avoid this dialog is by using the header() function to clear the POST data. However, if I use this function, not only will the POST data be cleared, but the variable containing the success message will also be cleared, and there will be no confirmation to the user that their submission was uploaded successfully. How can I solve this problem?
  2. Yes, I know how to record a total number of views. I am asking how to record the number of views in a given time, such as a day or a week. On GameSpot, the popularity of the games is based on total unique views from yesterday. Since my site is certainly not as well known as GameSpot, I figure it would be better to base the popularity of content on views from the last week, or last 7 days. How can I do this?
  3. By the way, just if I wasn't clear, when I say content I mean records in a database. For example, Newgrounds shows its most popular flash submissions on its Portal page. DeviantArt does the same sort of thing with art submissions. I think somehow sorting records by the most views in the last week might be a good way of showing the "most popular" items. But like I said, I would have no clue how to actually do this.
  4. I want to have a section on my site that shows the most popular content. I see this on a lot of sites, but I have no idea how to do it myself. Could anyone help me out with this?
  5. Yeah, I don't know what the hell I was thinking there. Thanks for pointing that out. But I still don't understand why my Switch event is not working. The game_ext variable never gets set to either of those options.
  6. I am so amazingly flustered. I just can't seem to figure out how to make my upload script work. The game_ext variable doesn't seem to set itself and I keep getting this error: Warning: move_uploaded_file(upload/) [function.move-uploaded-file]: failed to open stream <?php mysql_connect('localhost', 'angryclo_user', '********') or die(mysql_error()); mysql_select_db('angryclo_angrycloud') or die(mysql_error()); { if (($_FILES["game_source"]["type"] != "application/x-shockwave-flash") && ($_FILES["game_source"]["type"] != "application/x-cnc")) { die("Invalid file type." . "<br />"); } if ($_FILES["game_source"]["size"] > 500000) { die("File is too large." . "<br />"); } if ($_FILES["game_source"]["error"] > 0) { die($_FILES["game_source"]["error"] . "<br />"); } else { echo "Upload: " . $_FILES["game_source"]["name"] . "<br />"; echo "Type: " . $_FILES["game_source"]["type"] . "<br />"; echo "Size: " . ($_FILES["game_source"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["game_source"]["tmp_name"] . "<br />"; } switch($_FILES["game_source"]["type"]) { case '"application/x-shockwave-flash"': $game_ext=".swf"; break; case '"application/x-cnc"': $game_ext=".ccn"; break; } } mysql_query("INSERT INTO game_data (type, game_source, width, height, title, website_name, website_url, genre, comment) VALUES ('".$_POST['type']."','".(mysql_insert_id().$_POST['game_ext'])."','".$_POST['width']."','".$_POST['height']."','".$_POST['title']."','".$_POST['website_name']."','".$_POST['website_url']."','".$_POST['genre']."','".$_POST['comment']."')") or die(mysql_error()); move_uploaded_file($_FILES["game_source"]["tmp_name"], "upload/" . $_FILES["game_source"][(mysql_insert_id().$game_ext)]); echo "Stored in: " . "upload/" . $_FILES["game_source"][(mysql_insert_id().$game_ext)] . "<br />"; echo "Upload successful."; mysql_close ?>
  7. Yes, the spaces must have been the problem. Thanks for the help. But now I keep getting this error: Error: No database selected I updated my code a bit since my first post: <?php $con = mysql_connect('localhost', 'angryclo_user', '********'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db('angryclo_angrycloud', $con); $sql = "INSERT INTO game_data (type, width, height, title, website_name, website_url, genre, comment) VALUES ('".$_POST['type']."','".$_POST['width']."','".$_POST['height']."','".$_POST['title']."','".$_POST['website_name']."','".$_POST['website_url']."','".$_POST['genre']."','".$_POST['comment']."')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } { if (($_FILES["file_source"]["type"] != "application/x-shockwave-flash") && ($_FILES["file_source"]["type"] != "application/x-cnc")) { die("Invalid file type." . "<br />"); } if ($_FILES["file_source"]["size"] > 500000) { die("File is too large." . "<br />"); } if ($_FILES["file_source"]["error"] > 0) { die("Return Code: " . $_FILES["file_source"]["error"] . "<br />"); } else { echo "Upload: " . $_FILES["file_source"]["name"] . "<br />"; echo "Type: " . $_FILES["file_source"]["type"] . "<br />"; echo "Size: " . ($_FILES["file_source"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file_source"]["tmp_name"] . "<br />"; if ($_FILES["file_source"]["type"] == "application/x-shockwave-flash") { $filename = ($mysql_insert_id() . ".swf"); } if ($_FILES["file_source"]["type"] == "application/x-cnc") { $filename = ($mysql_insert_id() . ".ccn"); } move_uploaded_file($_FILES["file_source"]["tmp_name"], "upload/" . $_FILES["file_source"][$filename]); echo "Stored in: " . "upload/" . $_FILES["file_source"][$filename] . "<br />"; } } echo "Upload successful."; mysql_close($con) ?> The database name is shown just as it is in PHPMyAdmin.
  8. I am a bit of newbie to PHP. I am trying to create a file upload script and just learn as I code it. Don't be surprised if there are a lot of errors in my code. This is the specific error I am having problems with: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'name, website url, genre, comment) VALUES ('Vitalize!','320','240','TestGame' at line 1 My code: <?php $con = mysql_connect("localhost", "angryclo_user", "********"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("angrycloud", $con); $sql = "INSERT INTO game_data (type, width, height, title, website name, website url, genre, comment) VALUES ('$_POST[type]','$_POST[width]','$_POST[height]','$_POST[title]','$_POST[website_name]','$_POST[website_url]','$_POST[genre]','$_POST[comment]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } { if (($_FILES["file_source"]["type"] != "application/x-shockwave-flash") && ($_FILES["file_source"]["type"] != "application/x-cnc")) { die("Invalid file type." . "<br />"); } if ($_FILES["file_source"]["size"] > 500000) { die("File is too large." . "<br />"); } if ($_FILES["file_source"]["error"] > 0) { die("Return Code: " . $_FILES["file_source"]["error"] . "<br />"); } else { echo "Upload: " . $_FILES["file_source"]["name"] . "<br />"; echo "Type: " . $_FILES["file_source"]["type"] . "<br />"; echo "Size: " . ($_FILES["file_source"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file_source"]["tmp_name"] . "<br />"; move_uploaded_file($_FILES["file_source"]["tmp_name"], "upload/" . $_FILES["file_source"][$mysql_insert_id()]); echo "Stored in: " . "upload/" . $_FILES["file_source"][$mysql_insert_id()] . "<br />"; } } echo "Upload successful."; mysql_close($con) ?>
  9. I haven't really written it yet because I don't know how to do this. I like to know exactly what I am doing before I do it. Thats just how I am. I don't need anyone to write my code for me; I just want to know how to do this one thing. Is there not just a somewhat simple echo command to set the tmp_name of the file to the id number of the record where all the file's data was just stored? =/
  10. I am creating a page to upload files, as well as to submit data about the file to be stored in a database. When the form data is submitted, how can I program it to automatically rename the uploaded file to the ID or Key number of the record in the database in which the file's information is stored? I am rather new to the PHP language, so explanation to the code would be very helpful. Thanks.
×
×
  • 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.