Jump to content
2old2learn?

Adding data...

Recommended Posts

start here, this will get in a table for you and give you the initial steps needed to embed HTML into PHP output.http://www.w3schools.com/php/php_mysql_select.aspfrom there you should be able to convert it to meet your needs.

Edited by thescientist

Share this post


Link to post
Share on other sites
start here, this will get in a table for you and give you the initial steps needed to embed HTML into PHP output.http://www.w3schools.com/php/php_mysql_select.aspfrom there you should be able to convert it to meet your needs.
okay will do bud

Share this post


Link to post
Share on other sites

Hey thanks for the info here is what I've done for now...

echo "<table border='1'><tr><th>ID</th><th>SRNumber</th><th>Tenant</th><th>Floor</th><th>Tower</th><th>Job Description</th><th>Labour Cost</th><th>Material Cost</th><th>Date TWA Sent to Tenant</th><th>Date TWA Approved</th><th>Date Parts Ordered</th><th>Supplier</th><th>Date Job Completed</th><th>Date Billing Given to Accounting</th></tr>";// While a row of data exists, put that row in $row as an associative array// Note: If you're expecting just one row, no need to use a loop// Note: If you put extract($row); inside the following loop, you'll//	   then create $userid, $fullname, and $userstatuswhile ($row = mysql_fetch_assoc($result)) {	echo "<tr>";	echo "<td>" .$row["id"]."</td>";	echo "<td>" .$row["srnumber"]."</td>";	echo "<td>" .$row["tenant"]."</td>";	echo "<td>" .$row["floor"]."</td>";	echo "<td>" .$row["tower"]."</td>";	echo "<td>" .$row["job_description"]."</td>";	echo "<td>" .$row["labour_cost"]."</td>";	echo "<td>" .$row["material_cost"]."</td>";	echo "<td>" .$row["date_twa_sent_to_tenant"]."</td>";	echo "<td>" .$row["date_twa_approved"]."</td>";	echo "<td>" .$row["date_parts_ordered"]."</td>";	echo "<td>" .$row["supplier"]."</td>";	echo "<td>" .$row["date_job_completed"]."</td>";	echo "<td>" .$row["date_billing_given_to_accounting"]."</td>";	echo "</tr>";  }echo "</table>";mysql_free_result($result);?> </body></html>

The help here is " TOP NOTCHED " thanks guys..

Share this post


Link to post
Share on other sites

Okay most is all sorted out now..most scripts are working as expected..but will this add a new row of data to the table..this is my insert.php page..from what I am thinking this only adds one entry...am I correct?? I posting this just as I am about to goto tutorials..hoping I find the solution for both insert and displaying...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>insert.php</title><link rel="stylesheet" type="text/css" href="/icc/skins/My_Start_Style.css" /></head><body><?php $con = mysql_connect("localhost","root",""); if (!$con)   {   die('Could not connect: ' . mysql_error());   } mysql_select_db("tecicc", $con); $sql="INSERT INTO twal ( id, srnumber, tenant, floor, tower, job_description, labour_cost, material_cost, date_twa_sent_to_tenant, date_twa_approved, date_parts_ordered, supplier, date_job_completed, date_billing_given_to_accounting) values ('$_POST[id]','$_POST[srnumber]','$_POST[tenant]','$_POST[floor]','$_POST[tower]','$_POST[job_description]','$_POST[labour_cost]','$_POST[material_cost]','$_POST[date_twa_sent_to_tenant]','$_POST[date_twa_approved]','$_POST[date_parts_ordered]','$_POST[supplier]','$_POST[date_job_completed]','$_POST[date_billing_given_to_accounting]')";if (!mysql_query($sql,$con))   {   die('Error: ' . mysql_error());   } echo "1 record added"; mysql_close($con); ?> </body></html>

Share this post


Link to post
Share on other sites

LOL Disregard all of the above..yes it does add a new row..and displays a new row...LOLYou Guys are Great..

Share this post


Link to post
Share on other sites

New Question now...As you can see in the photo I wish to line up things to look neat how can I go about it..formo.jpg

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>TWAL</title><link rel="stylesheet" type="text/css" href="/icc/skins/My_Start_Style.css" /></head><body><?php include("menu.php"); ?><form action="insert.php" method="post"><table><center><caption>Tenant Work Authorization Log</caption></center><table class="space"> <tr><td>ID:							   <input type="text" name="id"/></td></tr></table> <tr><td>SR Number:						<input type="text" name="srnumber" /></td></tr> <td>Tenant:							   <input type="text" name="tenant" /></td></tr> <td>Floor:								<input type="text" name="floor" /></td></tr> <td>Tower:								<input type="text" name="tower" /></td></tr> <tr><td>Job Description:				  <input type="text" name="job_description" /><br></td></tr> <tr><td>Labour Cost:					  <input type="text" name="labour_cost" /><br></td></tr>  <tr><td>Material Cost:					<input type="text" name="material_cost" /><br></td></tr> <tr><td>Date TWA Sent to Tenant:		  <input type="text" name="date_twa_sent_to_tenant" /><br></td></tr> <tr><td>Date TWA Approved:				<input type="text" name="date_twa_approved" /><br></td></tr> <tr><td>Date Parts Ordered:			   <input type="text" name="date_parts_ordered" /><br></td></tr> <tr><td>Supplier:						 <input type="text" name="supplier" /><br></td></tr> <tr><td>Date Job Completed:			   <input type="text" name="date_job_completed" /><br></td></tr> <tr><td>Date Billing Given to Accounting: <input type="text" name="date_billing_given_to_accounting" /><br>  <input type="submit" />  </form> </body></html>

As you see some of the input area's are lined across I would like to do the same with it all making it look box like....Thanks...

Share this post


Link to post
Share on other sites

Not exactly sure what you mean by box?do you mean two column table? first column labels/decriptions, second column form inputs, as below

<form action="insert.php" method="post"><table><tr><td><center><caption>Tenant Work Authorization Log</caption></center></td></tr></table><table class="space"><tr><td>ID:</td><td>							  <input type="text" name="id"/></td></tr><tr><td>SR Number:</td><td>						 <input type="text" name="srnumber" /></td></tr><td>Tenant:</td><td>							   <input type="text" name="tenant" /></td></tr><td>Floor:</td><td>								<input type="text" name="floor" /></td></tr><td>Tower:</td><td>								 <input type="text" name="tower" /></td></tr><tr><td>Job Description:</td><td>				  <input type="text" name="job_description" /></td></tr><tr><td>Labour Cost:</td><td>					  <input type="text" name="labour_cost" /></td></tr><tr><td>Material Cost:</td><td>					 <input type="text" name="material_cost" /></td></tr><tr><td>Date TWA Sent to Tenant:</td><td>		   <input type="text" name="date_twa_sent_to_tenant" /></td></tr><tr><td>Date TWA Approved:</td><td>				 <input type="text" name="date_twa_approved" /></td></tr><tr><td>Date Parts Ordered:</td><td>				<input type="text" name="date_parts_ordered" /></td></tr><tr><td>Supplier:</td><td>						  <input type="text" name="supplier" /><br></td></tr><tr><td>Date Job Completed:</td><td>				<input type="text" name="date_job_completed" /></td></tr><tr><td>Date Billing Given to Accounting:</td><td>  <input type="text" name="date_billing_given_to_accounting" /></td></tr><tr><td colspan="2"><input type="submit" /></td></tr></table></form>

Share this post


Link to post
Share on other sites
Not exactly sure what you mean by box?do you mean two column table? first column labels/decriptions, second column form inputs, as below
<form action="insert.php" method="post"><table><tr><td><center><caption>Tenant Work Authorization Log</caption></center></td></tr></table><table class="space"><tr><td>ID:</td><td>							  <input type="text" name="id"/></td></tr><tr><td>SR Number:</td><td>						 <input type="text" name="srnumber" /></td></tr><td>Tenant:</td><td>							   <input type="text" name="tenant" /></td></tr><td>Floor:</td><td>								<input type="text" name="floor" /></td></tr><td>Tower:</td><td>								 <input type="text" name="tower" /></td></tr><tr><td>Job Description:</td><td>				  <input type="text" name="job_description" /></td></tr><tr><td>Labour Cost:</td><td>					  <input type="text" name="labour_cost" /></td></tr><tr><td>Material Cost:</td><td>					 <input type="text" name="material_cost" /></td></tr><tr><td>Date TWA Sent to Tenant:</td><td>		   <input type="text" name="date_twa_sent_to_tenant" /></td></tr><tr><td>Date TWA Approved:</td><td>				 <input type="text" name="date_twa_approved" /></td></tr><tr><td>Date Parts Ordered:</td><td>				<input type="text" name="date_parts_ordered" /></td></tr><tr><td>Supplier:</td><td>						  <input type="text" name="supplier" /><br></td></tr><tr><td>Date Job Completed:</td><td>				<input type="text" name="date_job_completed" /></td></tr><tr><td>Date Billing Given to Accounting:</td><td>  <input type="text" name="date_billing_given_to_accounting" /></td></tr><tr><td colspan="2"><input type="submit" /></td></tr></table></form>

Hey I sort of got it to do what I want...here is latest picture..form1g.jpgAnd here is the code on how I went about this compared to my first picture above... but maybe someone else has a better solution..
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>TWAL</title><link rel="stylesheet" type="text/css" href="/icc/skins/My_Start_Style.css" /></head><body><?php include("menu.php"); ?><form action="insert.php" method="post"><table><center><caption>Tenant Work Authorization Log</caption></center><table class="space"> <tr><td>ID:							   <input type="text" name="id"/></td> <td>SR Number:						<input type="text" name="srnumber" /></td> <td>Tenant:							   <input type="text" name="tenant" /></td> <td>Floor:								<input type="text" name="floor" /></td> <td>Tower:								<input type="text" name="tower" /></td> <td>Job Description:				  <input type="text" name="job_description" /><br></td></tr></table> <table> <tr><td>Labour Cost:					  <input type="text" name="labour_cost" /></td>  <td>Material Cost:					<input type="text" name="material_cost" /></td> <td>Date TWA Sent to Tenant:		  <input type="text" name="date_twa_sent_to_tenant" /></td> <td>Date TWA Approved:				<input type="text" name="date_twa_approved" /></td></table><table> <tr><td>Date Parts Ordered:			   <input type="text" name="date_parts_ordered" /></td> <td>Supplier:						 <input type="text" name="supplier" /></td> <td>Date Job Completed:			   <input type="text" name="date_job_completed" /></td> <td>Date Billing Given to Accounting: <input type="text" name="date_billing_given_to_accounting" /></td></tr></table>  <input type="submit" />  </form>

Edited by 2old2learn?

Share this post


Link to post
Share on other sites

to align the two last rows, and so make it more presentable, you could

<table><center><caption>Tenant Work Authorization Log</caption></center><table class="space"> <tr><td>ID:							   <input type="text" name="id"/></td> <td>SR Number:						<input type="text" name="srnumber" /></td> <td>Tenant:							   <input type="text" name="tenant" /></td> <td>Floor:								<input type="text" name="floor" /></td> <td>Tower:								<input type="text" name="tower" /></td> <td>Job Description:				  <input type="text" name="job_description" /><br></td></tr></table> <table> <tr><td>Labour Cost: </td><td>					   <input type="text" name="labour_cost" /></td>  <td>Material Cost: </td><td>					 <input type="text" name="material_cost" /></td> <td>Date TWA Sent to Tenant:</td><td>			<input type="text" name="date_twa_sent_to_tenant" /></td> <td>Date TWA Approved:</td><td>				  <input type="text" name="date_twa_approved" /></td><!--</table>--><!--<table>--> <tr><td>Date Parts Ordered:</td><td>				 <input type="text" name="date_parts_ordered" /></td> <td>Supplier:</td><td>						   <input type="text" name="supplier" /></td> <td>Date Job Completed:</td><td>				 <input type="text" name="date_job_completed" /></td> <td>Date Billing Given to Accounting:</td><td>   <input type="text" name="date_billing_given_to_accounting" /></td></tr></table> </table>

Share this post


Link to post
Share on other sites
to align the two last rows, and so make it more presentable, you could
<table><center><caption>Tenant Work Authorization Log</caption></center><table class="space"> <tr><td>ID:							   <input type="text" name="id"/></td> <td>SR Number:						<input type="text" name="srnumber" /></td> <td>Tenant:							   <input type="text" name="tenant" /></td> <td>Floor:								<input type="text" name="floor" /></td> <td>Tower:								<input type="text" name="tower" /></td> <td>Job Description:				  <input type="text" name="job_description" /><br></td></tr></table> <table> <tr><td>Labour Cost: </td><td>					   <input type="text" name="labour_cost" /></td>  <td>Material Cost: </td><td>					 <input type="text" name="material_cost" /></td> <td>Date TWA Sent to Tenant:</td><td>			<input type="text" name="date_twa_sent_to_tenant" /></td> <td>Date TWA Approved:</td><td>				  <input type="text" name="date_twa_approved" /></td><!--</table>--><!--<table>--> <tr><td>Date Parts Ordered:</td><td>				 <input type="text" name="date_parts_ordered" /></td> <td>Supplier:</td><td>						   <input type="text" name="supplier" /></td> <td>Date Job Completed:</td><td>				 <input type="text" name="date_job_completed" /></td> <td>Date Billing Given to Accounting:</td><td>   <input type="text" name="date_billing_given_to_accounting" /></td></tr></table> </table>

Hey Thanks...it worked out great here, is what it looks like..but how can I align up " SRNumber with Material Cost column " to look more uniformed like " ID & SRNumber " column'sform2h.jpgHelp here is out of this world..I think I am starting to get the idea now..at least I hope... Edited by 2old2learn?

Share this post


Link to post
Share on other sites

Okay guys thanks to all the neat info you give I was able to create this..this is an updated cleaner looking form view now...hope you like what you have accomplished...helping me...form3t.jpgYou guys are great..

Share this post


Link to post
Share on other sites

looks good, although I would try and center the form on the page (like the image is), maybe give it a border, just to make things a little sharper. An easy solution would be to put it all in a div, and then using CSS give it a width for as wide as you need it, and give it some border styles, and to center it, margin: 0px auto

Edited by thescientist

Share this post


Link to post
Share on other sites

and of course you should add some form validation, at the minimum to prevent against SQL injection and to prevent empty values from being submitted to your database.

Share this post


Link to post
Share on other sites
looks good, although I would try and center the form on the page (like the image is), maybe give it a border, just to make things a little sharper. An easy solution would be to put it all in a div, and then using CSS give it a width for as wide as you need it, and give it some border styles, and to center it, margin: 0px auto
Yea, still tweaking it manage to get words closer to the input boxes..like <tr align="right"> CSS styling is my next venture..just wanted to sort of get this down..And thanks..it was all because of you guys I was able to manage this...thanks...

Share this post


Link to post
Share on other sites
and of course you should add some form validation, at the minimum to prevent against SQL injection and to prevent empty values from being submitted to your database.
How can I accomplish this " form validation" ?Okay got it centered now..but lower two rows are still to the left ...is there a way to just move them over a bit to have the input boxes line up????? Edited by 2old2learn?

Share this post


Link to post
Share on other sites

I gave an example/explanation of that in post #7.

After that, you should be checking that all your inputs have been filled out. The best way is to usually write a script on the client side (i.e. javascript) as an initial form of validation to make sure all inputs have been filled out, that they are all numbers if they need to be numbers, are certain lengths, etc. Catching it at this point means you can give feedback before the form is even sent to the insert script.The next way to validate is to go through each member of the $_POST array and check that none of them are empty. For example, you could use a loop
$isFormValid = true;foreach($_POST as $key => $value){  if(empty($_POST[$key]){	$isFormValid = false;  };};if($isFormValid){  //create query and execute call to the database}else{  echo ' sorry, there was a problem with the form.  please try again';};

something like that. either way, after you verify that your form is actually submitting the data correctly, you should be checking for the integrity of that data somehow before just sending it off to the database.

I didn't include the part of sql injection, but that's as simple as making sure that every user submitted value is put through the mysql_real_escape_string function.http://us3.php.net/manual/en/function.mysq...cape-string.php

Share this post


Link to post
Share on other sites
I gave an example/explanation of that in post #7. I didn't include the part of sql injection, but that's as simple as making sure that every user submitted value is put through the mysql_real_escape_string function.http://us3.php.net/manual/en/function.mysq...cape-string.php
Ahhh, okay will read thru them..I will keep you posted on results..another thing is I will try to create a login script...I know there are many examples out there..so I have alot of reading ahead of me...LOL

Share this post


Link to post
Share on other sites

Okay I haven't done the form validation yet..still fine tuning the appearence of the form..I think I have it, for now until I get more knowledgeable with CSS also...Here is new Picture of form...form4e.jpgThanks...

Edited by 2old2learn?

Share this post


Link to post
Share on other sites

Could this be what you mean for form validation??

<html><head><title>form_validation</title></head><body><?phpif (isset($_POST['id']) && isset($_POST['srnumber']) && isset($_POST['tenant']) && isset($_POST['floor']) && isset($_POST['tower']) && isset($_POST['job_description']) &&(isset($_POST['labour_cost']) && isset($_POST['material_cost']) && isset($_POST['date_twa_sent_to_tenant']) && isset($_POST['date_twa_approved']) && isset($_POST['date_parts_ordered']) && isset($_POST['supplier']) && isset($_POST['date_job_completed']) && isset($_POST['date_billing_given_to_accounting']))  echo "succesful form submission. initialize DB connection .....";  $con = mysql_connect("localhost","root","");}  if (!$con){ { die('Could not connect: ' . mysql_error()); }; echo "connection initialized....."; } {$formValid = true;foreach($_POST as $key => $value){  if(empty($_POST[$key]){	$formValid = false;  };};if($formValid){  //create query and execute call to the database}else{  echo ' sorry, there was a problem with the form.  please try again';};?></body></html>

Hmmmm??? Am I close?????I get this error message?"Parse error: syntax error, unexpected T_ECHO in C:\xampp\htdocs\icc\form_validation.php on line 9"Thanks

Edited by 2old2learn?

Share this post


Link to post
Share on other sites

validation means check for values of external inputs for valid values which suppose to be inserted. It can be anything its not limited to only using isset(). isset() will determine only that inputs are coming or not.Forms will be processed only when all validation criteria meets else it wont process the form. and you have to make the form process conditional so that it will only process after all valid value..and one more thing you can avoid using && to add more condition isset() it can be done by isset($var,$var1,$var2) .It will only return TRUE when var1 var2 and var 3 all are been set..if minimum one is not set it will return false. more info here http://php.net/function.isset

Share this post


Link to post
Share on other sites
validation means check for values of external inputs for valid values which suppose to be inserted. It can be anything its not limited to only using isset(). isset() will determine only that inputs are coming or not.Forms will be processed only when all validation criteria meets else it wont process the form. and you have to make the form process conditional so that it will only process after all valid value..and one more thing you can avoid using && to add more condition isset() it can be done by isset($var,$var1,$var2) .It will only return TRUE when var1 var2 and var 3 all are been set..if minimum one is not set it will return false. more info here http://php.net/function.isset
Hmm...okay I guess I am off on this one..You mean like this:
if (isset(id,srnumber,tenant)

What I've done is create a new form_validation.php file which is added to twal.php as so...

<?php include("form_validation.php");?>

Edited by 2old2learn?

Share this post


Link to post
Share on other sites

I was thinking more like my post

$formValid = true;<?phpforeach($_POST as $key => $value){  if(empty($_POST[$key]){	$formValid = false;  };};if($formValid){  //create query and execute call to the database}else{  echo ' sorry, there was a problem with the form.  please try again';};?>

where if formValid == true if($formValid), then you would want to execute your database connection/insert code. For the sake of an example, I just used a comment.edit: the point is that you validate everything first, if it passes whatever criteria you deem passable, then do the database stuff, else you send a message back to the user.

Edited by thescientist

Share this post


Link to post
Share on other sites
I was thinking more like my post
$formValid = true;<?phpforeach($_POST as $key => $value){  if(empty($_POST[$key]){	$formValid = false;  };};if($formValid){  //create query and execute call to the database}else{  echo ' sorry, there was a problem with the form.  please try again';};?>

where if formValid == true if($formValid), then you would want to execute your database connection/insert code. For the sake of an example, I just used a comment.edit: the point is that you validate everything first, if it passes whatever criteria you deem passable, then do the database stuff, else you send a message back to the user.

LOL...sorry didn't realize that..Okay I used your code..and get an error here..>>>>Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\icc\form_validation.php on line 9
foreach($_POST as $key => $value){

Edited by 2old2learn?

Share this post


Link to post
Share on other sites

ijust see your edit now...

Parse error: syntax error, unexpected T_ECHO in C:\xampp\htdocs\icc\form_validation.php on line 9
You have to remove the semicolons after for loops and if structure . semicolons are used to terminate any statement and foreach is not a statement its a loop and if is a conditional structure.
foreach($_POST as $key => $value){ if(empty($_POST[$key]){ $formValid = false; }
This part and the if(isset(...)...) part is checking the same conditions. You can do that by either one way both aproach is quite correct.But It is good to use like this..instead of looping through each key.
if(isset($_POST['somedata'],$_POST['moredata']){//process the form}else{//show the errors mesage and dont process the form}

if(empty($_POST[$key]){ $formValid = false;
there i would like to mention something about empty(). it sometime looks like its same as isset() but it has some difference which may cause some trouble. eg if your one of field is supposed to take value '0' (zero) empty will return TRUE which means that the variable is empt/or not sety. Where as isset() will return true and tell that the variable has been set. It will do like this because empty() take zero as empty.you may like to check the http://php.net/function.empty for more details. Edited by birbal

Share this post


Link to post
Share on other sites

I think I forgot a closing paren on the next line. Can you show us the whole code as updates/changes have been made?edit: birbal does bring up a good point about empty. the foreach can be used to check for either case however.

Edited by thescientist

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...