| | |
need help in php forms..plz
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Dec 2008
Posts: 20
Reputation:
Solved Threads: 1
<?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> -- Manish Singh
manish.s@neuralit.com
manish.s@neuralit.com
•
•
Join Date: Dec 2008
Posts: 38
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Dec 2008
Posts: 20
Reputation:
Solved Threads: 1
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.
-- Manish Singh
manish.s@neuralit.com
manish.s@neuralit.com
•
•
Join Date: Dec 2008
Posts: 38
Reputation:
Solved Threads: 0
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...
what i mean is when user submit the form it will submited to test@test.com...
thanks man for ur time...
•
•
Join Date: Dec 2008
Posts: 20
Reputation:
Solved Threads: 1
<?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";
}
?> -- Manish Singh
manish.s@neuralit.com
manish.s@neuralit.com
![]() |
Similar Threads
- How can fix the problem? (JavaScript / DHTML / AJAX)
Other Threads in the PHP Forum
- Previous Thread: DIV Help
- Next Thread: Urgently need -php script for searching image
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken button cakephp checkbox class cms code compression cron curl database date directory display download dropdown dynamic echo email error file files folder form forms function functions google href htaccess html httppost image include insert integration ip java javascript joomla limit link login loop mail md5 menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search secure server sessions sms soap source space sql structure syntax system table tutorial undefined update upload url validation validator variable video virus votedown web xml youtube





