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


something's wrong but I don't see it :<





Poetsunited
Code:

$result = mysql_query("SELECT * FROM `targets`");

while($row = mysql_fetch_array($result))
  {
  echo '<form action="hitlist.php" method="post">';
  echo '<input type="radio" name="remuser">' . $row['username'];
  echo '<br />';
  }

echo '<input type="submit" value="Submit">';
echo '</form>' ;


if ($_POST[remuser] != "")
{
mysql_query("DELETE FROM `targets` WHERE `username` = '$_post[remuser]' ");
echo "succes!";
}
else
echo 'select a name to delete' ;



for some reason my script won't delete the user but it doesn't error either :/

anyone knows how to solve this?

thanks

- kev -
rvec
try leaving out all the ` in the queries
,putting the <form> tag above the while loop
, $_post is not the same variable as $_POST so change that in the query
, the radio button doesn't have a value, maybe add a value parameter and put the username in it
and put {} around the variable in the sql query to make sure it sees the whole thing as the variable name and not just $_POST.
Fire Boar
rvec wrote:
,putting the <form> tag above the while loop
, the radio button doesn't have a value, maybe add a value parameter and put the username in it
and put {} around the variable in the sql query to make sure it sees the whole thing as the variable name and not just $_POST.


These things are your Big Problems.

Code:
$result = mysql_query("SELECT * FROM `targets`");

echo "<form action=\"hitlist.php\" method=\"post\">\n";

while($row = mysql_fetch_array($result))
  {
  echo "<input type=\"radio\" name=\"remuser\" value=\"".$row['username']."\"><br />\n";
  }

echo "<input type=\"submit\" value=\"Submit\">\n";
echo "</form>" ;


if ($_POST['remuser'] != "")
{
mysql_query("DELETE FROM `targets` WHERE `username` = '".$_POST['remuser']."' ");
echo "success!";
}
else
echo 'select a name to delete' ;


Of course, you'll also want to validate $_POST['remuser'] to prevent SQL injections - the code above is extremely vulnerable and a hacker could quite easily post unexpected data and screw around with your database.
Poetsunited
I tried all the things you said, still didn't work :/

anything else that could help?


also fire boar, this site is meant for a few people to help them on a game, so if they'd do anything wrong with it, it's their own problem :p

anyone got a working delete script using a variable, because i think for some reason my variable doesn't work in this query


thanks guys for the help already
Poetsunited
or anyone who know how to make a script like the one I'm trying to make... where you have data being printed from your database but where you can also remove that data ( preferably using while)


because I have like no idea what to do right now :/


- kev -
coreymanshack
Poetsunited wrote:
or anyone who know how to make a script like the one I'm trying to make... where you have data being printed from your database but where you can also remove that data ( preferably using while)


because I have like no idea what to do right now :/


- kev -


Make sure remuser variable exists. Add a print function into the if{} block where it does something if remuser != ""; See if it prints it to the browser screen.

Is your while loop returning data to the browser? If not the problem may lie in your connect script.
Poetsunited
thanks all, found it :p forgot ' '

- kev -
Fire Boar
Poetsunited wrote:
also fire boar, this site is meant for a few people to help them on a game, so if they'd do anything wrong with it, it's their own problem :p


That may be, but it's very good practice to make sure the code is at least mostly watertight. Leaving huge loopholes may not seem like a bad thing at the time, but what if someone randomly finds this site and hacks through the back door you conveniently opened for them? Plus, it's worth getting into good habits early on.
Related topics
question : how to make a form on dreamweaver?
What's Wrong with Making Money?
Adding blank rows
What is wrong with this MySQL query?
Don't know what's wrong
I'm doing something wrong,,,
Get checkboxes values trough $_POST. HTML wrong?
Music playin' from enterin' the site?
I don't know how to describe it but I need help.
Is it wrong to care for people!?
Need a <site> Account
How to Input Text into a php script
Overflow
Hulp nodig met de PHP mail functie
HTML to CSS code
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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