Hi, I'm having a lot of trouble with some code I am working on. I am trying to write a script that will allow me to ensure the appropriateness of pictures people upload before they appear on my website. To do that, I assign the value 1 to the screen column when every file is uploaded. I have a page that displays all the entries in the database with the value of one, and puts a little form box underneath.
That is the form code. It then sends the information to the code below, which goes through and deletes every entry that was checked by the form page, and changes the value to 2 on every entry that was not checked.
My problem is, the form does not appear to pass anything on, or atleast nothing my second piece of code can read. It always changes the value to 2, and never deletes it from the database. Can anyone help me?
Last edited by RoughitforGreen247 on Sun May 14, 2006 2:52 pm; edited 1 time in total
| Code: |
|
<form action="done.php" method="post"> <?php mysql_connect("localhost", "roughitf_firsty", "******") or die(mysql_error()); mysql_select_db("roughitf_first") or die(mysql_error()); //connects to the database $data = mysql_query("SELECT * FROM uploads WHERE screen='1'") or die(mysql_error()); // This will load the entries that have not already been approved $info = mysql_fetch_array($data); echo "<h2><center>" . $info['name'] . "</h2>"; //Prints the name of the picture echo "<center><br><br><br><br><img src='http://iequalsgamer.frih.net/useruploads/files/" . $info['path'] . "'><br><br>"; //prints the picture itself echo "<center>" . $info['description'] . "<br><br>"; //prints the description echo "<input type='checkbox' name='" . $info['path'] . "'> Is this inapropriate?<br><br>"; // Where i put in the decision (it was originally written with checkboxes, but one of my attempts to fix it, I tried text) while($info = mysql_fetch_array($data)) //Loop, does same thing as above { echo "<h2><center>" . $info['name'] . "</h2>"; echo "<center><br><br><br><br><img src='http://iequalsgamer.frih.net/useruploads/files/" . $info['path'] . "'><br><br>"; echo "<center>" . $info['description']; echo "<input type='checkbox' name='" . $info['path'] . "'> Is this inapropriate?<br><br>"; } ?> <input type="submit"> </form> |
That is the form code. It then sends the information to the code below, which goes through and deletes every entry that was checked by the form page, and changes the value to 2 on every entry that was not checked.
| Code: |
|
<?php mysql_connect("localhost", "roughitf_firsty", "******") or die(mysql_error()); mysql_select_db("roughitf_first") or die(mysql_error()); //connects to the database $data = mysql_query("SELECT * FROM uploads WHERE screen='1'") or die(mysql_error()); //Loads the entries again that have not been checked $info = mysql_fetch_array($data); $path = $info['path']; $n = $_POST['$path']; //gets the value of the checkbox that corresponds to the picture if ($n){ mysql_query("DELETE FROM uploads WHERE path ='$path'"); //deletes from the database when the checkbox was checked unlink(files/$path); //This is supposed to delete the file, but I'm not sure whether it works, and is not the problem that concerns me } else { $name = $info['name']; //loads the information about the entry for resubmitting $description = $info['description']; mysql_query("DELETE FROM uploads WHERE path ='$path'"); //deletes the entry mysql_query("INSERT INTO uploads VALUES ( '$path','$name','$description','user','2')") or die(mysql_error()); //rewrites the entry with the value 2, marking that it has been checked } while($info = mysql_fetch_array($data)) //While loop just does the same thing over and over again { $path = $info['path']; $n = $_POST['$path']; echo $path . " <- PATH<br><br>"; if ($n == "y"){ mysql_query("DELETE FROM uploads WHERE path ='$path'"); unlink(files/$path); } else { $name = $info['name']; $description = $info['description']; $rand = mysql_query("DELETE FROM uploads WHERE path ='$path'"); mysql_query("INSERT INTO uploads VALUES ( '$path','$name','$description','user','2')") or die(mysql_error()); } } ?> |
My problem is, the form does not appear to pass anything on, or atleast nothing my second piece of code can read. It always changes the value to 2, and never deletes it from the database. Can anyone help me?
Last edited by RoughitforGreen247 on Sun May 14, 2006 2:52 pm; edited 1 time in total
