I have just started learning php with no programming background except for HTML which I know quite well and need some help with a project I am trying to do...
The application has a login screen with a register option if not registered with a user_profile table for users. Other tables in the database will be companies, insurance companies, insurance brokers, vehicles, drivers, contacts, all in relation with each other to name a few.
The first page "index.php" contains two HTML forms of which one's FORM ACTION is login.php and the other's is regist.php if a new user does not have an account yet and needs to register. regist.php contains a form with text boxes and submit/reset buttons and the form action is data.php which in turn adds the new user's details in the database.
This all works perfect but inside the application a user will be able to add new customers, vehicles ect and this is where I am totally stuck.
I am trying to get all sql queries that insert or update data in the different tables in one file named data.php so in other words the the form action of broker_add.php customer_add.php, vehicle_add.php, contact_add.php and so forth will be data.php
I will post some of the code for data.php and then explain my problem:
The first bit is just to check that the two password fields is the same from regist.php and the connection to mysql:
<?
require 'functions.php';
if($password != $password1){
// if both passwords not the same then generate err msg
header("Location:[url]http://[/url]$http_host/$db_docroot/passwderror.html");
exit();
}else{
// Open persistant connection
if(!($link = mysql_pconnect($db_server, $db_login, $db_passwd))) {
DisplayErrMsg (sprintf("internal error %d:%s\n",
mysql_errno(), mysql_error()));
return 0;
exit();
}
The next couple of lines is for registring of new user:
// create user record
if (!($newresult = mysql_db_query($db, "INSERT INTO user_profile
(name, first_name, last_name, password, cell_no, email)
VALUES
('$user', '$first_name', '$last_name', '$password', '$cell_no', '$email')"))) {
DisplayErrMsg(sprintf("internal error %d:%s\n",
mysql_errno(), mysql_error()));
exit();
}
// if registration successfull then display else err msg
header("Location:[url]http://[/url]$http_host/$db_docroot/success.html");
exit();
}
The next bit is to add a new user from within the application by someone who has administrative rights. There is a extra variable, $levels, of which the value in it is determined by the the swicth statement and all the original values comes from user_add.php and this is where I have my first problem.
It tries to add the data to the table but without anything in the fields - just creates a empty row.
// This is to add a new user by an administrator and set their user level
//Switch statement for user levels
switch ($levels){
case "a":
$levels = "1";
break;
case "s":
$levels = "2";
break;
case "u":
$levels = "3";
break;
case "k":
$levels = "4";
break;
}
// Add user record - help needed here
if (!($newresult = mysql_db_query($db, "INSERT INTO user_profile
(name, first_name, last_name, password, cell_no, email, user_level)
VALUES
('$user1', '$first_name1', '$last_name1', '$password1', '$cell_no1', '$email1', $levels)"))) {
DisplayErrMsg(sprintf("internal error %d:%s\n",
mysql_errno(), mysql_error()));
exit();
}
I have the same problem with the next block of code:
// Add new insurance broker details
if (!($newresult = mysql_db_query($db, "INSERT INTO brokers
(broker_first_name, broker_last_name, broker_phone1, broker_phone2, broker_fax, broker_email, broker_address1, broker_address2, broker_city, broker_province, broker_postal_code)
VALUES
('$broker_first_name', '$broker_last_name', '$broker_phone1', '$broker_phone2', '$broker_fax', '$broker_email', '$broker_address1', '$broker_address2', '$broker_city', '$broker_province', $broker_postal_code)"))) {
DisplayErrMsg(sprintf("internal error %d:%s\n",
mysql_errno(), mysql_error()));
exit();
}
header("Location:[url]http://[/url]$http_host/$db_docroot/main.php");
exit();
The above code also adds a empty row in user_profile table and it should add the data in the brokers table and when the code is finished it takes you to success.html which should be where you are going if you have successfully registered
I want to avoid having tons of small files each doing it's own little job which currently is the only way I can solve this. Can anyone suggest/show me what to do or the best way to do it. Remember I have just started and needs to be explained carefull to me