PDA

View Full Version : Using the Login ID to update Database?


cdavenport4
05-22-2007, 05:06 PM
I want to be able to use the ID from the login screen to update client information database based on that id. I know that I can get the ID to pass from page to page but I'm trying to modify the Tutorial #11 in the PHP Basics to do this.

Any suggestions? :)

davidj
05-23-2007, 08:34 AM
the ID should be held in a session and should be available in any page

please give more details of what your wanting to do

cdavenport4
05-29-2007, 03:07 PM
Sorry for the delay in replying to your response.... I'm trying to take the $id = general_id in the database. Which I believe I have done. My real problem is this....

I need to have the submit button do an update if the general_id does exist if not add the record which includes the $id.


require_once("connection.php"); //Database Connection
include("Security.php");

session_start();

$id = $_SESSION['id'];

//////////////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM users WHERE user_id = '$id'");
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
/////////////////////////////////////////////////////////////

//////////////////////////////////////////////////
$generalid = $_POST['general_id'];
$dealership = $_POST['dealership'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
//$phone = $_POST['phone'];
$pattern = '/^\(?\d{3}\)? \d{3}-\d{4}$/';
$phone = trim($_POST['phone']);
$website = $_POST['website'];
$fax = $_POST['fax'];
$pricont = $_POST['pricont'];
$prititle = $_POST['prititle'];
$priphone = $_POST['priphone'];
$priemail = $_POST['priemail'];
$sales = $_POST['sales'];
$saletitle = $_POST['saletitle'];
$salephone = $_POST['salephone'];
$saleemail = $_POST['saleemail'];
$it = $_POST['it'];
$ittitle = $_POST['ittitle'];
$itphone = $_POST['itphone'];
$itemail = $_POST['itemail'];
$gmmotors = $_POST['gmmotors'];
$toyotamotor = $_POST['toyotamotor'];
$fordmotor = $_POST['fordmotor'];
$volkswagen = $_POST['volkswagen'];
$daimierchry = $_POST['daimierchry'];
$honda = $_POST['honda'];
$nissan = $_POST['nissan'];
$hyundaimotor = $_POST['hyundaimotor'];
$mitsubishi = $_POST['mitsubishi'];
$bmwgroup = $_POST['bmwgroup'];
$salesmgr1 = $_POST['salesmgr1'];
$admin1 = $_POST['admin1'];
$salesmgr2 = $_POST['salesmgr2'];
$admin2 = $_POST['admin2'];
$salesmgr3 = $_POST['salesmgr3'];
$admin3 = $_POST['admin3'];
$salesmgr4 = $_POST['salesmgr4'];
$admin4 = $_POST['admin4'];
$salesmgr5 = $_POST['salesmgr5'];
$admin5 = $_POST['admin5'];
$salesmgr6 = $_POST['salesmgr6'];
$admin6 = $_POST['admin6'];
$salesmgr7 = $_POST['salesmgr7'];
$admin7 = $_POST['admin7'];
$salesmgr8 = $_POST['salesmgr8'];
$admin8 = $_POST['admin8'];
$vehicles1 = implode(",", $gmmotors);
$vehicles2 = implode(",", $toyotamotor);
$vehicles3 = implode(",", $fordmotor);
$vehicles4 = implode(",", $volkswagen);
$vehicles5 = implode(",", $daimierchry);
$vehicles6 = implode(",", $honda);
$vehicles7 = implode(",", $nissan);
$vehicles8 = implode(",", $hyundaimotor);
$vehicles9 = implode(",", $mitsubishi);
$vehicles10 = implode(",", $bmwgroup);
$preview = $_POST['button'];
$submitted = $_POST['submit'];
$missing = array();
$verify_value = $HTTP_GET_VARS['verify'];
$upd = $_GET['upd'];
$update_id = $_POST['update_id'];

//////////////////////////////////////////////////
$query1 = sprintf("SELECT * FROM dealershipinfo general_id = '$upd' ");
$result1 = @mysql_query($query1);
$rowUpdate = mysql_fetch_array($result1);
//////////////////////////////////////////////////

//////////////////////////////////////////////////
$to = 'cdavenport4@mac.com';
$from = 'cdavenport4@mac.com';
$message ='Profile Information';

$headers = 'MIME-Version: 1.0\n';
$headers .= 'Content-type: text/html; charset=iso-8859-1\n';

$headers .= 'To: '.$to.' \n';
$headers .= 'From: '.$from.' \n';
$subject = 'General Information Profile has been filled out';
//////////////////////////////////////////////////

$generalid = $id

if ($dealership == null && $submitted && ! $update_id) { //*****Changed*****//
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#CC0000\"><font color=\"#FFFFFF\">Dealership Field is empty!</font></td></tr></table>";
}

if ($address == null && $submitted && $update_id) {
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#CC0000\"><font color=\"#FFFFFF\">address Field is empty!</font></td></tr></table>";
}

if ($city == null && $submitted) {
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#CC0000\"><font color=\"#FFFFFF\">city Field is empty!</font></td></tr></table>";
}

if ($state == null && $submitted) {
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#CC0000\"><font color=\"#FFFFFF\">state Field is empty!</font></td></tr></table>";
}

if ($zip == null && $submitted) {
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#CC0000\"><font color=\"#FFFFFF\">zip Field is empty!</font></td></tr></table>";
}


----- Code Continued below -----


if ($admin1 == null && $submitted) {
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#CC0000\"><font color=\"#FFFFFF\">You need at least one Administrator of ePencil</font></td></tr></table>";

}

if ($submitted) {

//*****Update Record*****//
////////////////////////////////////////////////////
$query = sprintf("UPDATE dealershipinfo SET dealership='$dealership', address='$address', city='$city', state='$state', zip='$zip', phone='$phone', website='$website', fax='$fax' WHERE general_id = '$upd'");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#F7941C\"><font color=\"#000000\">Thank You! Your Information has been Updated!.</font></td></tr></table>";
////////////////////////////////////////////////////

} elseif ($submitted) {

//*****Create Record*****//
////////////////////////////////////////////////////
$query5 = sprintf("INSERT INTO dealershipinfo (dealership, address, city, state, zip, phone, website, fax, pricont, prititle, priphone, priemail, sales, saletitle, salephone, saleemail, it, ittitle, itphone, itemail, gmmotors, toyotamotor, fordmotor, volkswagen, daimierchry, honda, nissan, hyundaimotor, mitsubishi, bmwgroup, salesmgr1, admin1, salesmgr2, admin2, salesmgr3, admin3, salesmgr4, admin4, salesmgr5, admin5, salesmgr6, admin6, salesmgr7, admin7, salesmgr8, admin8) VALUES ('$dealership', '$address', '$city', '$state', '$zip', '$phone', '$website', '$fax', '$pricont', '$prititle', '$priphone', '$priemail', '$sales', '$saletitle', '$salephone', '$saleemail', '$it', '$ittitle', '$itphone', '$itemail', '$vehicles1', '$vehicles2', '$vehicles3', '$vehicles4', '$vehicles5', '$vehicles6', '$vehicles7', '$vehicles8', '$vehicles9', '$vehicles10', '$salesmgr1', '$admin1', '$salesmgr2', '$admin2', '$salesmgr3', '$admin3', '$salesmgr4', '$admin4', '$salesmgr5', '$admin5', '$salesmgr6', '$admin6', '$salesmgr7', '$admin7', '$salesmgr8', '$admin8')");
//$result5 = mysql_query("SELECT general_id FROM dealershipinfo WHERE general_id = '$id'");
$result5 = @mysql_query($query5);
$row = mysql_fetch_array($result5);
mysql_query($query) or die(mysql_error());
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#0099FF\"><font color=\"#FFFFFF\">Thank You! Your Information has been sent.</font></td></tr></table>";
mail($to, $subject, $message, $headers);
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#0099FF\"><font color=\"#FFFFFF\">Thank You! Your Information has been emailed to us.</font></td></tr></table>";
//////////////////////////////////////////////////
}


I'm tried a lot of different things but I can seem figure it out. I think it all boils down to the if...elseif statement. :-?

davidj
05-29-2007, 07:18 PM
you are on the right lines

just need to add a condition to the IF

you could add a hidden field to the form and echo the $general_id in the field value

when you post the form then catch the field in a $_POST and then just check the $_POST var in the IF to determine where to go next (insert or update)

does this make it clearer

cdavenport4
05-29-2007, 08:12 PM
Yea... This does make some since. Thank You Again! 8-)

cdavenport4
05-30-2007, 01:59 PM
Okay Davidj,

I understand what your talking about but I guess It's eluding me on how I can accomplish this task.

I included the $generalid in the Update and Insert query's and what I'm lost on how I can check the mysql database if the $generalid exist within the table.

I'm trying my hardest to understand this... I'm sure it's starring me in the face.

davidj
05-30-2007, 02:01 PM
post the code

cdavenport4
05-30-2007, 02:33 PM
Thank You Davidj...


require_once("connection.php"); //Database Connection
include("Security.php");

session_start();

$id = $_SESSION['id'];

//////////////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM users WHERE user_id = '$id'");
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
/////////////////////////////////////////////////////////////

//////////////////////////////////////////////////
$generalid = $_POST['general_id'];
$dealership = $_POST['dealership'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
//$phone = $_POST['phone'];
$pattern = '/^\(?\d{3}\)? \d{3}-\d{4}$/';
$phone = trim($_POST['phone']);
$website = $_POST['website'];
$fax = $_POST['fax'];
$pricont = $_POST['pricont'];
$prititle = $_POST['prititle'];
$priphone = $_POST['priphone'];
$priemail = $_POST['priemail'];
$sales = $_POST['sales'];
$saletitle = $_POST['saletitle'];
$salephone = $_POST['salephone'];
$saleemail = $_POST['saleemail'];
$it = $_POST['it'];
$ittitle = $_POST['ittitle'];
$itphone = $_POST['itphone'];
$itemail = $_POST['itemail'];
$gmmotors = $_POST['gmmotors'];
$toyotamotor = $_POST['toyotamotor'];
$fordmotor = $_POST['fordmotor'];
$volkswagen = $_POST['volkswagen'];
$daimierchry = $_POST['daimierchry'];
$honda = $_POST['honda'];
$nissan = $_POST['nissan'];
$hyundaimotor = $_POST['hyundaimotor'];
$mitsubishi = $_POST['mitsubishi'];
$bmwgroup = $_POST['bmwgroup'];
$salesmgr1 = $_POST['salesmgr1'];
$admin1 = $_POST['admin1'];
$salesmgr2 = $_POST['salesmgr2'];
$admin2 = $_POST['admin2'];
$salesmgr3 = $_POST['salesmgr3'];
$admin3 = $_POST['admin3'];
$salesmgr4 = $_POST['salesmgr4'];
$admin4 = $_POST['admin4'];
$salesmgr5 = $_POST['salesmgr5'];
$admin5 = $_POST['admin5'];
$salesmgr6 = $_POST['salesmgr6'];
$admin6 = $_POST['admin6'];
$salesmgr7 = $_POST['salesmgr7'];
$admin7 = $_POST['admin7'];
$salesmgr8 = $_POST['salesmgr8'];
$admin8 = $_POST['admin8'];
$vehicles1 = implode(",", $gmmotors);
$vehicles2 = implode(",", $toyotamotor);
$vehicles3 = implode(",", $fordmotor);
$vehicles4 = implode(",", $volkswagen);
$vehicles5 = implode(",", $daimierchry);
$vehicles6 = implode(",", $honda);
$vehicles7 = implode(",", $nissan);
$vehicles8 = implode(",", $hyundaimotor);
$vehicles9 = implode(",", $mitsubishi);
$vehicles10 = implode(",", $bmwgroup);
$preview = $_POST['button'];
$submitted = $_POST['submit'];
$missing = array();
$verify_value = $HTTP_GET_VARS['verify'];
$upd = $_GET['upd'];
$update_id = $_POST['update_id'];

//////////////////////////////////////////////////
$query1 = sprintf("SELECT * FROM users, dealershipinfo, generalinfo");
$result1 = @mysql_query($query1);
$rowUpdate = mysql_fetch_array($result1);
//////////////////////////////////////////////////
$generalid = $upd;
//////////////////////////////////////////////////
$to = 'cdavenport4@mac.com';
$from = 'cdavenport4@mac.com';
$message ='Profile Information';

$headers = 'MIME-Version: 1.0\n';
$headers .= 'Content-type: text/html; charset=iso-8859-1\n';

$headers .= 'To: '.$to.' \n';
$headers .= 'From: '.$from.' \n';
$subject = 'General Information Profile has been filled out';
//////////////////////////////////////////////////

if ($dealership == null && $submitted) {
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#CC0000\"><font color=\"#FFFFFF\">Dealership Field is empty!</font></td></tr></table>";
}

if ($address == null && $submitted && $update_id) {
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#CC0000\"><font color=\"#FFFFFF\">address Field is empty!</font></td></tr></table>";
}

\\~~~~~~~~Additional Code~~~~~~~~~~~~~~~~~

if ($admin1 == null && $submitted) {
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#CC0000\"><font color=\"#FFFFFF\">You need at least one Administrator of ePencil</font></td></tr></table>";
}

if ($rowUpdate == $upd) && $submitted) {

//*****Update Record*****//
////////////////////////////////////////////////////
$query = sprintf("UPDATE dealershipinfo SET general_id='$upd', dealership='$dealership', address='$address', city='$city', state='$state', zip='$zip', phone='$phone', website='$website', fax='$fax' WHERE general_id = '$upd'");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#F7941C\"><font color=\"#000000\">Thank You! Your Information has been Updated!.</font></td></tr></table>";
////////////////////////////////////////////////////


} elseif ($rowUpdate == null) && $submitted) {
$generalid = $upd;

//*****Create Record*****//
////////////////////////////////////////////////////
$query = sprintf("INSERT INTO dealershipinfo (general_id, dealership, address, city, state, zip, phone, website, fax, pricont, prititle, priphone, priemail, sales, saletitle, salephone, saleemail, it, ittitle, itphone, itemail, gmmotors, toyotamotor, fordmotor, volkswagen, daimierchry, honda, nissan, hyundaimotor, mitsubishi, bmwgroup, salesmgr1, admin1, salesmgr2, admin2, salesmgr3, admin3, salesmgr4, admin4, salesmgr5, admin5, salesmgr6, admin6, salesmgr7, admin7, salesmgr8, admin8) VALUES ('$upd', '$dealership', '$address', '$city', '$state', '$zip', '$phone', '$website', '$fax', '$pricont', '$prititle', '$priphone', '$priemail', '$sales', '$saletitle', '$salephone', '$saleemail', '$it', '$ittitle', '$itphone', '$itemail', '$vehicles1', '$vehicles2', '$vehicles3', '$vehicles4', '$vehicles5', '$vehicles6', '$vehicles7', '$vehicles8', '$vehicles9', '$vehicles10', '$salesmgr1', '$admin1', '$salesmgr2', '$admin2', '$salesmgr3', '$admin3', '$salesmgr4', '$admin4', '$salesmgr5', '$admin5', '$salesmgr6', '$admin6', '$salesmgr7', '$admin7', '$salesmgr8', '$admin8')");
//$result5 = mysql_query("SELECT general_id FROM dealershipinfo WHERE general_id = '$id'");
$result = @mysql_query($query);
//$row = mysql_fetch_array($result);
//mysql_query($query) or die(mysql_error());
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#0099FF\"><font color=\"#FFFFFF\">Thank You! Your Information has been sent.</font></td></tr></table>";
mail($to, $subject, $message, $headers);
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#0099FF\"><font color=\"#FFFFFF\">Thank You! Your Information has been emailed to us.</font></td></tr></table>";
//////////////////////////////////////////////////
}

davidj
05-30-2007, 02:40 PM
you have illegal brackets in your condition

i have added what you need

if ($rowUpdate == $upd && $submitted && $generalid) { ///<< ** $generalid

//*****Update Record*****//
////////////////////////////////////////////////////
$query = sprintf("UPDATE dealershipinfo SET general_id='$upd', dealership='$dealership', address='$address', city='$city', state='$state', zip='$zip', phone='$phone', website='$website', fax='$fax' WHERE general_id = '$upd'");
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#F7941C\"><font color=\"#000000\">Thank You! Your Information has been Updated!.</font></td></tr></table>";
////////////////////////////////////////////////////


} elseif ($rowUpdate == null && $submitted) {
$generalid = $upd;

//*****Create Record*****//
////////////////////////////////////////////////////
$query = sprintf("INSERT INTO dealershipinfo (general_id, dealership, address, city, state, zip, phone, website, fax, pricont, prititle, priphone, priemail, sales, saletitle, salephone, saleemail, it, ittitle, itphone, itemail, gmmotors, toyotamotor, fordmotor, volkswagen, daimierchry, honda, nissan, hyundaimotor, mitsubishi, bmwgroup, salesmgr1, admin1, salesmgr2, admin2, salesmgr3, admin3, salesmgr4, admin4, salesmgr5, admin5, salesmgr6, admin6, salesmgr7, admin7, salesmgr8, admin8) VALUES ('$upd', '$dealership', '$address', '$city', '$state', '$zip', '$phone', '$website', '$fax', '$pricont', '$prititle', '$priphone', '$priemail', '$sales', '$saletitle', '$salephone', '$saleemail', '$it', '$ittitle', '$itphone', '$itemail', '$vehicles1', '$vehicles2', '$vehicles3', '$vehicles4', '$vehicles5', '$vehicles6', '$vehicles7', '$vehicles8', '$vehicles9', '$vehicles10', '$salesmgr1', '$admin1', '$salesmgr2', '$admin2', '$salesmgr3', '$admin3', '$salesmgr4', '$admin4', '$salesmgr5', '$admin5', '$salesmgr6', '$admin6', '$salesmgr7', '$admin7', '$salesmgr8', '$admin8')");
//$result5 = mysql_query("SELECT general_id FROM dealershipinfo WHERE general_id = '$id'");
$result = @mysql_query($query);
//$row = mysql_fetch_array($result);
//mysql_query($query) or die(mysql_error());
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#0099FF\"><font color=\"#FFFFFF\">Thank You! Your Information has been sent.</font></td></tr></table>";
mail($to, $subject, $message, $headers);
echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#0099FF\"><font color=\"#FFFFFF\">Thank You! Your Information has been emailed to us.</font></td></tr></table>";
//////////////////////////////////////////////////
}

cdavenport4
06-02-2007, 09:57 PM
Okay David, I've tried adding the generalid. It didn't work for what ever the reason so, I made a little test to figure this out. I'm still at a lost... If you would check this out and let me know where I'm going wrong.


require_once("connection.php"); //Database Connection
include("Security.php");

session_start();

$id = $_SESSION['id'];

///////////////////////////////////////////////////
//--------Search in for id in database table//
$queryresult = mysql_query("SELECT * FROM dealershipinfo");
while ($fetchresult = mysql_fetch_array($queryresult)) {
$id2 = $fetchresult['general_id'];
$username = $fetchresult['dealership'];
}
/////////////////////////////////////////////////

if ($id2 == $id) {

echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#F7941C\"><font color=\"#000000\">Thank You! Your Information has been Updated!.</font></td></tr></table>";
echo "<p>update----------- id2 = ".$id2;
////////////////////////////////////////////////////

} else {

echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#0099FF\"><font color=\"#FFFFFF\">Thank You! Your Information has been emailed to us.</font></td></tr></table>";
echo "<p>Insert----------- id2 != ".$id2;
//////////////////////////////////////////////////
}



Again thank you for all your help.

davidj
06-02-2007, 10:08 PM
this is incorrect
The select query is not valid

$queryresult = mysql_query("SELECT * FROM dealershipinfo");

Your While loop is being run above the output and the result would return incorrectly anywaywhile ($fetchresult = mysql_fetch_array($queryresult)) {
$id2 = $fetchresult['general_id'];
$username = $fetchresult['dealership'];
}

You are echoing values inside the PHP which is fine in tutorials but you should assign to variables

I think you need to visit the tutorials again

cdavenport4
06-02-2007, 10:42 PM
David this was just a test 'no production' to see if I could match the $id to a general_id from the database. Also, I'm not quite sure what you mean "Your While loop is being run above the output"

cdavenport4
06-02-2007, 11:09 PM
I changed the Select Query statement...


///////////////////////////////////////////////////
//--------Search for id in database table--//
$query = sprintf("SELECT * FROM dealershipinfo");
$queryresult = mysql_query($query);
while ($fetchresult = mysql_fetch_array($queryresult)) {
$id2 = $fetchresult['general_id'];
//$username = $fetchresult['dealership'];
}/////////////////////////////////////////////////

if ($id2 == $id) {

echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#F7941C\"><font color=\"#000000\">Thank You! Your Information has been Updated!.</font></td></tr></table>";
echo "<p>update----------- id2 = ".$id2;
////////////////////////////////////////////////////

} else {

echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#0099FF\"><font color=\"#FFFFFF\">Thank You! Your Information has been emailed to us.</font></td></tr></table>";
echo "<p>Insert----------- id2 != ".$id2;
//////////////////////////////////////////////////
}

davidj
06-03-2007, 10:15 AM
ok

first you have this..


///////////////////////////////////////////////////
//--------Search for id in database table--//
$query = sprintf("SELECT * FROM dealershipinfo");
$queryresult = mysql_query($query);
while ($fetchresult = mysql_fetch_array($queryresult)) {
$id2 = $fetchresult['general_id'];
//$username = $fetchresult['dealership'];
}/////////////////////////////////////////////////


and your looking for an id that exists in the db

why not do this...

///////////////////////////////////////////////////
//--------Search for id in database table--//
$query = sprintf("SELECT * FROM dealershipinfo where id_field='$id2'");
$queryresult = mysql_query($query);
$row = mysql_fetch_assoc($queryresult);
}/////////////////////////////////////////////////

you need to pass in $id2 but if you have followed the tuts you would know how to do that. Then all you have to do is see if $row contains a value. If it does then you have found a record.

you also have this going on...

if ($id2 == $id) {

echo "<table width=\"100%\" border=\"0\"><tr><td bgcolor=\"#F7941C\"><font color=\"#000000\">Thank You! Your Information has been Updated!.</font></td></tr></table>";
echo "<p>update----------- id2 = ".$id2;
////////////////////////////////////////////////////

you are echo-ing a string inside a script. Remember that if this is at the top of the page (before the HTML) and you echo this above output you may create problems. Best to assign the messages to a var and then echo the var in the html somewhere.

You are also formating your messages using html. You should use CSS

The warning message contains a table. Remember that your job as a programmer is to come up with a clever way to do stuff. You dont need to write the table into a var just write the message in a var and use CSS to format it.