943,744 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1201
  • PHP RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Dec 23rd, 2008
0

Re: need help in php forms..plz

<?php

if($_POST['submit'] == "Submit")
{
	$textbox = $_POST['textfield'];
	
	if(is_array($textbox))
	{
		foreach($textbox as $textkey=>$textvalue)
		{
			$textvalue = trim($textvalue);
			
			if($textvalue <> "")
			{
				//your insert query......
			}
		}
	}
	
}

?>
<html>
	<head>
		<script language="JavaScript">
			function make_textbox(no)
			{ 
				if(no < 1)
				  return false;
				  
				var my_textbox = "";
				
				for(var i=0;i<no;i++)
				{
					my_textbox += "<br>Text Box "+eval(i+1)+": <input type='text' name='textfield["+i+"]'>";
				}
				
				document.getElementById("text_id").innerHTML = my_textbox;
			}
				
		</script>
	</head>
			
	<body>
			
			<form name="myfrm" method="POST">
				
				Select Number Of TextBox : <select name="select_num_text" onChange="javascript:make_textbox(this.value);">
					<option value="">Select</option>
					<?php
					
						for($i=3;$i<=40;$i++)
						{
							echo "<option value='".$i."'>".$i."</option>";
						}
					?>
				</select>
				<br>
				<div id="text_id"></div>
				<input type="submit" name="submit" value="Submit">
			</form>
	</body>
</html>
Reputation Points: 10
Solved Threads: 5
Light Poster
manish.s is offline Offline
29 posts
since Dec 2008
Dec 23rd, 2008
0

Re: need help in php forms..plz

i just want to to add the enterd value in the input boxs to simble table where the it only store the vlue of the data enterd
Reputation Points: 10
Solved Threads: 0
Light Poster
wwwmadeasy is offline Offline
38 posts
since Dec 2008
Dec 23rd, 2008
0

Re: need help in php forms..plz

manish i am really thanks full to u but what if there is other fields is the code going to be disturbed

like

if i want to submit to data base the flowing:

Name (input field)
Email (input field)
Contact No (input field)
Number of cars you want to insure (this the drop box)
and if the user select from the drop down 4 the 4 input text will appear and then he will put the car registration numbers and when he press submit button the name will store in name colum in the database and email and contact no it will also and then each value of the text box will store in it is coulm like car 1 with regestation numer and the car2 with regestation number and so on

is that possible? thanks man u helped me a lot
Reputation Points: 10
Solved Threads: 0
Light Poster
wwwmadeasy is offline Offline
38 posts
since Dec 2008
Dec 23rd, 2008
0

Re: need help in php forms..plz

I think you will have to make two tables (use normalization of table)

1. car_owner

id (primary key, Auto incr.)
name
email
contact

2. car_registration

id (primary key , Auto incr.)
owner_id (foreign key)
reg_no



<?php

if($_POST['submit'] == "Submit")
{
	
	$name = $_POST['name'];
	$email = $_POST['email'];
	$contact = $_POST['contact'];
	$textbox = $_POST['textfield'];
	
	$query = "insert into car_owner(name,email,contact) values ('".$name."','".$email."','".$contcat."') ";
	 mysql_query($query);
	
	$last_insert_id = mysql_insert_id();
	
	
	if(is_array($textbox))
	{
		foreach($textbox as $textvalue)
		{
			$textvalue = trim($textvalue);
			
			if($textvalue <> "")
			{
				$sub_query = "insert into car_registration(owner_id,reg_no) values('".$last_insert_id."','".$textvalue."') ";
				mysql_query($sub_query);
			}
		}
	}
	
}

?>



NOTE :

1. if you have 50 text boxes and user will fill only one text box.
rest of 49 will be wastage of storage.

2. Later if u want to display 55 boxes, then no need to change in code only increase $i<=55.
Last edited by manish.s; Dec 23rd, 2008 at 6:37 pm.
Reputation Points: 10
Solved Threads: 5
Light Poster
manish.s is offline Offline
29 posts
since Dec 2008
Dec 23rd, 2008
0

Re: need help in php forms..plz

Manish Singh thanks for reply u were very help full i will try that and i will let u know
Reputation Points: 10
Solved Threads: 0
Light Poster
wwwmadeasy is offline Offline
38 posts
since Dec 2008
Dec 24th, 2008
0

Re: need help in php forms..plz

Manish Singh what if i want to use these values to send an email...

what i mean is when user submit the form it will submited to test@test.com...

thanks man for ur time...
Reputation Points: 10
Solved Threads: 0
Light Poster
wwwmadeasy is offline Offline
38 posts
since Dec 2008
Dec 24th, 2008
0

Re: need help in php forms..plz

<?php


if($_POST['submit'] == "Submit")
{

	$name = $_POST['name'];
	$email = $_POST['email'];
	$contact = $_POST['contact'];
	$textbox = $_POST['textfield'];
	
	
	$mail_body = "<html><body>";
	$mail_body .= "<b>Name : </b>".$name;
	$mail_body .= "<br><b>Email : </b>".$email;
	$mail_body .= "<br><b>Contact : </b>".$contact;
	
	
	$query = "insert into car_owner(name,email,contact) values ('".$name."','".$email."','".$contcat."') ";
	 mysql_query($query);
	
	$last_insert_id = mysql_insert_id();
	
	$cnt = 1;
	
	if(is_array($textbox))
	{
		foreach($textbox as $textvalue)
		{
			$textvalue = trim($textvalue);
			
			if($textvalue <> "")
			{
				$mail_body .= "<br><b>Registration No ".$cnt." : </b>".$textvalue;
				$cnt ++;
			}
		}
	}
	
	
	$mail_to = "manish.s@neuralit.com"; //mail id to whom you r sending mail
	$mail_to_name = "Manish Singh"; //Name to whom you r sending mail
	$subject = "Your subject";
	
	$mail_from = "from@test.com"; //Sender mail id
	$mail_from_name = "FROM"; //Sender name
	
	// To send HTML mail, the Content-type header must be set
	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
	

	// Additional headers
	$headers .= 'To: '.$mail_to_name.' <'.$mail_to.'>' . "\r\n";
	$headers .= 'From: '.$mail_from_name.' <'.$mail_from.'>' . "\r\n";
	$headers .= 'Reply-To: '.$mail_from_name.' <'.$mail_from.'>'."\r\n";

	// Mail it
	if(mail($mail_to, $subject, $mail_body, $headers))
		echo "mail sent successfully.....";
	else
		echo "Error!! while sending mail";
	
}

?>
Reputation Points: 10
Solved Threads: 5
Light Poster
manish.s is offline Offline
29 posts
since Dec 2008
Dec 26th, 2008
0

Re: need help in php forms..plz

Manish Singh.....hope u ok ..i have other problem, what if i want to add 2 text box instead of one..what i mean when the user select 5 ,5box will appear but in one line it will ask him his first name and last name and how i can submit these to email like the what u did in the previous code.....
Reputation Points: 10
Solved Threads: 0
Light Poster
wwwmadeasy is offline Offline
38 posts
since Dec 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: DIV Help
Next Thread in PHP Forum Timeline: Urgently need -php script for searching image





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC