Hi Im new here and I was wondering if someone could tell me why my class is not working correctly, sorry if its a bit long
<?php
include("database_vars.php");
echo "entered page";
class customer_code {
//var $this;
function customer_code() {
echo "enter function";
mysql_connect($db_location, $db_username, $db_password)
or die("Failure to connect with database");
mysql_select_db("job_control");
/*if($_POST['update_cont'] = 'Update') {
$this->update_contact();
}
elseif($_POST['cont_submit'] = 'Submit') {
$this->insert_contact();
}
elseif($_POST['delete_cont'] = 'Delete') {
$this->delete_contact();
}*/
$customer_id = $_POST['cont_id'];
$update_id = "update_cont" . $customer_id;
$delete_id = "delete_cont" . $customer_id;
if(isset($update_id)) {
$this->update_contact();
echo "going to update function";
}
elseif(isset($_POST['cont_insert'])) {
$this->insert_contact();
}
elseif(isset($delete_id)) {
$this->delete_contact();
}
}
function update_contact() {
$emp_name = $_POST['emp_name'];
$emp_id_query = "SELECT employee.emp_id, emp_name
FROM employee
WHERE employee.emp_name = '$emp_name'";
$emp_id_result = mysql_query($emp_id_query);
$emp_id_array = mysql_fetch_array($emp_id_result);
$comp_id = $_POST['comp_id'];
$cust_name = $_POST['cont_name'];
$cust_title = $_POST['cont_title'];
$cust_resp = $_POST['cont_resp'];
$cust_phone = $_POST['cont_phone'];
$cust_mobile = $_POST['cont_mobile'];
$cust_fax = $_POST['cont_fax'];
$cust_mail = $_POST['cont_mail'];
$emp_id = $emp_id_array[emp_id];
$update_query = "UPDATE customer
SET customer.cust_name='$cust_name', customer.cust_title='$cust_title', customer.cust_resp='$cust_resp', customer.cust_phone='$cust_phone', customer.cust_mobile='$cust_mobile', customer.cust_fax='$cust_fax', customer.cust_mail='$cust_mail', customer.emp_id='$emp_id'
WHERE customer.comp_id = '$comp_id'";
$update_result = mysql_query($update_query);
if(mysql_affected_rows() == 1) {
echo "<p>The customer contact information has been updated</p>";
} else {
error_log(mysql_error());
echo "<p>The information could not be updated: " . mysql_error() . "</p>";
}
echo "<form method='POST' action='customer.php' />";
echo "<input type='hidden name='cust_name' value=\"$cust_name\"";
echo "<meta http-equiv=\"refresh\" url=\"customer.php\" content=\" $cust_name \" />\n";
echo "</form>";
}
function insert_contact() {
$cust_id_query = "SELECT customer.cust_id
FROM customer
ORDER BY customer.cust_id DESC LIMIT 1";
$cust_id_result = mysql_query($cust_id_query);
$cust_id_array = mysql_fetch_array($cust_id_result);
//insert new customer data
//$cust_id = $_POST['cust_id'];
$last_cust = $cust_id_array[cust_id] + 1;
if($last_cust > 9) {
$cust_id = '0' . $last_cust;
} elseif($last_cust > 99) {
$cust_id = $last_cust;
} else {
$cust_id = '00' . $last_cust;
}
$comp_id = $_POST['comp_id'];
$cust_name = $_POST['cust_name'];
$cust_title = $_POST['cust_title'];
$cust_resp = $_POST['cust_resp'];
$cust_phone = $_POST['cust_phone'];
$cust_mobile = $_POST['cust_mobile'];
$cust_fax = $_POST['cust_fax'];
$cust_mail = $_POST['cust_mail'];
$emp_id = $_POST['emp_id'];
$cust_query = "INSERT INTO customer(customer.cust_id, customer.comp_id, customer.cust_name, customer.cust_title, customer.cust_resp, customer.cust_phone, customer.cust_mobile, customer.cust_fax, customer.cust_mail, customer.emp_id)
VALUES('$cust_id', '$comp_id', '$cust_name', '$cust_title', '$cust_resp', '$cust_phone', '$cust_mobile', '$cust_fax', '$cust_mail', '$emp_id')";
$cust_result = mysql_query($cust_query);
if(mysql_affected_rows() == 1) {
echo "<p>The new customer contact has been inserted into the database</p>";
} else {
error_log(mysql_error());
echo "<p>The information could not be entered into the database: " . mysql_error() . "</p>";
}
echo "<meta http-equiv=\"refresh\" url=\"customer.php\" content=\"$cust_name\" />\n";
}
function delete_contact() {
$cust_name = $_POST['cont_name'];
$cust_id = $_POST['cont_id'];
$delete_query = "DELETE FROM customer
WHERE customer.cust_id = '$cust_id'";
$delete_result = mysql_query($delete_query);
echo "<meta http-equiv=\"refresh\" url=\"customer.php\" content=\"$cust_name\" />\n";
}
}
?>