Topic: MySql/PHP help... Deleting a row from a database...

Well I am currently working on a Auth panel for me and my friend.. but i got stuck on the delete option of deleting the auth... please review my files and see if you can be any help...

delusers.php

<?php
   if(($username = strtolower($_POST['username'])) == "")
   {
     $username = strtolower($_GET['username']);
   }   

   if(($ip = strtolower($_POST['ip'])) == "")
   {
     $ip = strtolower($_GET['ip']);
   }

   if(($comments = strtolower($_POST['comments'])) == "")
   {
     $comments = strtolower($_GET['comments']);
   }
   
  if($username != "" || $ip != "" || $comments != "")
  {    
    echo '<html>';
    echo '<head>';
    echo '<title>Scripter\'s Panel V0.1 :: Viewing ' . $username . '</title>';
    echo '</head>';
    echo '<body bgcolor="CCCCCC" alink="FFFFFF" vlink="FFFFFF" link="FFFFFF">';
    echo '<center>';
    echo '<br>';
    echo '<br>';
    echo '<br>';
    echo '<br>';
    echo '<table height="97" width="550" border="0">';
    echo '<img src="./images/Logo.gif" border="0">';
    echo '</table>';
    echo '<table hieght="" width="550" border="0" background="./images/Middle.gif">';
    echo '<form action="deluser.php" method="post">';
    echo '<img src="./images/Header.gif" border="0"><br>';   
    echo '<td>';
    echo '<center>';
    echo '<br>';
    echo '<br>';
    echo '<br>';        
    echo '<b>Username:</b> ' . $username . '<br>';
    echo '<b>IP Address:</b> ' . $ip .'<br>';
    echo '<b>Comments:</b> ' . $comments . '<br><br>';
    echo '<input type="submit" name="del" value="Delete Auth"><br>';  
    echo '<br>';
    echo '<br>';
    echo '<br>';
    echo '<center><a href="delauths.php?username=' . $username . '">Delete Another Auth</a></center><br>';
    echo '<center><a href="panel.php">Go Back</a></center>';
    echo '<br>';
    echo '</center>';
    echo '</td>';
    echo '</form>'; 
    echo '</table>';
    echo '<img src="./images/Footer.gif" border="0">';
    echo '</center>';
    echo '<br>';
    echo '<br>';
    echo '<br>';
    echo '</body>';
    echo '</html>';
  }
?>

delusers.php

<?php
include('../config.php');
  echo '<html>';
  echo '<head>';
  echo '<title>Scripter\'s Panel V0.1 :: Delete Auths</title>';
  echo '</head>';
  echo '<body bgcolor="CCCCCC" alink="FFFFFF" vlink="FFFFFF" link="FFFFFF">';
  echo '<center>';
  echo '<br>';
  echo '<br>';
  echo '<br>';
  echo '<br>';
  echo '<table height="97" width="550" border="0">';
  echo '<img src="./images/Logo.gif" border="0">';
  echo '</table>';
  echo '<table hieght="" width="550" border="0" background="./images/Middle.gif">';
  echo '<img src="./images/Header.gif" border="0"><br>';
  echo '<img src="./images/DeleteAuthsImage.gif" border="0" width="550"><br>';
  echo '<td>';
  echo '<center>';
  echo '<br>';
  echo '<br>';
  echo '<br>';
  if($connect = mysql_connect($dbhost,$dbuser,$dbpass))
  {
    mysql_select_db($dbname);
    $query = mysql_query('SELECT * FROM auths');
    while($array = MySQL_fetch_array($query))
    {
      echo '<center><a href="delusers.php?username='.$array[username].'&ip='.$array[ip].'&comments='.$array[comments].'">'.$array[username].'</a></center><br>';
    }
  }
  echo '<br>';
  echo '<br>';
  echo '<br>';
  echo '<center><a href="panel.php">Go Back</a></center>';
  echo '<br>';
  echo '</center>';
  echo '</td>';
  echo '</table>';
  echo '<img src="./images/Footer.gif" border="0">';
  echo '</center>';
  echo '<br>';
  echo '<br>';
  echo '<br>';
  echo '</body>';
  echo '</html>';
?>

deluser.php

<?php
   if(($username = strtolower($_POST['username'])) == "")
   {
     $username = strtolower($_GET['username']);
   }   

include("../config.php");

  echo '<html>';
  echo '<head>';
  echo '<title>Scripter\'s Panel V0.1 :: Deleting ' . $username . ' from auth system</title>';
  echo '</head>';
  echo '<body bgcolor="CCCCCC" alink="FFFFFF" vlink="FFFFFF" link="FFFFFF">';
  echo '<center>';
  echo '<br>';
  echo '<br>';
  echo '<br>';
  echo '<br>';   
  echo '<table height="97" width="550" border="0">';
  echo '<img src="./images/Logo.gif" border="0">';
  echo '</table>';
  echo '<table hieght="" width="550" border="0" background="./images/Middle.gif">';
  echo '<img src="./images/Header.gif" border="0"><br>';   
  echo '<td>';
  echo '<center>';
  echo '<br>';
  echo '<br>';
  echo '<br>'; 
  if($con = mysql_connect($dbhost,$dbuser,$dbpass))
  {
    mysql_select_db($dbname);
    $query = mysql_query('DELETE FROM auths WHERE (`username`) VALUES(\''.$username.'\');');
    echo '<center><b>' . $username . ' deleted succesfully.</b></center>';
  }
  else
  {
    echo '<center><b>There was a error deleting the specified auth...</b></center>';
  }        
  echo '<br>';
  echo '<br>';
  echo '<br>';
  echo '<center><a href="delauths.php">Delete Another Auth</a></center><br>';
  echo '<center><a href="panel.php">Go Back</a></center>';
  echo '<br>';
  echo '</center>';
  echo '</td>';
  echo '</table>';
  echo '<img src="./images/Footer.gif" border="0">';
  echo '</center>';
  echo '<br>';
  echo '<br>';
  echo '<br>';
  echo '</body>';
  echo '</html>';
?>

the main page is delauths.php, it says it successfully deleted the auth but it doesn't really... the table 'auths' has the rows username, password, ip, comments, and rdate

2 (edited by scottywz 2005-06-30 18:05)

Re: MySql/PHP help... Deleting a row from a database...

One thing, you should use <div style="text-align: center"> instead of <center>, and close empty tags (<br></br> or <br /> instead of <br>). Just a suggestion.

Oh. And you MUST, I mean MUST, put in the DOCTYPE.
Example: For XHTML 1.0 Strict, use <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
XHTML 1.0 Transitional: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
XHTML 1.0 Frameset: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

I'm not good at MySQL queries.

Re: MySql/PHP help... Deleting a row from a database...

The delete query should be of the form

DELETE FROM table WHERE field = value

Re: MySql/PHP help... Deleting a row from a database...

scottywz wrote:

One thing, you should use <div style="text-align: center"> instead of <center>, and close empty tags (<br></br> or <br /> instead of <br>). Just a suggestion.

Oh. And you MUST, I mean MUST, put in the DOCTYPE.
Example: For XHTML 1.0 Strict, use <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
XHTML 1.0 Transitional: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
XHTML 1.0 Frameset: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

I'm not good at MySQL queries.

wrong wrong wrong tongue

you can use <center> you don't need to do <br /> (infact i think its wrong to use it in html), and you don't need a doctype

have a look at the source on http://www.google.com/ tongue

just because punbb is 1337 doesn't mean everyone else MUST be

5 (edited by scottywz 2005-07-01 01:32)

Re: MySql/PHP help... Deleting a row from a database...

Connorhd wrote:

...

wrong wrong wrong tongue

you can use <center> you don't need to do <br /> (infact i think its wrong to use it in html), and you don't need a doctype

have a look at the source on http://www.google.com/ tongue

just because punbb is 1337 doesn't mean everyone else MUST be

I'm just saying. And running it through the validator without a DOCTYPE will make it default to something (and it may not be the intended DOCTYPE). After all, I did say "just a suggestion."

And isn't <center> deprecated?

EDIT: I never knew Google was so bad at HTML.
1. You need to say what language in <script>.
2. The DOCTYPE is mandatory.
3. This is what the validator said: http://validator.w3.org/check?uri=http% … ;verbose=1

It also said:

A DOCTYPE Declaration is mandatory for most current markup languages and without one it is impossible to reliably validate this document. I am falling back to "HTML 4.01 Transitional" and will attempt to validate the document anyway, but this is very likely to produce spurious error messages for most non-trivial documents.

So, yes, DOCTYPE is mandatory. See this.