FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP script trouble





RoughitforGreen247
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.

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?
Rhysige
Would it be possible for you to add comments using
//comment here
to explain what your code is doing at each point?

Also I suggest with something like this you use a checkbox rather than a text field.[/code]
RoughitforGreen247
It has been fixed. I originally did use checkboxes, but after it was clear that none of my other attempts to fix it had worked, I tried converting it to text, but both failed.
DanielXP
I wonder how many people on this forum forgets to change there password to **********

No relly i want to know Arrow Question
NG
it might be the same as his host password thats y hes covering it Smile
Ghost Face
Lolz, I'm such a hypocrite.

[url]frihost.pastebin.com[/url] Very Happy Twisted Evil
mathiaus
RoughitforGreen247 wrote:
It has been fixed.


-close-
Related topics
Phoenix free PHP scripts
error in my PHP script
how can i make a php script for enter username and password?
Inserting data to MYSQL with a PHP script
Running a "Hello World" php script
[PHP] Running Cron Jobs Via PHP Script
Simple PHP script not working
PHP Script- How can we install it
I need a VERY simple php script
PHP Script needed
Logging systeem php script
Preventing bad PHP script calls
array check box on php script using $_POST
vBulletin Config.php script
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.