RoughitforGreen247 Posted May 14, 2006 Share Posted May 14, 2006 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 in the picture's corresponding mySQL db entry 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. The columns in the database referenced in the code are: path (the filename of the picture like picture.jpg), name (the name the uploader selects to have displayed for the picture), description (the short line describing the picture that will be placed under the picture on the website).Code:<form action="done.php" method="post"><?phpmysql_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 pictureecho "<center><br><br><br><br><img src='http://iequalsgamer.frih.net/useruploads/files/" . $info['path'] . "'><br><br>"; //prints the picture itselfecho "<center>" . $info['description'] . "<br><br>"; //prints the descriptionecho "<input type='checkbox' name='" . $info['path'] . "'> Is this inapropriate?<br><br>"; // Where i put in the decision, the input is named the path of the corresponding imagewhile($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:<?phpmysql_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 pictureif ($n){mysql_query("DELETE FROM uploads WHERE path ='$path'"); //deletes from the database when the checkbox was checkedunlink(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 entrymysql_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){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. Thank you so much, I have been trying to find the problem in the code for over a week now. Quote Link to comment Share on other sites More sharing options...
sasa Posted May 14, 2006 Share Posted May 14, 2006 change lines [code]$n = $_POST['$path'];[/code] to [code]$n = $_POST[$path];[/code] or to[code]$n = $_POST["$path"];[/code] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 14, 2006 Share Posted May 14, 2006 This line [code]<?php $n = $_POST['$path']; ?>[/code] is your problem. Remove the single quotes. When you use the single quotes, PHP will look for the index of with the literal sting [b]$path[/b], not the value of the variable [!--coloro:red--][span style=\"color:red\"][!--/coloro--][b]$path[/b][!--colorc--][/span][!--/colorc--]. Also remove the single quotes from a similar line later.Your method still may not work, since only checkboxes that were checked are returned to your script.Why do you do your code once and then again in the "while" loop? Just do all your code in the "while" loop.Ken Quote Link to comment Share on other sites More sharing options...
RoughitforGreen247 Posted May 15, 2006 Author Share Posted May 15, 2006 Thanks for the help, guys. The code still seems to be malfunctioning, but I really appreciate the attempt. I doubled the code because the code I learned off of at php.about.com was doubled, so I wasn't sure whether it was necessary. I've tried changing the checkbox around, but the POST still seems to return nothing. Ah well, I'll keep trying. And thanks again. Quote Link to comment 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.