Jump to content

Clean database not working.


Gubbins

Recommended Posts

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(); 

} 

?>  
   

Link to comment
Share on other sites

$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'")

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?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();

}

?>   
   

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!!!

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.