Jump to content

Adding data...


2old2learn?
 Share

Recommended Posts

HelloForgive me..I am very new to all this so excuse my error's of my way..I am trying to create a user interface database for work..I have the form done still some fine tuning to do..but it works..but what is not working it inserting the data..I keep getting these error's..Notice: Undefined index: srnumber in C:\xampp\htdocs\icc\insert.php on line 19Notice: Undefined index: tenant in C:\xampp\htdocs\icc\insert.php on line 19Notice: Undefined index: floor in C:\xampp\htdocs\icc\insert.php on line 19Notice: Undefined index: tower in C:\xampp\htdocs\icc\insert.php on line 19Notice: Undefined index: job_description in C:\xampp\htdocs\icc\insert.php on line 19Notice: Undefined index: labour_cost in C:\xampp\htdocs\icc\insert.php on line 19Notice: Undefined index: material_cost in C:\xampp\htdocs\icc\insert.php on line 19Notice: Undefined index: date_twa_sent_to_tenant in C:\xampp\htdocs\icc\insert.php on line 19Notice: Undefined index: date_twa_approved in C:\xampp\htdocs\icc\insert.php on line 19Notice: Undefined index: date_parts_orderd in C:\xampp\htdocs\icc\insert.php on line 19Notice: Undefined index: supplier in C:\xampp\htdocs\icc\insert.php on line 19Notice: Undefined index: date_job_completed in C:\xampp\htdocs\icc\insert.php on line 19Notice: Undefined index: date_billing_given_to_accounting in C:\xampp\htdocs\icc\insert.php on line 19Error: Unknown column 'date_parts_orderd' in 'field list'So here is my script

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>insert.php</title></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 ( srnumber, tenant, floor, tower, job_description, labour_cost, material_cost, date_twa_sent_to_tenant, date_twa_approved, date_parts_orderd, supplier, date_job_completed, date_billing_given_to_accounting) VALUESThis line 19-->> ('$_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_orderd]','$_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>

Link to comment
Share on other sites

  • Replies 251
  • Created
  • Last Reply

Top Posters In This Topic

Those errors mean that $_POST doesn't contain the values you're looking for, which usually means that the form hasn't been submitted yet. Make sure your form is using the post action. It also looks like you have a column in your database query that isn't in the twal table.

Link to comment
Share on other sites

It's also a good idea to check whether your POST values have been set, especially if they are user generated. That will probably mean something like this:

if (empty($_POST['srnumber']) ) {   // do something}

This works especially well when the form and the script that processes the form data are in the same document. If there's a glitch, the script can download the form again, but this time with icons or text doodads to let the user know where they goofed.

Link to comment
Share on other sites

Those errors mean that $_POST doesn't contain the values you're looking for, which usually means that the form hasn't been submitted yet. Make sure your form is using the post action. It also looks like you have a column in your database query that isn't in the twal table.
Hey thanks;I checked my database and it does have the date_parts_ordered column...if thats what your saying...
Link to comment
Share on other sites

It's also a good idea to check whether your POST values have been set, especially if they are user generated. That will probably mean something like this:
if (empty($_POST['srnumber']) ) {   // do something}

This works especially well when the form and the script that processes the form data are in the same document. If there's a glitch, the script can download the form again, but this time with icons or text doodads to let the user know where they goofed.

Okay..not sure of what you mean..also my form is a separate php file from the insert.php are you saying these should be together in one file.????
Link to comment
Share on other sites

you should show us the form, but basically what everyone is trying to get is you need to be validating your inputs. you are just assuming they are coming over the wire. the best thing you can do when testing forms is to verify the data. The simplest way is to add this at the top of your insert script (ideallu right after <?php).

var_dump($_POST);

Make sure you are getting what you expect first. 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

$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';};

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.

Link to comment
Share on other sites

okay here is my form file...

<!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><form action="insert.php" method="post"> SR Number:<br>                        <input type="text" name="SR Number" /><br> Tenant:<br>                           <input type="text" name="Tenant" /><br> Floor:<br>                            <input type="text" name="Floor" /><br> Tower:<br>                            <input type="text" name="Tower" /><br> Job Description:<br>                  <input type="text" name="Job Description" /><br> Labour Cost:<br>                      <input type="text" name="Labour Cost" /><br>  Material Cost:<br>                    <input type="text" name="Material Cost" /><br> Date TWA Sent to Tenant:<br>          <input type="text" name="Date TWA Sent to Tenant" /><br> Date TWA Approved:<br>                <input type="text" name="Date TWA Approved" /><br> Date Parts Ordered:<br>               <input type="text" name="Date Parts Ordered" /><br> Supplier:<br>                         <input type="text" name="Supplier" /><br> Date Job Completed:<br>               <input type="text" name="Date Job Completed" /><br> Date Billing Given to Accounting:<br> <input type="text" name="Date Billing Given to Accounting          " /><br>  <input type="submit" /> </form> </body></html>

Link to comment
Share on other sites

the names of your input elements

 SR Number:<br>						<input type="text" name="SR Number" /><br> Tenant:<br>						   <input type="text" name="Tenant" /><br> Floor:<br>							<input type="text" name="Floor" /><br> Tower:<br>							<input type="text" name="Tower" /><br> Job Description:<br>				  <input type="text" name="Job Description" /><br> Labour Cost:<br>					  <input type="text" name="Labour Cost" /><br>  Material Cost:<br>					<input type="text" name="Material Cost" /><br> Date TWA Sent to Tenant:<br>		  <input type="text" name="Date TWA Sent to Tenant" /><br> Date TWA Approved:<br>				<input type="text" name="Date TWA Approved" /><br> Date Parts Ordered:<br>			   <input type="text" name="Date Parts Ordered" /><br> Supplier:<br>						 <input type="text" name="Supplier" /><br> Date Job Completed:<br>			   <input type="text" name="Date Job Completed" /><br> Date Billing Given to Accounting:<br> <input type="text" name="Date Billing Given to Accounting		  " /><br>

don't match the members in $_POST your are trying to access in your query

('$_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_orderd]','$_POST[supplier]','$_POST[date_job_completed]','$_POST[date_billing_given_to_accounting]')";

Edited by thescientist
Link to comment
Share on other sites

the names of your input elements
 SR Number:<br>						<input type="text" name="SR Number" /><br> Tenant:<br>						   <input type="text" name="Tenant" /><br> Floor:<br>							<input type="text" name="Floor" /><br> Tower:<br>							<input type="text" name="Tower" /><br> Job Description:<br>				  <input type="text" name="Job Description" /><br> Labour Cost:<br>					  <input type="text" name="Labour Cost" /><br>  Material Cost:<br>					<input type="text" name="Material Cost" /><br> Date TWA Sent to Tenant:<br>		  <input type="text" name="Date TWA Sent to Tenant" /><br> Date TWA Approved:<br>				<input type="text" name="Date TWA Approved" /><br> Date Parts Ordered:<br>			   <input type="text" name="Date Parts Ordered" /><br> Supplier:<br>						 <input type="text" name="Supplier" /><br> Date Job Completed:<br>			   <input type="text" name="Date Job Completed" /><br> Date Billing Given to Accounting:<br> <input type="text" name="Date Billing Given to Accounting		  " /><br>

don't match the members in $_POST your are trying to access in your query

('$_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_orderd]','$_POST[supplier]','$_POST[date_job_completed]','$_POST[date_billing_given_to_accounting]')";

Yea, while awaiting a reply I did a check of PHP MySQL Insert Into(w3schools examples) so I removed the $_POST from infront of field names..now all I get it this error only...Error: Unknown column 'date_parts_orderd' in 'field list'also should the input type="text" name= "Date Job Completed" be written the same as the field names???? Edited by 2old2learn?
Link to comment
Share on other sites

Yea, while awaiting a reply I did a check of PHP MySQL Insert Into(w3schools examples) so I removed the $_POST from infront of field names..now all I get it this error...Error: Unknown column 'date_parts_orderd' in 'field list'
umm... not quite. those weren't the field names in the query I was talking about. they are members of the $_POST array, which is what you are telling the form to populate when you submit it. The names of your form elements and the members in $_POST that you want to look for need to match, i.e.
SR Number:<br> <input type="text" name="srnumber" /><br>
to match
('$_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_orderd]','$_POST[supplier]','$_POST[date_job_completed]','$_POST[date_billing_given_to_accounting]')";
or vice versa, but they need to match on both pages. That's the only chance the script and the form will be able to sync the mapping of these values. you might want to read this page.http://www.w3schools.com/php/php_post.asp Edited by thescientist
Link to comment
Share on other sites

umm... not quite. those weren't the field names in the query I was talking about. they are members of the $_POST array, which is what you are telling the form to populate when you submit it. The names of your form elements and the members in $_POST that you want to look for need to match, i.e.to matchor vice versa, but they need to match on both pages. That's the only chance the script and the form will be able to sync the mapping of these values. you might want to read this page.http://www.w3schools.com/php/php_post.asp
Ahh okay...will recheck them..thanks..
Link to comment
Share on other sites

also should the input type="text" name= "Date Job Completed" be written the same as the field names????
the names you for the columns part of an INSERT just need to match the column names in the database.http://www.w3schools.com/php/php_mysql_insert.asp Edited by thescientist
Link to comment
Share on other sites

the names you for the columns part of an INSERT just need to match the column names in the database.http://www.w3schools.com/php/php_mysql_insert.asp
Okay gotcha..which means they have to be the same...as the fields in the table...thanks..will correct it now..so I can re-add the $_POST back where they were before???
Link to comment
Share on other sites

this is how it works. form inputs have a name attribute. whatever name you give it, is what it's 'name' will be in $_POST.

<input name="w3schools" />..$value = $_POST['w3schools'];

That's how you get those values from HTML to PHP.then, to use it in a query, the column part of the INSERT query needs to match the column names in your table. The values part is just values.just follow the links I gave you in their order posted and you should get it.

Edited by thescientist
Link to comment
Share on other sites

this is how it works. form inputs have a name attribute. whatever name you give it, is what it's 'name' will be in $_POST.
<input name="w3schools" />..$value = $_POST['w3schools'];

That's how you get those values from HTML to PHP.then, to use it in a query, the column part of the INSERT query needs to match the column names in your table. The values part is just values.just follow the links I gave you in their order posted and you should get it.

yea, I hear you this is how I got started ...starting off with the links you gave..thanks..will research some more I think I am getting the idea now..LOL...just re-read my script..and found this..' date_parts_orderd '...should have been ' date_parts_ordered '... left the " e " out on ordered...LOL Edited by 2old2learn?
Link to comment
Share on other sites

yea, I hear you this is how I got started ...starting off with the links you gave..thanks..will research some more I think I am getting the idea now..LOL...just re-read my script..and found this..' date_parts_orderd '...should have been ' date_parts_ordered '... left the " e " out on ordered...LOL
Okay I've made some correction and now all I get is this error??"Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= ('','000002345','BMO','18','250 Yonge','shredding','40.00','20.00','4/23/11'' at line 2"Never mind got it to work now..1 record added it says now..thanks GUYS.....also checked database and it shows all the data entered..but in the dates they just show 0000/00/00..not the date I entered...I have the type as " Date "..in the structure...is that correct or should it just be " Text "... Edited by 2old2learn?
Link to comment
Share on other sites

okay updated on how you guys helped alot...I've also tested my display of data..now this works tooo" No rows found, nothing to print so am exiting "which is correct I've deleted test entries..into database...you guys are amazing...thanks...

Link to comment
Share on other sites

nice :)
but in the dates they just show 0000/00/00..not the date I entered...I have the type as " Date "..in the structure...is that correct or should it just be " Text "... thanks
Link to comment
Share on other sites

oh right!can you show your updated form and insert code?edit: is this like whats happening?http://www.webdeveloper.com/forum/showthread.php?t=236459

Edited by thescientist
Link to comment
Share on other sites

Okay updated Form:

<!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"> ID<br>								<input type="text" name="id"/><br> SR Number:<br>						<input type="text" name="srnumber" /><br> Tenant:<br>						   <input type="text" name="tenant" /><br> Floor:<br>							<input type="text" name="floor" /><br> Tower:<br>							<input type="text" name="tower" /><br> Job Description:<br>				  <input type="text" name="job_description" /><br> Labour Cost:<br>					  <input type="text" name="labour_cost" /><br>  Material Cost:<br>					<input type="text" name="material_cost" /><br> Date TWA Sent to Tenant:<br>		  <input type="text" name="date_twa_sent_to_tenant" /><br> Date TWA Approved:<br>				<input type="text" name="date_twa_approved" /><br> Date Parts Ordered:<br>			   <input type="text" name="date_parts_ordered" /><br> Supplier:<br>						 <input type="text" name="supplier" /><br> Date Job Completed:<br>			   <input type="text" name="date_job_completed" /><br> Date Billing Given to Accounting:<br> <input type="text" name="date_billing_given_to_accounting" /><br>  <input type="submit" /> </form> </body></html>

Updated insert:

<!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>

thanks....but I am talking about the database in myphpadmin I have style set to "date"...should it be " text "

Link to comment
Share on other sites

well, the link I posted suggested the date needs to be hyphenated, not slashed. i.e. 2011-04-23.I think the best way to save a date is to is a timestamp and then to use date functions to parse it or to do calculations with it. If all you plan on doing with the date is to show it, then text could be fine.

Link to comment
Share on other sites

well, the link I posted suggested the date needs to be hyphenated, not slashed. i.e. 2011-04-23.I think the best way to save a date is to is a timestamp and then to use date functions to parse it or to do calculations with it. If all you plan on doing with the date is to show it, then text could be fine.
Okay I will for now go with " Text " after getting more knowledge will look into updating..this is work in progress...LOLNice Info .. bud
Link to comment
Share on other sites

okay I wish to display my data in display boxes..

while ($row = mysql_fetch_assoc($result)) {	echo $row["id"];	echo $row["srnumber"];	echo $row["tenant"];	echo $row["floor"];	echo $row["tower"];	echo $row["job_description"];	echo $row["labour_cost"];	echo $row["material_cost"];	echo $row["date_twa_sent_to_tenant"];	echo $row["date_twa_approved"];	echo $row["date_parts_ordered"];	echo $row["supplier"];	echo $row["date_job_completed"];	echo $row["date_billing_given_to_accounting"];/body></html>}mysql_free_result($result);?>

now it returns a display like this when I go to display.php for now.."10000023456BMO18250 YongeShredding40204/23/114/24/114/24/11TEC4/26/114/28/11 "I wish it to separate from each other and in a text box..can this be done???

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×
×
  • Create New...