Jump to content

Adding data...


2old2learn?

Recommended Posts

Hey reading over some php/mysql books I see I can create drop down list, checkboxes, radio buttons...greatNow here is a questionIf I create a drop down list say: Locationex: Location: Location 1 Location 2 Location 3Now say I select " Location 3 ", once I finish all my entries, and then click " Submit " button, can it be sent to a separate table called " Location 3 " vice versa with " Location 2 " or " Location 1 "What I mean is I have 3 separate tables called location1, location2, location3..so once I select the appropriate location it will be saved in the appropriate table..??? Can this be done...
yup. if you google around, you will find out how in each way a form element populates itself in POST or GET. Dropdown's will be whatever name you give the select tag, with the corresponding value being whatever you set the value of the respective drop down elements (so the value will be the value of the value attribute you set in the option tags). note: the value passed over to POST/GET is not necessarily what has to be/is displayed on the website. (i.e. what a user sees). What you present to the user and what you give it as a value can be two different things.
Link to comment
Share on other sites

  • Replies 251
  • Created
  • Last Reply
yup. if you google around, you will find out how in each way a form element populates itself in POST or GET. Dropdown's will be whatever name you give the select tag, with the corresponding value being whatever you set the value of the respective drop down elements (so the value will be the value of the value attribute you set in the option tags). note: the value passed over to POST/GET is not necessarily what has to be/is displayed on the website. (i.e. what a user sees). What you present to the user and what you give it as a value can be two different things.
Cool..I will be making some test variations....before I make the adjustment to current project...Oh...one other question..in the input box where user/users insert data into the input field how can I make it larger to look like a big comment box...????For instance I have " Job Description " set as a mediumblog....so how can i make it so everyone see everything that is written(comments) into it..
Link to comment
Share on other sites

I think you are referring to a textarea.
Correct textarea..Would it be something like this?
<td>< input type='text' name='$field' size='65' maxlength='65' ></td>

Link to comment
Share on other sites

um, well no. it would need to be a textarea.http://www.w3schools.com/tags/tag_textarea.asp
Okay is this fine????
<input type="text" name="job_description" textarea rows="2" cols="20"/>

But it doesn't expand cause it is in a table..or that doesn't matter..if thats the case then the example code is wrong...

Link to comment
Share on other sites

This is a textarea:

<textarea rows="2" cols="20" name="name">At W3Schools you will find all the Web-building tutorials you need, from basic HTML to advanced XML, SQL, ASP, and PHP. </textarea>

You're still using an input tag, not a textarea tag.

Link to comment
Share on other sites

This is a textarea:
<textarea rows="2" cols="20" name="name">At W3Schools you will find all the Web-building tutorials you need, from basic HTML to advanced XML, SQL, ASP, and PHP. </textarea>

You're still using an input tag, not a textarea tag.

Okay
<td>Job Description:</td><td>				   <textarea rows="2" cols="20" name="job_description" /></td></tr>

but any code after this entry shows up in the textarea..I will search to see how to prevent that...thanksDisregard the above code its wrong..below is the answer...Okay never mind found the solution

td>Job Description:</td><td>				   <textarea rows="2" cols="20" name="job_description"></textarea></td></tr>

Thanks for leading in the right direction...

Link to comment
Share on other sites

Error: Unknown column 'managers_comments' in 'field list'Can't understand why getting this error??

<!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><?phpif (isset($_POST['id'])) {  	include('twal.php'); }$formValid = true;foreach($_POST as $key => $value){  if(empty($_POST[$key])){	$formValid = false;  };};if($formValid){  $con = mysql_connect("localhost","teamcomb_icc","1234dataman1234");  if (!$con){   die('Could not connect: ' . mysql_error());   };   	mysql_select_db("teamcomb_tecicc", $con);		$sql="INSERT INTO twal ( id, srnumber, tenant, floor, tower, job_description, employee, labour_cost, material_cost, tenant_contact, phone_number, date_twa_sent_to_tenant, date_twa_approved, date_parts_ordered, supplier, date_job_completed, date_billing_given_to_accounting, employee_comments, managers_comments,) values ('$_POST[id]','$_POST[srnumber]','$_POST[tenant]','$_POST[floor]','$_POST[tower]','$_POST[job_description]','$_POST[employee]','$_POST[labour_cost]','$_POST[material_cost]','$_POST[tenant_contact]','$_POST[phone_number]','$_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]','$_POST[employee_comments]','$_POST[managers_comments]')";	if (!mysql_query($sql,$con)){      die('Error: ' . mysql_error());   } echo "1 record added"; mysql_close($con);}else{echo ' Sorry, there was a problem with the form.  Please check all data entries, try again';}; ?> </body></html>

thanks..

Link to comment
Share on other sites

remove comma after managers_comments,) to managers_comments) and see what happens
Yea, it wasn't there before..I just added that a minute ago..but will check site script to see if its there...Edited:Okay just checked no " comma " after " managers_comments)
Link to comment
Share on other sites

it usually means the field/column name can't be found? check if the name is correct i.e 'manager_comments', or 'managers_comment', instead of 'managers_comments'
LOL...thanks you made me clear my mind..and doubled checked database table and found the field was spelt wrong..was manager_comments..now I've changed it to managers_comments...Thanks...another question on how the field " id " works..I have it displayed in the input form...does the user just add say the number " 1 " then here after it auto-increments..the next records added????thanks...
Link to comment
Share on other sites

if you left blank (done mentioning it in column list in insert query) or pass null to the id column it will auto incremented. you dont need to pass it manualy.

Link to comment
Share on other sites

if you left blank or pass null to the id column it will auto incremented. you dont need to pass it manualy.
So leaving it blank ..will still auto-increment it..am I right? which means I have to change script structure..because if one field left blank returns " error " to user to check data entries....
Link to comment
Share on other sites

yes, you have to match the column numbers specified and the data numbers. if you remove id column and the data it will increment it automaticaly. if id coulmn is auto_incrememnt constraint

$sql="INSERT INTO twal ( srnumber, tenant, floor, tower, job_description, employee, labour_cost, material_cost, tenant_contact, phone_number, date_twa_sent_to_tenant, date_twa_approved, date_parts_ordered, supplier, date_job_completed, date_billing_given_to_accounting, employee_comments, managers_comments,)values('$_POST[srnumber]','$_POST[tenant]','$_POST[floor]','$_POST[tower]','$_POST[job_description]','$_POST[employee]','$_POST[labour_cost]','$_POST[material_cost]','$_POST[tenant_contact]','$_POST[phone_number]','$_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]','$_POST[employee_comments]','$_POST[managers_comments]')";

Link to comment
Share on other sites

yes, you have to match the column numbers specified and the data numbers. if you remove id column and the data it will increment it automaticaly. if id coulmn is auto_incrememnt constraint
$sql="INSERT INTO twal ( srnumber, tenant, floor, tower, job_description, employee, labour_cost, material_cost, tenant_contact, phone_number, date_twa_sent_to_tenant, date_twa_approved, date_parts_ordered, supplier, date_job_completed, date_billing_given_to_accounting, employee_comments, managers_comments,)values('$_POST[srnumber]','$_POST[tenant]','$_POST[floor]','$_POST[tower]','$_POST[job_description]','$_POST[employee]','$_POST[labour_cost]','$_POST[material_cost]','$_POST[tenant_contact]','$_POST[phone_number]','$_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]','$_POST[employee_comments]','$_POST[managers_comments]')";

Hey thanks...I was wondering about that...I now have to remove it from the data input form..also...OKay..now as I am trying to learn all this I may ask question that may seem foolish..like this one..if I did this ... would this select only 1 row...to display..???
while($row = mysql_fetch_array($result(1))){

Thanks ...

Link to comment
Share on other sites

$row = mysql_fetch_array($result);echo $row['srnumber'].'<br/>';would only show the first result from SQL SELECT query, you can limit the number of results by using LIMIT in SQL query"SELECT * FROM mytable ORDER BY Name ASC LIMIT 5" will produce 5 record results IF 5 are found, when used with while loop.

Link to comment
Share on other sites

$row = mysql_fetch_array($result);echo $row['srnumber'].'<br/>';would only show the first result from SQL SELECT query, you can limit the number of results by using LIMIT in SQL query"SELECT * FROM mytable ORDER BY Name ASC LIMIT 5" will produce 5 record results IF 5 are found, when used with while loop.
So if I wanted to see only one record at a time it would read like this then???
"SELECT * FROM mytable ORDER BY Name ASC LIMIT 1"

Link to comment
Share on other sites

yes it is like so. You can use mysql_result() also which is used to fetch one row at a time from a resultset. It depends on the situation when the which is more effective.

Link to comment
Share on other sites

yes it is like so. You can use mysql_result() also which is used to fetch one row at a time from a resultset. It depends on the situation when the which is more effective.
okay thanks..another question now is can it be done to retrieve this record and as an form that can be edited..and then save back again to table.?????and if so what would be the starting script structure???
Link to comment
Share on other sites

okay thanks..another question now is can it be done to retrieve this record and as an form that can be edited..and then save back again to table.?????
Do you mean like a form where pre stored data will be shown and will be editable and then you can insert it back to DB? if so then you can fetch the data from database and then can insert those data into the <input> tags value attribute or in <textarea> innerhtml. Now you can insert it back to db the rest of the part about insertion is the same as you did before.
Link to comment
Share on other sites

Do you mean like a form where pre stored data will be shown and will be editable and then you can insert it back to DB? if so then you can fetch the data from database and then can insert those data into the <input> tags value attribute or in <textarea> innerhtml. Now you can insert it back to db the rest of the part about insertion is the same as you did before.
Okay thanks..I've should've been more clearer..yes say a record has to be corrected so it would have to be retrieved and corrected, then saved...
Link to comment
Share on other sites

what he's saying is if you get a record ahead of time, you can pre-populate your form with the data you are given back from mysql_query, which a user can then see and edit, and then will be saved back into the database when they submit the form. How you get a specific record in the first place depends on the nature of your application.

Link to comment
Share on other sites

Trying to display this in a html table..and get this error??" Parse error: syntax error, unexpected T_ECHO in C:\xampp\htdocs\icc\display.php on line 36 "Here is the code..

<html><style type="text/css">table {  border: 2px solid red;  background-color: #FFC;  } th{	border-bottom: 5px solid #000;	}td{   border-bottom: 2px solid #666;   }</style><head><title>Display Data</title></head><body><h1>Display Data</h1><?php//include("connect.php");$con = mysql_connect("localhost","root",""); if (!$con)   {   die('Could not connect: ' . mysql_error());   } mysql_select_db("tecicc", $con);$result = mysql_query("SELECT * FROM twal ORDER BY ID");$sqlget ="SELECT * From twal";$sqldata = mysqli_query($dbcon, $sqlget) or die (' error getting data ')echo "<table>";echo "<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($row =mysqli_fetch_array($sqldata, MYSQLI_ASSOC)){	 	 echo "<tr><td>";	 echo $row['id'];	 echo"</td><td>";	 echo $row['srnumber'];	 echo"</td><td>";	 echo $row['tenant'];	 echo"</td><td>";	 echo $row['floor'];	 echo"</td><td>";	 echo $row['tower'];	 echo"</td><td>";		 echo $row['job_description'];	 echo"</td><td>";	 echo $row['employee'];	 echo"</td><td>";	 echo $row['labour_cost'];	 echo"</td><td>";	 	 echo $row['material_cost'];	 echo"</td><td>";	 	 	 echo $row['tenant_contact'];	 echo"</td><td>";	 	 echo $row['phone_number'];	 echo"</td><td>";	 	 echo $row['date_twa_sent_to_tenant'];	 echo"</td><td>";	 	 echo $row['date_twa_approved'];	 echo"</td><td>";	 	 echo $row['date_parts_ordered'];	 echo"</td><td>";	 	 echo $row['supplier'];	 echo"</td><td>";		 echo $row['date_job_completed'];	 echo"</td><td>";	 	 echo $row['date_billing_given_to_accounting'];	 echo"</td><td>";	 	 	 echo $row['employee_comments'];	 echo"</td><td>";	 	 echo $row['manager_comments'];	 echo"</td></tr>";		 }echo "</table>";	 ?>

thanks..

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...