I apologize for the rather ambiguous subject, but wasn't sure whats the best wording for my issue at hand.
What I am trying to accomplish, is to call all the DB connection variables through a class, but I want my query to be different depending on the page it is on.
Let me put it in context. I am writing this 2 page form that ultimately outputs to a 3rd page. When the first page is submitted, the HTML form data gets passed into variables, which I then place into session variables. However at the same time, I am storing those variables into a table on my MySQL DB.
The user then fills out the fields on the 2nd page, then hits another button, and that either shows an error or gives you a thank you message. However on the backend of it, it stores the data from both page 1 and page 2, and that goes into a separate table on the same DB.
Which because the insert statement I use on page 2 does not contain all the columns I have in my insert statement on page 3, my insert statements are writing a different table, and of course the 2nd table contains more columns.
So, the way I have it right now, is I define the connection variables in a class in an external .inc file like so:
class Database {
public $host = 'myhost.example.com';
public $db = 'mydb';
public $user = 'johndoe';
public $pass = 'mypass';
function mysql() {
$connect = mysql_connect($host, $user, $pass);
if(!$connect) {
die('Error: ' . mysql_error());
}
mysql_select_db($db, $connect);
if(!mysql_query($insert, $connect) {
die('Error: ' . mysql_error());
}
mysql_close();
}
}
So let's say on page two, I write to a table I called request_part_one. So I call my variable insert, and then call my function inside my class.
$insert = "INSERT into request_part_one (fname, lname, campus, aostudy, program) VALUES ($first, $last, $phone, $campus, $aoStudy, $program)";
$database = new Database();
$database->mysql();
And then comes page 3, which data is being passed now from page 1 and 2. But the table I am using for this insert statement is one, a different table, and two, this table has the same data as the first table, but also has the data passed from page 2.
$insert = "INSERT into requests (fname, lname, phone, campus, aostudy, program, email, cell, address, city, state, zip) VALUES ($first, $last, $campus, $phone, $aoStudy, $program, $email, $cell, $address, $city, $state, $zip)";
$database = new Database();
$database->mysql();
So, with that laid out, the problem I having is it is not performing the insert statement. It connects to the database just fine as expected, but it doesn't ever run the query.
Now, one thing I tried doing is created a variable in my .inc file inside the class and changed the conditional to apply to query
public $query;
if(!$query, $connect) {
die('Error: ' . mysql_error());
}
And then assign the value of query to the value of insert on both pages 2 and 3
$database = new Database();
$database->query = $insert;
$database->mysql();
But that didn't seem to make a big difference.
What am I doing wrong here? I'm sure I'm just going about this the wrong way.
Thanks in advance for your help. :queasy: