Location: PHPKode > projects > PHP MySQL Address Book > addressbook/saveusr.php
<?php

require("sesionchk.php");

if(! isset($_SESSION['sectors'])){
    session_start();
include 'library/config.php';
//    $dbConf = new AAConf();
    $databaseURL =$dbhost;// 'localhost';//$dbConf->get_databaseURL();
    $databaseUName = $dbuser;//'root';//$dbConf->get_databaseUName();
    $databasePWord = $dbpass;//'';//$dbConf->get_databasePWord();
    $databaseName = $dbname;// 'addrnew';//$dbConf->get_databaseName();
        
        //Set DB Info. in-session
/*  $_SESSION['databaseURL']=$databaseURL; 
    $_SESSION['databaseUName']=$databaseUName; 
    $_SESSION['databasePWord']=$databasePWord; 
    $_SESSION['databaseName']=$databaseName;
*/
if (trim($_POST[user_id])=="" )
{
require("links.php");
echo "<center> Enter User Name...<br>";
echo "<a href='addedituser.php?ID=-1'>Go Back..</a></center>";
}
else if (trim($_POST[user_password])!=trim($_POST[reuser_password]))
{
require("links.php");
echo "<center>Password Mismatch...<br>";
echo "<a href='addedituser.php?ID=-1'>Go Back..</a></center>";
}
else if (trim($_POST[isEnabled])=="")
{
require("links.php");
echo "<center>Select Enable Or Disable Account..<br>";
echo "<a href='addedituser.php?ID=-1'>Go Back..</a></center>";
}
else if (trim($_POST[usr_level])=="")
{
require("links.php");
echo "<center>Select Userlevel..<br>";
echo "<a href='addedituser.php?ID=-1'>Go Back..</a></center>";
}
else
{
    $connection = mysql_connect($databaseURL,$databaseUName,$databasePWord);
	if (!$connection)
  {
  die('Could not connect: ' . mysql_error());
  }
        // or die ("Error while connecting to localhost");
    $db = mysql_select_db($databaseName,$connection);
       
 if ($_POST[idofusr]<=0)
 {   

$sql="insert into `cal_accounts` (`user`,`pass`,`usr_level`,`addedon`,`isEnabled`) values ('". $_POST[user_id]."','".md5($_POST[user_password].CAL_SQL_PASSWD_SALT)."','".$_POST[usr_level]."','".date("j/n/Y, g:i a")."','".$_POST[isEnabled]."')";
}
else
{

//$sql="UPDATE contacts SET `FirstName`='". $_POST[fullname]."',`EmailAddress`='". $_POST[txtemail]."',`Notes`='". $_POST[notes]."' WHERE id=".$_POST[addrid];
if (trim ($_POST[user_password])!="")
{

$sql="UPDATE cal_accounts SET `pass`='".md5($_POST[user_password].CAL_SQL_PASSWD_SALT)."',`usr_level`=". $_POST[usr_level].",`isEnabled`=". $_POST[isEnabled]." WHERE id=".$_POST[idofusr];
}
else
{
$sql="UPDATE cal_accounts SET `usr_level`=". $_POST[usr_level].",`isEnabled`=". $_POST[isEnabled]." WHERE id=".$_POST[idofusr];
}
}

 


mysql_query("SET NAMES 'utf8'");
mysql_query('SET CHARACTER SET utf8'); 
if (!mysql_query($sql,$connection))
  {
  die('Error: ' . mysql_error());
  }
//echo "1 record added";

 
//echo "<br>".$_GET['a']."<br>";
if ($_POST[idofusr]<=0)
{
$IDD=mysql_insert_id(); 
}
else
{
$IDD=$_POST[idofusr];
}
header('Location: addedituser.php?ID='.$IDD.'&mod=e');
/*
  if ($_GET['a']=='0')
  {
			  if ($_POST[addrid]==0)
			  {
				$IDD=mysql_insert_id(); 
			  }
			  else
			  {
				$IDD=$_POST[addrid];
			  }
   mysql_close($connection);
/*   
echo "<br>IDD = ".$IDD."wen a=".$_GET['a']."<br>";
echo "1 record added don wen get is 0";*/
  /*	header('Location: ./uploader/upload.form.php?ID='.$IDD.'&a='.$_GET['adb']);
  }
  else if ($_GET['a']=='2')
  {
    if ($_POST[addrid]==0)
			  {
				$IDD=mysql_insert_id(); 
			  }
			  else
			  {
				$IDD=$_POST[addrid];
			  }
   mysql_close($connection);
/*   
echo "<br>IDD = ".$IDD."wen a=".$_GET['a']."<br>";
echo "1 record added don wen get is 0";*/
  /*	header('Location: ./dtaildwabraaddressbook.php?ID='.$IDD);
  }
  else
  {
  if ($_POST[addrid]==0)
			  {
				$IDD=mysql_insert_id(); 
			  }
			  else
			  {
				$IDD=$_POST[addrid];
			  }
   mysql_close($connection);
//    echo "1 record added don wen get is 1";
//echo "b4location";
header('Location: ./wabraaddressbook.php?ID='.$IDD);
//echo "aftrlocation";
//	header('Location: alphapaging.php?type=sort&value=A');  
  }*/

		//exit;
/* } */


}
}



?>
Return current item: PHP MySQL Address Book