Location: PHPKode > scripts > PHP Online Invoice System > php-online-invoice-system/editadmin.php
<?
/*
 * Exemplar Web hosting
 * http://www.exemplar.biz
 *
 * Title: PHP Online Invoice System
 * Version: 2.0
 * Author: Exemplar
 * Date: 01-01-2006
 *
*/

include('header.php');

  if ($id) {
echo "<h1>Edit Admin</h1>";
}
else
{
echo " <h1>Add new Admin</h1>";
}

if($submit && ($passwd === $passwd2))
{
$passwd = $_POST['passwd'];
//-------------------check user name-----------------------------------------------------
$name = $_POST['name'];

$select = "select name from admins where name = '".$name."';";
$query = mysql_query($select) or die ("Mysql error! It was: ".mysql_error());
$rows = mysql_num_rows($query);
if ($rows != 0)
{

  echo ("<script language=javascript>alert ('Sorry! $name is already taken!')</script>");
  echo ("<script language=javascript>document.location.href = 'editadmin.php'</script>");

exit;


}
//-----------------------------------end check-------------------------------------------
$sql = "INSERT INTO admins (name, password, email) VALUES ('$name','$passwd','$email')";
$result = mysql_query($sql);
echo "<p>Thank you: a new admin has been created</p>";
echo "<p>To view client details, please <a href=admins.php>see the admin list</a>.</p>";
}
else if($update && ($passwd === $passwd2))
{
$passwd_updated = $_POST['passwd'];
$sql = "UPDATE admins SET name='$name',password='$passwd_updated',email='$email' WHERE name='$name'";
$result = mysql_query($sql);
echo "<p>Thank you: the client admin have been updated.</p>";
}
else if ($passwd !== $passwd2) {
echo "You entered two different passwords. <a href=$PHP_SELF?id=$id>Please try again</a>";
}
else if($id)
{
$result = mysql_query("SELECT * FROM admins WHERE adminid=$id",$db);
while ($row = mysql_fetch_array($result)){
$clientid=$row["clientid"];
$name=$row["name"];
$password=$row["password"];
$email=$row["email"];

}
?>
  <form method="post" action="<?php echo $PHP_SELF?>">
    <p>
      <input type="hidden" name="id" value="<?=$clientid?>">
      Admin's Login Name:<br>
      <input type="text" name="name" size="20" value="<?=$name?>">
      <br>
      Current Password:<br>
      <?=$password?><br>
      Enter NEW password:<br>
          <input type="password" name="passwd" size="20">
    <br>
	Re-type password:<br>
    <input type="password" name="passwd2" size="20">
      <br>
      Email:<br>
          <input type="text" name="email" size="40" value="<?=$email?>">
      <br>
    <br>
      <input type="Submit" name="update" value="Update information">
    </p>
    </form>
<?

}
else
{
?>
  <form method="post" action="<?php echo $PHP_SELF?>">
      <p>
    Admin Username:<br>
    <input type="text" size="20" name="name" >
    <br>
    Password:<br>
    <input type="password" name="passwd" size="20">
    <br>
    Re-type password:<br>
    <input type="password" name="passwd2" size="20">
    <br>
    Email:<br>
    <input type="text" name="email" size="20">
    <br>
    <br>
    <input type="Submit" name="submit" value="Enter information">
    </p>
  </form>

<?
}
include "footer.php";
?>
Return current item: PHP Online Invoice System