Gubbins Posted April 2, 2010 Share Posted April 2, 2010 I cant seem to get the code correct, can anyone see the error please? <?php $que = mysql_query("SELECT * FROM `staff` WHERE `playername` = '$player' LIMIT 1")or die(mysql_error()); $arr = mysql_fetch_array($que); $lvl = $arr['level']; if ($lvl == 4) { if ($_POST['clean']){ $dead = mysql_query("SELECT * FROM `players` WHERE `status` == 'dead'"); mysql_query ("DELETE FROM `garage` WHERE `owner` = '$dead'"); echo "Success"; } ?> <html> <head> <title>DataBase Cleaner</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <br /> <form action="clean.php" method="post"> Clean the Database <br /> <br /> <br /> <br /> <input name="clean" class="submit" type="submit" value="Submit" id="clean"> <? } else{ echo "No Access"; die(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/197389-clean-database-not-working/ Share on other sites More sharing options...
taquitosensei Posted April 2, 2010 Share Posted April 2, 2010 $dead is a database result you need to get the value from it $result_dead=mysql_query("SELECT * FROM `players` WHERE `status` == 'dead'"); while ($row_dead = mysql_fetch_array($result_dead, MYSQL_ASSOC)) { $dead=$row['owner field from players']; } mysql_query ("DELETE FROM `garage` WHERE `owner` = '$dead'") Quote Link to comment https://forums.phpfreaks.com/topic/197389-clean-database-not-working/#findComment-1036056 Share on other sites More sharing options...
Gubbins Posted April 2, 2010 Author Share Posted April 2, 2010 I now have this:- <?php require("connections/db.php"); require("connections/require.php"); $que = mysql_query("SELECT * FROM `staff` WHERE `playername` = '$player' LIMIT 1")or die(mysql_error()); $arr = mysql_fetch_array($que); $lvl = $arr['level']; if ($lvl == 4){ if ($_POST['clean']) $result_dead=mysql_query("SELECT * FROM `players` WHERE `status` == 'dead'"); while ($row_dead = mysql_fetch_array($result_dead, MYSQL_ASSOC)) { $dead=$row['owner field from players']; } mysql_query ("DELETE FROM `garage` WHERE `owner` = '$dead'"); echo "Success"; } ?> <html> <head> <title>DataBase Cleaner</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <br /> <form action="clean.php" method="post"> Clean the Database <br /> <br /> <br /> <br /> <input name="clean" class="submit" type="submit" value="Submit" id="clean"> <? } else{ echo "No Access"; die(); } ?> with this error:- Parse error: syntax error, unexpected '}' in clean.php on line 40 Quote Link to comment https://forums.phpfreaks.com/topic/197389-clean-database-not-working/#findComment-1036089 Share on other sites More sharing options...
jcbones Posted April 2, 2010 Share Posted April 2, 2010 <?php require("connections/db.php"); require("connections/require.php"); $que = mysql_query("SELECT * FROM `staff` WHERE `playername` = '$player' LIMIT 1")or die(mysql_error()); $arr = mysql_fetch_array($que); $lvl = $arr['level']; if ($lvl == 4){ if ($_POST['clean']) { $result_dead=mysql_query("SELECT * FROM `players` WHERE `status` = 'dead'"); while ($row_dead = mysql_fetch_array($result_dead, MYSQL_ASSOC)) { $dead=$row['owner field from players']; } mysql_query ("DELETE FROM `garage` WHERE `owner` = '$dead'"); echo "Success"; } ?> <html> <head> <title>DataBase Cleaner</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> <br /> <form action="clean.php" method="post"> Clean the Database <br /> <br /> <br /> <br /> <input name="clean" class="submit" type="submit" value="Submit" id="clean"> <? } else{ echo "No Access"; die(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/197389-clean-database-not-working/#findComment-1036093 Share on other sites More sharing options...
Gubbins Posted April 2, 2010 Author Share Posted April 2, 2010 Thanks no errors but it didn't work :S Quote Link to comment https://forums.phpfreaks.com/topic/197389-clean-database-not-working/#findComment-1036097 Share on other sites More sharing options...
Gubbins Posted April 2, 2010 Author Share Posted April 2, 2010 Thanks no errors but it didn't work :S cause i dint know what to put in this section:- $dead=$row['owner field from players']; Quote Link to comment https://forums.phpfreaks.com/topic/197389-clean-database-not-working/#findComment-1036099 Share on other sites More sharing options...
mikesta707 Posted April 2, 2010 Share Posted April 2, 2010 probably because you just copy pasted his example without trying to understand it. You need to change the array key in =$row['owner field from players']; to whatever the column is called in your 'players' table that has the value of the 'owner' column in your 'garage' table. just a word of advice, usually copy pasting code you get from a help forum won't work. you actually have to take the example, understand why it works, and alter it to work with your code. in your case the alteration was very minor... but crucial to the code working Quote Link to comment https://forums.phpfreaks.com/topic/197389-clean-database-not-working/#findComment-1036101 Share on other sites More sharing options...
Gubbins Posted April 2, 2010 Author Share Posted April 2, 2010 Thank you for your fast response and explanation. I changed it to $dead=$row['playername']; i know this is not right, but to be honest this small piece of code is to much for me! i dont understand what needs to go in here! I know you said "to whatever the column is called in your 'players' table that has the value of the 'owner' column in your 'garage' table". under the players table i have 'playername' something tells me i am still wrong!!! Quote Link to comment https://forums.phpfreaks.com/topic/197389-clean-database-not-working/#findComment-1036109 Share on other sites More sharing options...
Gubbins Posted April 2, 2010 Author Share Posted April 2, 2010 I think all i need is an example to know what to change, can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/197389-clean-database-not-working/#findComment-1036146 Share on other sites More sharing options...
Gubbins Posted April 3, 2010 Author Share Posted April 3, 2010 ok i tried this but still no joy $dead=$row['playername FROM Players']; Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/197389-clean-database-not-working/#findComment-1036309 Share on other sites More sharing options...
taquitosensei Posted April 4, 2010 Share Posted April 4, 2010 It's your database layout. Nobody here would have any idea. You should know long before starting on the php what your keys are in your tables and what they correlate to in other tables. Quote Link to comment https://forums.phpfreaks.com/topic/197389-clean-database-not-working/#findComment-1036749 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.