can’t insert form data into mysql table in oops php


i cant add form data to mysql table.i am using oops php to create project checklist and had used session and cookie in it.i can login into the admin but i cant add form data to another table that i have  created in mysql.
form.php

<?
include(“include/session.php”);
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″ />
<title>Mindzpark</title>
<link rel=”stylesheet” href=”css/screen_new.css” type=”text/css” media=”screen” title=”default” />
<!–[if IE]>
<link rel=”stylesheet” media=”all” type=”text/css” href=”css/pro_dropline_ie.css” />
<![endif]–>

<!–  jquery core –>
<script src=”js/jquery/jquery-1.4.1.min.js” type=”text/javascript”></script>

<!–  checkbox styling script –>
<script src=”js/jquery/ui.core.js” type=”text/javascript”></script>
<script src=”js/jquery/ui.checkbox.js” type=”text/javascript”></script>
<script src=”js/jquery/jquery.bind.js” type=”text/javascript”></script>
<script type=”text/javascript”>
$(function(){
$(‘input’).checkBox();
$(‘#toggle-all’).click(function(){
$(‘#toggle-all’).toggleClass(‘toggle-checked’);
$(‘#mainform input[type=checkbox]’).checkBox(‘toggle’);
return false;
});
});
</script>

<![if !IE 7]>

<!–  styled select box script version 1 –>
<script src=”js/jquery/jquery.selectbox-0.5.js” type=”text/javascript”></script>
<script type=”text/javascript”>
$(document).ready(function() {
$(‘.styledselect’).selectbox({ inputClass: “selectbox_styled” });
});
</script>

<![endif]>

<!–  styled select box script version 2 –>
<script src=”js/jquery/jquery.selectbox-0.5_style_2.js” type=”text/javascript”></script>
<script type=”text/javascript”>
$(document).ready(function() {
$(‘.styledselect_form_1’).selectbox({ inputClass: “styledselect_form_1” });
$(‘.styledselect_form_2’).selectbox({ inputClass: “styledselect_form_2″ });
});
</script>

<!–  styled select box script version 3 –>
<script src=”js/jquery/jquery.selectbox-0.5_style_2.js” type=”text/javascript”></script>
<script type=”text/javascript”>
$(document).ready(function() {
$(‘.styledselect_pages’).selectbox({ inputClass: “styledselect_pages” });
});
</script>

<!–  styled file upload script –>
<script src=”js/jquery/jquery.filestyle.js” type=”text/javascript”></script>
<script type=”text/javascript” charset=”utf-8″>
$(function() {
$(“input.file_1”).filestyle({
image: “images/forms/choose-file.gif”,
imageheight : 21,
imagewidth : 78,
width : 310
});
});
</script>

<!– Custom jquery scripts –>
<script src=”js/jquery/custom_jquery.js” type=”text/javascript”></script>

<!– Tooltips –>
<script src=”js/jquery/jquery.tooltip.js” type=”text/javascript”></script>
<script src=”js/jquery/jquery.dimensions.js” type=”text/javascript”></script>
<script type=”text/javascript”>
$(function() {
$(‘a.info-tooltip ‘).tooltip({
track: true,
delay: 0,
fixPNG: true,
showURL: false,
showBody: ” – “,
top: -35,
left: 5
});
});
</script>

<!–  date picker script –>
<link rel=”stylesheet” href=”css/datePicker.css” type=”text/css” />
<script src=”js/jquery/date.js” type=”text/javascript”></script>
<script src=”js/jquery/jquery.datePicker.js” type=”text/javascript”></script>
<script type=”text/javascript” charset=”utf-8″>
$(function()
{

// initialise the “Select date” link
$(‘#date-pick’)
.datePicker(
// associate the link with a date picker
{
createButton:false,
startDate:’01/01/2005′,
endDate:’31/12/2020′
}
).bind(
// when the link is clicked display the date picker
‘click’,
function()
{
updateSelects($(this).dpGetSelected()[0]);
$(this).dpDisplay();
return false;
}
).bind(
// when a date is selected update the SELECTs
‘dateSelected’,
function(e, selectedDate, $td, state)
{
updateSelects(selectedDate);
}
).bind(
‘dpClosed’,
function(e, selected)
{
updateSelects(selected[0]);
}
);

var updateSelects = function (selectedDate)
{
var selectedDate = new Date(selectedDate);
$(‘#d option[value=’ + selectedDate.getDate() + ‘]’).attr(‘selected’, ‘selected’);
$(‘#m option[value=’ + (selectedDate.getMonth()+1) + ‘]’).attr(‘selected’, ‘selected’);
$(‘#y option[value=’ + (selectedDate.getFullYear()) + ‘]’).attr(‘selected’, ‘selected’);
}
// listen for when the selects are changed and update the picker
$(‘#d, #m, #y’)
.bind(
‘change’,
function()
{
var d = new Date(
$(‘#y’).val(),
$(‘#m’).val()-1,
$(‘#d’).val()
);
$(‘#date-pick’).dpSetSelected(d.asString());
}
);

// default the position of the selects to today
var today = new Date();
updateSelects(today.getTime());

// and update the datePicker to reflect it…
$(‘#d’).trigger(‘change’);
});
</script>

<!– MUST BE THE LAST SCRIPT IN <HEAD></HEAD></HEAD> png fix –>
<script src=”js/jquery/jquery.pngFix.pack.js” type=”text/javascript”></script>
<script type=”text/javascript”>
$(document).ready(function(){
$(document).pngFix( );
});
</script>
</head>

<body>
<form action=”process.php” method=”POST”>
<div id=”wrapper”><div style=”background-image:url(images/shared/bg.png);background-repeat: repeat-x;
clear: both;padding-top: 0;position: relative;width:1024px;”>
<!– Start: page-top-outer –>
<div id=”page-top-outer”>

<!– Start: page-top –>
<div id=”page-top”>

<!– start logo –>
<div id=”logo”>
<a href=”index.html”><h1 style=”width:600px; position:absolute;font-size:28px; text-align:center; “> MINDZ PARK</h1></a>
</div>
<!– end logo –>

<!–  start top-search –>
<div id=”top-search”>
<table border=”0″ cellpadding=”0″ cellspacing=”0″>
<tr>
<td><input type=”text” value=”Search” onblur=”if (this.value==”) { this.value=’Search’; }” onfocus=”if (this.value==’Search’) { this.value=”; }” /></td>

<td>
<a href=””><input type=”button” style=”background:url(images/shared/search3.jpg) no-repeat; border: medium none;
cursor: pointer;
display: block;
height: 29px;
text-indent: -3000px;
width: 73px; “/></a>
</td>
</tr>
</table>
</div>
<!–  end top-search –>
<div></div>

</div>
<!– End: page-top –>

</div>
<!– End: page-top-outer –>

<div>&nbsp;</div>

<!–  start nav-outer-repeat……………………………………………………………………………………. START –>
<div>
<!–  start nav-outer –>
<div>

<!– start nav-right –>
<div id=”nav-right”>

<div style=”display:block; padding:6px 50px 0px 0px; font-size:24px; “>
<h1 style=”color: #FFFFFF;font-size:18px;”>Logged in as  &nbsp;&nbsp; Johnson
<b><a href=”logout.php”>Log Out</a></b></h1>
</div>

<div>&nbsp;</div>

</div>

<div>

<ul id=”menu”>

<li><a href=”index.html”><span>Home</span></a></li>
<li><a href=”#”><span>Add Product</span></a></li>
<li><a href=””><span>View Project Details</span></a></li>
</ul>

</div>
<!–  start nav –>

<div></div></div>
<!–  start nav-outer –>
</div>
<!–  start nav-outer-repeat…………………………………………… END –>

<div id=”content-outer” style=”background-color:#F0E8DB;background: url(images/shared/bg.png);background-repeat: repeat scroll;
clear: both;padding-top: 0;position: relative;width:1024px;”>
<!– start content-outer .. …………………………………………………START –>

<div>

<!– main –>
<section id=”main”><h1 style=”text-align:center; “>Add Project Details</h1>

<div>
<section>

<h2 style=”font-size: 22px;line-height: 25px;margin-bottom: 15px;margin-top: 10px;”>Project Name</h2>
<div>
<label style=”margin:0 30px 0 20px”>Project Name <span>*</span></label><input name=”p_name” type=”text” id=”name” value=”” />
<? echo $form->error(“p_name”); ?></div>
<div>
<label style=”margin:0 70px 0 20px”>Duration</label>
<input name=”p_dur” type=”text” id=”p_dur”  value=”” /> <? echo $form->error(“p_dur”); ?>
</div>
<div>
<label style=”margin:0 30px 0 20px”>Description</label>
<textarea name=”p_des” rows=”5″ cols=”20″  id=”p_des” style=”height:100px;
margin:-20px 0px 0px 150px;”></textarea><br /><br /> <? echo $form->error(“p_des”); ?>
</div>
</section>
<section>
<h2 style=”font-size: 22px;line-height: 25px;margin-bottom: 15px;margin-top: 10px;”>FTP</h2>
<div>
<label style=”margin:0 99px 0 20px”>Host</label><input name=”ftp_host” type=”text” id=”name” value=”” /> <? echo $form->error(“ftp_host”); ?>
</div>
<div>
<label style=”margin:0 64px 0 20px”>Username</label>
<input name=”ftp_uname” type=”text” id=”ftp_uname”  value=”” /><span><? echo $form->error(“ftp_uname”); ?></span>
</div>
<div>
<label style=”margin:0 64px 0 20px”>Password</label>
<input name=”ftp_pass” type=”text” id=”ftp_pass”  value=”” /><span><? echo $form->error(“ftp_pass”); ?></span>
</div>
<div>
<label style=”margin:0 30px 0 20px”>Description </label>
<textarea name=”ftp_des” rows=”5″ cols=”20″  id=”ftp_des” style=”height:100px;
margin:-20px 0px 0px 150px;”></textarea><br /><br /><span><? echo $form->error(“ftp_des”); ?></span>
</div>
</section>

</div>

<div>
<section>
<h2 style=”font-size: 22px;line-height: 25px;margin-bottom: 15px;margin-top: 10px;”>Database Name</h2>
<div>
<label style=”margin:0 100px 0 20px”>Host</label><input name=”db_host” type=”text” id=”db_host” value=”” /><span><? echo $form->error(“db_host”); ?></span>
</div>
<div>
<label style=”margin:0 68px 0 20px”>DB name</label>
<input name=”db_name” type=”text” id=”db_name”  value=”” /><span><? echo $form->error(“db_name”); ?></span>
</div>
<div>
<label style=”margin:0 60px 0 20px”>User name</label>
<input name=”db_uname” type=”text” id=”db_uname”  value=”” />
</div>
<div>
<label style=”margin:0 64px 0 20px”>Password</label>
<input name=”db_pass” type=”text” id=”db_pass”  value=”” />
</div>
<div>
<label style=”margin:0 30px 0 20px”>Description</label>
<textarea name=”db_des” rows=”5″ cols=”20″  id=”db_des” style=”height:100px;
margin:-20px 0px 0px 150px;”></textarea><br /><br />
</div>
</section>

<section>
<h2 style=”font-size: 22px;line-height: 25px;margin-bottom: 15px;margin-top: 10px;”>Demo ON</h2>
<div>
<label style=”margin:0 100px 0 20px”>Host</label><input name=”dm_host” type=”text” id=”demo_host” value=”” />
</div>
<div>
<label style=”margin:0 68px 0 20px”>DB name</label>
<input name=”dm_dbname” type=”text” id=”demodb_name”  value=”” />
</div>
<div>
<label style=”margin:0 60px 0 20px”>User name</label>
<input name=”dm_uname” type=”text” id=”demodb_uname”  value=”” />
</div>
<div>
<label style=”margin:0 64px 0 20px”>Password</label>
<input name=”dm_pass” type=”text” id=”demodb_pass”  value=”” />
</div>
<div>
<label style=”margin:0 30px 0 20px”>Description</label>
<textarea name=”dm_des” rows=”5″ cols=”20″  id=”demodb_descp” style=”height:100px;
margin:-20px 0px 0px 150px;”></textarea><br /><br />
</div>
</section>
<section>
<h2 style=”font-size: 22px;line-height: 25px;margin-bottom: 15px;margin-top: 10px;”>Control Panel</h2>
<div>
<label style=”margin:0 58px 0 20px”>User Name</label><input name=”cp_name” type=”text” id=”cp_name” value=”” />
</div>
<div>
<label style=”margin:0 64px 0 20px”>Password</label>
<input name=”cp_pass” type=”text” id=”cp_pass”  value=”” />
</div>
<div>
<label style=”margin:0 30px 0 20px”>Description</label>
<textarea name=”cp_des” rows=”5″ cols=”20″  id=”cp_descp” style=”height:100px;
margin:-20px 0px 0px 150px;”></textarea><br /><br />
</div>
</section>
<section>
<h2 style=”font-size: 22px;line-height: 25px;margin-bottom: 15px;margin-top: 10px;”>WP Admin</h2>
<div>
<label style=”margin:0 58px 0 20px”>User Name</label><input name=”wp_name” type=”text” id=”wp_name” value=”” />
</div>
<div>
<label style=”margin:0 64px 0 20px”>Password</label>
<input name=”wp_pass” type=”text” id=”wp_pass”  value=”” />
</div>
<div>
<label style=”margin:0 30px 0 20px”>Description</label>
<textarea name=”wp_des” rows=”5″ cols=”20″  id=”wp_descp” style=”height:100px;
margin:-20px 0px 0px 150px;”></textarea><br /><br />
</div>
</section>
<section>
<h2 style=”font-size: 22px;line-height: 25px;margin-bottom: 15px;margin-top: 10px;”>Additional 1</h2>
<div>
<label style=”margin:0 58px 0 20px”>User Name</label><input name=”add1_name” type=”text” id=”addt1_name” value=”” />
</div>
<div>
<label style=”margin:0 64px 0 20px”>Password</label>
<input name=”add1_pass” type=”text” id=”addt1_pass”  value=”” />
</div>
<div>
<label style=”margin:0 30px 0 20px”>Description</label>
<textarea name=”add1_des” rows=”5″ cols=”20″  id=”addt1_descp” style=”height:100px;
margin:-20px 0px 0px 150px;”></textarea><br /><br />
</div>
</section>
<section>
<h2 style=”font-size: 22px;line-height: 25px;margin-bottom: 15px;margin-top: 10px;”>Additional 2</h2>
<div>
<label style=”margin:0 58px 0 20px”>User Name</label><input name=”add2_name” type=”text” id=”addt2_name” value=”” />
</div>
<div>
<label style=”margin:0 64px 0 20px”>Password</label>
<input name=”add2_pass” type=”text” id=”addt2_pass”  value=”” />
</div>
<div>
<label style=”margin:0 30px 0 20px”>Description</label>
<textarea name=”add2_des” rows=”5″ cols=”20″  id=”addt2_descp” style=”height:100px;
margin:-20px 0px 0px 150px;”></textarea><br /><br />
</div>
</section>
<section>
<h2 style=”font-size: 22px;line-height: 25px;margin-bottom: 15px;margin-top: 10px;”>Additional 3</h2>
<div>
<label style=”margin:0 87px 0 20px”>Data 1</label><input name=”add3_d1″ type=”text” id=”addt3_d1″ value=”” />
</div>
<div>
<label style=”margin:0 82px 0 20px”>Data 2</label>
<input name=”add3_d2″ type=”text” id=”addt3_d2″  value=”” />
</div>
<div>
<label style=”margin:0 82px 0 20px”>Data 2</label>
<input name=”add3_d3″ type=”text” id=”addt3_d2″  value=”” />
</div>
<div>
<label style=”margin:0 30px 0 20px”>Data 3</label>
<textarea name=”add3_des” rows=”5″ cols=”20″  id=”addt3_d3″ style=”height:100px;
margin:-20px 0px 0px 150px;”></textarea><br /><br />
</div>
</section>

</div>
<div style=”text-align:center;”>
<input type=”submit”  value=”Submit” name=”sub” />
<input type=”reset” value=”Reset”/>
</form>
</div>

</section>

</div>
</div>

</div></div>
<!– start footer –>
<div id=”footer”>
<!–  start footer-left –>
<div id=”footer-left”>

rights reserved.</div>
<!–  end footer-left –>
<div>&nbsp;</div>
</div>
<!– end footer –>

</body>
</html>

process.php
<html>
<body>
<?
/**
* Process.php
*
* The Process class is meant to simplify the task of processing
* user submitted forms, redirecting the user to the correct
* pages if errors are found, or if form is successful, either
* way. Also handles the logout procedure.
*
* Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
* Last Updated: August 19, 2004
*/
include(“include/session.php”);

class Process
{
/* Class constructor */
function Process(){
global $session;
/* User submitted login form */
if(isset($_POST[‘sublogin’])){
$this->procLogin();
}
else if(isset($_POST[‘subjoin’])){
$this->procRegister();
}
elseif(isset($_POST[‘sub’]))
{
$this->proadd();

}
else{
header(“Location: form_new.php”);
}
}

/**
* procLogin – Processes the user submitted login form, if errors
* are found, the user is redirected to correct the information,
* if not, the user is effectively logged in to the system.
*/
function procLogin(){
global $session, $form;
/* Login attempt */
$retval = $session->login($_POST[‘user’], $_POST[‘pass’], isset($_POST[‘remember’]));

/* Login successful */
if($retval){
header(“Location:index.php”);
}
/* Login failed */
else{
$_SESSION[‘value_array’] = $_POST;
$_SESSION[‘error_array’] = $form->getErrorArray();
echo”failed”;
header(“Location:main.php “);
//header(“Location: “.$session->referrer);
}
}
function proadd()
{
global $session, $form;

$retval = $session->proreg($_POST[‘p_name’],$_POST[‘p_dur’],$_POST[‘p_des’],$_POST[‘ftp_host’],$_POST[‘ftp_uname’],

$_POST[‘ftp_pass’],$_POST[‘ftp_des’],$_POST[‘db_host’],
$_POST[‘db_name’],$_POST[‘db_uname’],$_POST[‘db_pass’],$_POST[‘db_des’],$_POST[‘dm_host’],$_POST[‘dm_dbname’],$_POST[‘dm_uname’],$_POST[‘dm_pass’],$_POST[‘dm_des’],

$_POST[‘cp_name’],$_POST[‘cp_pass’],$_POST[‘cp_des’],$_POST[‘wp_name’],$_POST[‘wp_pass’],$_POST[‘wp_des’],$_POST[‘add1_name’],$_POST[‘add1_pass’],$_POST[‘add1_des’],

$_POST[‘add2_name’],$_POST[‘add2_pass’],$_POST[‘add2_des’],$_POST[‘add3_d1’],$_POST[‘add3_d2’],$_POST[‘add3_d3’],$_POST[‘add3_des’]);
if($retval == 0){
$_SESSION[‘reguname’] = $_POST[‘p_name’];
$_SESSION[‘regsuccess’] = true;
echo”successful added”;
/* header(“Location:form_new.php “);*/
}
/* Error found with form
else if($retval == 1){
$_SESSION[‘value_array’] = $_POST;
$_SESSION[‘error_array’] = $form->getErrorArray();
header(“Location:form_new.php”);
}
/* Registration attempt failed
else if($retval == 2){
$_SESSION[‘p_name’] = $_POST[‘p_name’];
$_SESSION[‘regsuccess’] = false;
header(“Location:form_new.php”);
}*/

else
{
echo ‘failure in process.php’;
header(“Location:main.php “);

}
}
/**
* procRegister – Processes the user submitted registration form,
* if errors are found, the user is redirected to correct the
* information, if not, the user is effectively registered with
* the system and an email is (optionally) sent to the newly
* created user.
*/
function procRegister(){
global $session, $form;
/* Convert username to all lowercase (by option) */
if(ALL_LOWERCASE){
$_POST[‘user’] = strtolower($_POST[‘user’]);
}
/* Registration attempt */
$retval = $session->register($_POST[‘user’], $_POST[‘pass’], $_POST[’email’]);

/* Registration Successful */
if($retval == 0){
$_SESSION[‘reguname’] = $_POST[‘user’];
$_SESSION[‘regsuccess’] = true;
echo”successful”;
header(“Location:register.php “);
}
/* Error found with form */
else if($retval == 1){
$_SESSION[‘value_array’] = $_POST;
$_SESSION[‘error_array’] = $form->getErrorArray();
header(“Location:register.php”);
}
/* Registration attempt failed */
else if($retval == 2){
$_SESSION[‘reguname’] = $_POST[‘user’];
$_SESSION[‘regsuccess’] = false;
header(“Location:register.php”);
}
}
/**
* procLogout – Simply attempts to log the user out of the system
* given that there is no logout form to process.
*/
function procLogout(){
global $session;
$retval = $session->logout();
header(“Location: main.php”);

}

};

/* Initialize process */
$process = new Process;

?>
</body>
</html>

constant.php
<?
define(“DB_SERVER”, “localhost”);
define(“DB_USER”, “pramodh”);
define(“DB_PASS”, “”);
define(“DB_NAME”, “pramodh”);

/**
* Database Table Constants – these constants
* hold the names of all the database tables used
* in the script.
*/
define(“TBL_USERS”, “users”);
define(“TBL_checklst”, “checklist”);
define(“ADMIN_NAME”, “admin”);
define(“GUEST_NAME”, “Guest”);
define(“ADMIN_LEVEL”, 5);
define(“USER_LEVEL”,  1);
define(“GUEST_LEVEL”, 0);

define(“TRACK_VISITORS”, true);

define(“USER_TIMEOUT”, 10);
define(“GUEST_TIMEOUT”, 5);

define(“COOKIE_EXPIRE”, 60*60*24*100);  //100 days by default
define(“COOKIE_PATH”, “/”);

?>

constant.php
<?
include(“constants.php”);

class MySQLDB
{
var $connection;         //The MySQL database connection
var $num_active_users;   //Number of active users viewing site

/* Class constructor */
function MySQLDB(){
/* Make connection to database */
$this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());

/**
* Only query database to find out number of members
* when getNumMembers() is called for the first time,
* until then, default value set.
*/
$this->num_members = -1;

}

/**
* confirmUserPass – Checks whether or not the given
* username is in the database, if so it checks if the
* given password is the same password in the database
* for that user. If the user doesn’t exist or if the
* passwords don’t match up, it returns an error code
* (1 or 2). On success it returns 0.
*/
function confirmUserPass($username, $password){
/* Add slashes if necessary (for query) */
if(!get_magic_quotes_gpc()) {
$username = addslashes($username);
}

/* Verify that user is in database */
$q = “SELECT password FROM “.TBL_USERS.” WHERE username = ‘$username'”;
$result = mysql_query($q, $this->connection);
if(!$result || (mysql_numrows($result) < 1)){
return 1; //Indicates username failure
}

/* Retrieve password from result, strip slashes */
$dbarray = mysql_fetch_array($result);
$dbarray[‘password’] = stripslashes($dbarray[‘password’]);
$password = stripslashes($password);

/* Validate that password is correct */
if($password == $dbarray[‘password’]){
return 0; //Success! Username and password confirmed
}
else{
return 2; //Indicates password failure
}
}

/**
* confirmUserID – Checks whether or not the given
* username is in the database, if so it checks if the
* given userid is the same userid in the database
* for that user. If the user doesn’t exist or if the
* userids don’t match up, it returns an error code
* (1 or 2). On success it returns 0.
*/
function confirmUserID($username, $userid){
/* Add slashes if necessary (for query) */
if(!get_magic_quotes_gpc()) {
$username = addslashes($username);
}

/* Verify that user is in database */
$q = “SELECT userid FROM “.TBL_USERS.” WHERE username = ‘$username'”;
$result = mysql_query($q, $this->connection);
if(!$result || (mysql_numrows($result) < 1)){
return 1; //Indicates username failure
}

/* Retrieve userid from result, strip slashes */
$dbarray = mysql_fetch_array($result);
$dbarray[‘userid’] = stripslashes($dbarray[‘userid’]);
$userid = stripslashes($userid);

/* Validate that userid is correct */
if($userid == $dbarray[‘userid’]){
return 0; //Success! Username and userid confirmed
}
else{
return 2; //Indicates userid invalid
}
}

/**
* usernameTaken – Returns true if the username has
* been taken by another user, false otherwise.
*/
function usernameTaken($username){
if(!get_magic_quotes_gpc()){
$username = addslashes($username);
}
$q = “SELECT username FROM “.TBL_USERS.” WHERE username = ‘$username'”;
$result = mysql_query($q, $this->connection);
return (mysql_numrows($result) > 0);
}

function updateUserField($username, $field, $value){
$q = “UPDATE “.TBL_USERS.” SET “.$field.” = ‘$value’ WHERE username = ‘$username'”;
return mysql_query($q, $this->connection);
}
/**
* addNewUser – Inserts the given (username, password, email)
* info into the database. Appropriate user level is set.
* Returns true on success, false otherwise.
*/
function addNewUser($username, $password, $email){
$time = time();
/* If admin sign up, give admin user level */
if(strcasecmp($username, ADMIN_NAME) == 0){
$ulevel = ADMIN_LEVEL;
}else{
$ulevel = USER_LEVEL;
}
$q = “INSERT INTO “.TBL_USERS.”(username,password,userlevel,email,timestamp) VALUES (‘$username’, ‘$password’, $ulevel, ‘$email’, $time)”;
return mysql_query($q, $this->connection);
}
function addproject($pname,$pdur,$pdes,$ftphost,$ftpname,$ftppass,$ftpdes,$dbhost,$dbname,$dbuname,$dbpass,$dbdes,$dmhost,$dmdbname,$dmuname,

$dmpass,$dmdes,$cpname,$cppass,$cpdes,$wpname,$wppass,$wpdes,$add1name,$add1pass,$add1des,$add2name,$add2pass,$add2des,$add3d1,$add3d2,$add3d3,$add3des)
{

if($pname==1)
{
$q =”INSERT INTO “.TBL_checklst.”(P_Name,p_Duration,p_Des,ftp_Host,ftp_Uname,ftp_Pass,ftp_Des,db_Host,db_Name,db_Uname,db_Pass,db_Des,cp_Uname,cp_Pass,cp_Des

,dm_Host,dm_DBname,dm_Uname,dm_Pass,dm_Des,wp_Uname,wp_Pass,wp_Des,ad1_Uname,ad1_Pass,ad1_Des,ad2_Data1,ad2_Data2,ad2_Data3,ad2_Des,ad3_Uname,ad3_Pass,ad3_Des)
VALUES (‘$pname’,’$pdur’,’$pdes’,’$ftphost’,’$ftpname’,’$ftppass’,’$ftpdes’,’$dbhost’,’$dbname’,’$dbuname’,’$dbpass’,’$dbdes’,

$dmhost,’$dmdbname’,’$dmuname’,’$dmpass’,’$dmdes’,’$cpname’,’$cppass’,’$cpdes’,’$wpname’,’$wppass’,’$wpdes’,’$add1name’,’$add1pass’,’$add1des’,’$add2name’,’$add2pass’,’$add2des’,’$add3d1′,’$add3d2′,’$add3d3′,’$add3des’)”;

return mysql_query($q);
}
else{

echo”failed in database”;
}

}

/**
* getUserInfo – Returns the result array from a mysql
* query asking for all information stored regarding
* the given username. If query fails, NULL is returned.
*/
function getUserInfo($username){
$q = “SELECT * FROM “.TBL_USERS.” WHERE username = ‘$username'”;
$result = mysql_query($q, $this->connection);
/* Error occurred, return given name by default */
if(!$result || (mysql_numrows($result) < 1)){
return NULL;
}
/* Return result array */
$dbarray = mysql_fetch_array($result);
return $dbarray;
}

/**
* getNumMembers – Returns the number of signed-up users
* of the website, banned members not included. The first
* time the function is called on page load, the database
* is queried, on subsequent calls, the stored result
* is returned. This is to improve efficiency, effectively
* not querying the database when no call is made.
*/
function getNumMembers(){
if($this->num_members < 0){
$q = “SELECT * FROM “.TBL_USERS;
$result = mysql_query($q, $this->connection);
$this->num_members = mysql_numrows($result);
}
return $this->num_members;
}

/**
* calcNumActiveUsers – Finds out how many active users
* are viewing site and sets class variable accordingly.
*/

function query($query){
return mysql_query($query, $this->connection);
}

};

/* Create database connection */
$database = new MySQLDB;

?>

session.php

<?
include(“database.php”);
include(“form.php”);
class Session
{

var $username;     //Username given on sign-up
var $userid;       //Random value generated on current login
var $userlevel;    //The level to which the user pertains
var $referrer;
function Session(){
$this->time = time();
$this->startSession();
}

/**
* startSession – Performs all the actions necessary to
* initialize this session object. Tries to determine if the
* the user has logged in already, and sets the variables
* accordingly. Also takes advantage of this page load to
* update the active visitors tables.
*/
function startSession(){
global $database;  //The database connection
session_start();   //Tell PHP to start the session

/* Determine if user is logged in */
$this->logged_in = $this->checkLogin();

}

/**
* checkLogin – Checks if the user has already previously
* logged in, and a session with the user has already been
* established. Also checks to see if user has been remembered.
* If so, the database is queried to make sure of the user’s
* authenticity. Returns true if the user has logged in.
*/
function checkLogin(){
global $database;  //The database connection
/* Check if user has been remembered */
if(isset($_COOKIE[‘cookname’]) && isset($_COOKIE[‘cookid’])){
$this->username = $_SESSION[‘username’] = $_COOKIE[‘cookname’];
$this->userid   = $_SESSION[‘userid’]   = $_COOKIE[‘cookid’];
}

/* Username and userid have been set and not guest */
if(isset($_SESSION[‘username’]) && isset($_SESSION[‘userid’])){
/* Confirm that username and userid are valid */
if($database->confirmUserID($_SESSION[‘username’], $_SESSION[‘userid’]) != 0){
/* Variables are incorrect, user not logged in */
unset($_SESSION[‘username’]);
unset($_SESSION[‘userid’]);
return false;
}

/* User is logged in, set class variables */

$this->username  = $this->userinfo[‘username’];
$this->userid    = $this->userinfo[‘userid’];
$this->userlevel = $this->userinfo[‘userlevel’];
return true;
}
/* User not logged in */
else{
return false;
}
}

/**
* login – The user has submitted his username and password
* through the login form, this function checks the authenticity
* of that information in the database and creates the session.
* Effectively logging in the user if all goes well.
*/
function login($subuser, $subpass, $subremember){
global $database, $form;  //The database and form object

/* Username error checking */
$field = “user”;  //Use field name for username
if(!$subuser || strlen($subuser = trim($subuser)) == 0){
$form->setError($field, “* Username not entered”);
}
else{
/* Check if username is not alphanumeric */
if(!eregi(“^([0-9a-z])*$”, $subuser)){
$form->setError($field, “* Username not alphanumeric”);
}
}

/* Password error checking */
$field = “pass”;  //Use field name for password
if(!$subpass){
$form->setError($field, “* Password not entered”);
}

/* Return if form errors exist */
if($form->num_errors > 0){
return false;
}

/* Checks that username is in database and password is correct */
$subuser = stripslashes($subuser);
$result = $database->confirmUserPass($subuser, md5($subpass));

/* Check error codes */
if($result == 1){
$field = “user”;
$form->setError($field, “* Username not found”);
}
else if($result == 2){
$field = “pass”;
$form->setError($field, “* Invalid password”);
}

/* Return if form errors exist */
if($form->num_errors > 0){
return false;
}

/* Username and password correct, register session variables */
$this->userinfo  = $database->getUserInfo($subuser);
$this->username  = $_SESSION[‘username’] = $this->userinfo[‘username’];
$this->userlevel = $this->userinfo[‘userlevel’];

/**
* This is the cool part: the user has requested that we remember that
* he’s logged in, so we set two cookies. One to hold his username,
* and one to hold his random value userid. It expires by the time
* specified in constants.php. Now, next time he comes to our site, we will
* log him in automatically, but only if he didn’t log out before he left.
*/
if($subremember){
setcookie(“cookname”, $this->username, time()+COOKIE_EXPIRE, COOKIE_PATH);
setcookie(“cookid”,   $this->userid,   time()+COOKIE_EXPIRE, COOKIE_PATH);
}

/* Login completed successfully */
return true;
}

/**
* logout – Gets called when the user wants to be logged out of the
* website. It deletes any cookies that were stored on the users
* computer as a result of him wanting to be remembered, and also
* unsets session variables and demotes his user level to guest.
*/
function logout(){
global $database;  //The database connection
/**
* Delete cookies – the time must be in the past,
* so just negate what you added when creating the
* cookie.
*/
if(isset($_COOKIE[‘cookname’]) && isset($_COOKIE[‘cookid’])){
setcookie(“cookname”, “”, time()-COOKIE_EXPIRE, COOKIE_PATH);
setcookie(“cookid”,   “”, time()-COOKIE_EXPIRE, COOKIE_PATH);
}

/* Unset PHP session variables */
unset($_SESSION[‘username’]);
unset($_SESSION[‘userid’]);

/* Reflect fact that user has logged out */
$this->logged_in = false;
}

/**
* isAdmin – Returns true if currently logged in user is
* an administrator, false otherwise.
*/
function isAdmin(){
return ($this->userlevel == ADMIN_LEVEL ||
$this->username  == ADMIN_NAME);
}

function proreg($pname,$pdur,$pdes,$ftphost,$ftpname,$ftppass,$ftpdes,$dbhost,$dbname,$dbuname,$dbpass,$dbdes,$dmhost,$dmdbname,$dmuname,$dmpass,$dmdes,$cpname,$cppass,$cpdes,$wpname,$wppass,$wpdes,$add1name,$add1pass,$add1des,$add2name,$add2pass,$add2des,$add3d1,$add3d2,$add3d3,$add3des)
{
global $database,$form;
echo “$pname”;
if($database->addproject($pname,$pdur,$pdes,$ftphost,$ftpname,$ftppass,$ftpdes,$dbhost,$dbname,$dbuname,$dbpass,$dbdes,$dmhost,$dmdbname,$dmuname,$dmpass,$dmdes,$cpname,$cppass,$cpdes,$wpname,$wppass,$wpdes,$add1name,$add1pass,$add1des,$add2name,$add2pass,$add2des,$add3d1,$add3d2,$add3d3,$add3des))
{
echo ‘sucessfully in session’;
}
//New user added succesfully

else{
echo”Registration Failure in session”;  //Registration attempt failed
}
}

/*
function proreg($pname,$pdur,$pdes,$ftphost,$ftpname,$ftppass,$ftpdes,$dbhost,$dbname,$dbuname,$dbpass,$dbdes,$dmhost,$dmdbname,$dmuname,$dmpass,$dmdes,$cpname,$cppass,$cpdes,$wpname,$wppass,$wpdes,$add1name,$add1pass,$add1des,$add2name,$add2pass,$add2des,$add3d1,$add3d2,$add3d3,$add3des)
{
global $database, $form;
if($form->num_errors > 0){
return false;  //Errors with form
}

/* Update password since there were no errors

if($database->addproject($pname,$pdur,$pdes,$ftphost,$ftpname,$ftppass,$ftpdes,$dbhost,$dbname,$dbuname,$dbpass,$dbdes,$dmhost,$dmdbname,$dmuname,$dmpass,$dmdes,$cpname,$cppass,$cpdes,$wpname,$wppass,$wpdes,$add1name,$add1pass,$add1des,$add2name,$add2pass,$add2des,$add3d1,$add3d2,$add3d3,$add3des))
{
echo”success”;
}

return true;
}*/

function register($subuser, $subpass, $subemail){
global $database, $form, $mailer;  //The database, form and mailer object

/* Username error checking */
$field = “user”;  //Use field name for username
if(!$subuser || strlen($subuser = trim($subuser)) == 0){
$form->setError($field, “* Username not entered”);
}
else{
/* Spruce up username, check length */
$subuser = stripslashes($subuser);
if(strlen($subuser) < 5){
$form->setError($field, “* Username below 5 characters”);
}
else if(strlen($subuser) > 30){
$form->setError($field, “* Username above 30 characters”);
}
/* Check if username is not alphanumeric */
else if(!eregi(“^([0-9a-z])+$”, $subuser)){
$form->setError($field, “* Username not alphanumeric”);
}
/* Check if username is reserved */

/* Check if username is already in use */
else if($database->usernameTaken($subuser)){
$form->setError($field, “* Username already in use”);
}

}

/* Password error checking */
$field = “pass”;  //Use field name for password
if(!$subpass){
$form->setError($field, “* Password not entered”);
}
else{
/* Spruce up password and check length*/
$subpass = stripslashes($subpass);
if(strlen($subpass) < 4){
$form->setError($field, “* Password too short”);
}
/* Check if password is not alphanumeric */
else if(!eregi(“^([0-9a-z])+$”, ($subpass = trim($subpass)))){
$form->setError($field, “* Password not alphanumeric”);
}
/**
* Note: I trimmed the password only after I checked the length
* because if you fill the password field up with spaces
* it looks like a lot more characters than 4, so it looks
* kind of stupid to report “password too short”.
*/
}

/* Email error checking */
$field = “email”;  //Use field name for email
if(!$subemail || strlen($subemail = trim($subemail)) == 0){
$form->setError($field, “* Email not entered”);
}
else{
/* Check if valid email address */
$regex = “^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*”
.”@[a-z0-9-]+(\.[a-z0-9-]{1,})*”
.”\.([a-z]{2,}){1}$”;
if(!eregi($regex,$subemail)){
$form->setError($field, “* Email invalid”);
}
$subemail = stripslashes($subemail);
}

/* Errors exist, have user correct them */
if($form->num_errors > 0){
return 1;  //Errors with form
}
/* No errors, add the new account to the */
else{
if($database->addNewUser($subuser, md5($subpass), $subemail)){
echo”added successfully”;  //New user added succesfully
}else{
echo”Registration Failure”;  //Registration attempt failed
}
}

}
};
/**
* Initialize session object – This must be initialized before
* the form object because the form uses session variables,
* which cannot be accessed unless the session has started.
*/
$session = new Session;

/* Initialize form object */
$form = new Form;

?>

Advertisements
About

myself pramodh kumar yet another php developer from India and have worked on oops,procedural,yii framework,codeigniter,wordpress,joomla,api and more.

Tagged with: , , , , , , , , , , ,
Posted in can't insert form data into mysql table in oops php

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow php tutorial on WordPress.com
categories
Calendar
July 2012
M T W T F S S
« Jun   Sep »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
Follow me on Twitter
Blog Stats
  • 72,886 hits
%d bloggers like this: