hello I want to insert my value to the database here my structure .
<tr>
<td>
<b>Vendredi</b> </br><?php echo $date6 ?>
</td>
<td>
<input size="10" type="text" id="projvendredi" name="projvendredi"onkeypress="return handleEnter6(event, this, 'task');"/>
</td>
<td>
<input type="text" name="clientvendredi" class = "client" size="12" id ="clientvendredi" disabled />
</td>
<td>
<input type="text" name="projdesvendredi" size="30" class "desc" id ="projdesvendredi"disabled />
</td>
<td>
<span id="calculTemps5">
<input id="input6" class= "temps" type="number" name="tempsv" size="2" min="0" max="24" value="0" /></br>
</span>
</td>
</tr>
and here my button
<input type="text" id="result" readonly="readonly" name="total" />
<input type="submit" value="Terminé" id="end" />
<input type="hidden" name="data" value="<?php echo $date; ?>" />
</p>
</form>
Here is my insert.php
$date = $_POST['data'] ;
if (isSet($_POST['descprojsam']))
{
$descprojsam = $_POST['descprojsam'] ;
echo($descprojsam);
}
echo($date);
// Connect to the DB
$link = mysqli_connect("localhost","root","","cruel") or die("Error " . mysqli_error($link));
// adding new recherche
if(!empty($_POST['descprojsam']))
{
$sql = " INSERT INTO `projetstaches`(`prtId`, `prtTimeSheetId`, `prtProjetNum`, `prtDate`, `prtTaskId`, `prtTime`, `prtLocation`, `prtDescription`)
([value-1],[value-2],[value-3],[value-4],[value-5],[value-6],[value-7],'$descprojsam')";
$link->query($sql);
}
?>
I've not finish my insert cause i don't know how really to do it. I have 7 days so I gave you my friday for exemple.
PHP is case sensative, isSet($_POST['descprojsam']) should be isset($_POST['descprojsam'])
Related
Hello Everyone,
i have built one basic HTML form using PHP for submitting data in one database table, list of variable that i use in my database table are
id, a1, a2, a3, a, a4, a5, a6, date, color, today
and i am using below HTML form to submit data in my database table
<form method="post" action="" autocomplete="off">
TODAY: <input type="text" name="today" size="5" value="<?php $theDate = date("d/m/y"); echo " $theDate"; ?>"><br>
DATE:<input type="text" name="date" size="5" align="absmiddle" value="<?php
$current_dayname = date("l");
echo $date = date("d/m/y",strtotime('monday next week')).' <br>to<br> '.date("d/m/y",strtotime("sunday next week"));
?>">
<table><tr><td><input type="text" name="a1" size="1" value="<?php echo $query2['a1']; ?>">
<input type="text" name="a2" size="1" value="<?php echo $query2['a2']; ?>">
<input type="text" name="a3" size="1" value="<?php echo $query2['a3']; ?>"></td><td>
<input type="text" name="a" size="2" value="<?php echo $query2['a']; ?>"></td><td>
<input type="text" name="a4" size="1" value="<?php echo $query2['a4']; ?>">
<input type="text" name="a5" size="1" value="<?php echo $query2['a5']; ?>">
<input type="text" name="a6" size="1" value="<?php echo $query2['a6']; ?>"></td></tr></table>
<input type="submit" name="submit">
now the issue is that i have to use three input field for values a1,a2,a3 and also for a4,a5,a6 and i want to use only one input field for these variables, so that it is easy to enter values in it..
also check image of my HTML form code
And I Want HTML form looks like below after modification:
can anyone help me in order to combine these input fields
thanks
Try this code.
It works for me(array elements can have string datatype ('words') and numeric (3, 3.4324)):
<form method="post" action="" autocomplete="off">
TODAY: <input type="text" name="today" size="5" value="<?php $theDate = date("d/m/y"); echo " $theDate"; ?>"><br>
DATE:<input type="text" name="date" size="5" align="absmiddle" value="<?php
$current_dayname = date("l");
echo $date = date("d/m/y",strtotime('monday next week')).' <br>to<br> '.date("d/m/y",strtotime("sunday next week"));
?>">
<?php if(is_string($query2['a1']) || is_numeric($query2['a1'])
&& is_string($query2['a2']) || is_numeric($query2['a2'])
&& is_string($query2['a3']) || is_numeric($query2['a3'])
&& is_string($query2['a4']) || is_numeric($query2['a4'])
&& is_string($query2['a5']) || is_numeric($query2['a5'])
&& is_string($query2['a6']) || is_numeric($query2['a6'])
&& is_string($query2['a']) || is_numeric($query2['a'])): ?>
<table>
<tr>
<td>
<input type="text" name="a1a2a3" size="3" value="<?= $query2['a1'].$query2['a2'].$query2['a3']; ?>">
</td>
<td>
<input type="text" name="a" size="2" value="<?= $query2['a']; ?>">
</td>
<td>
<input type="text" name="a4a5a6" size="3" value="<?= $query2['a4'].$query2['a5'].$query2['a6']; ?>">
</td>
</tr>
</table>
<?php endif; ?>
<input type="submit" name="submit">
this code in php gen for getting HTML snippet below
<form method="post" action="" autocomplete="off">
TODAY: <input type="text" name="today" size="5" value=" 11/10/19"><br>
DATE:<input type="text" name="date" size="5" align="absmiddle" value="14/10/19 <br>to<br> 20/10/19">
<table>
<tr>
<td>
<input type="text" name="a1a2a3" size="3" value="a1a2a3">
</td>
<td>
<input type="text" name="a" size="2" value="ww">
</td>
<td>
<input type="text" name="a4a5a6" size="3" value="a456">
</td>
</tr>
</table>
<input type="submit" name="submit">
I had tried to insert bulk data with same name field contains multiple rows. But only single row is inserted.
How to insert bulk data as different values to insert into the database.
INSERT INTO table_name (username, luck_number, test, tester) VALUES (('$username', '$luck_number', '$test', '$tester').
<tr>
<td>1</td>
<input type="hidden" name="username" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number" value="" />
</td>
<td>
<input type="text" name="big" value="" />
</td>
<td>
<input type="text" name="test" value="" />
</td>
<td>
<input type="text" name="tester" value="" />
</td>
</tr>
<tr>
<td>2</td>
<input type="hidden" name="username" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number" value="" />
</td>
<td>
<input type="text" name="big" value="" />
</td>
<td>
<input type="text" name="test" value="" />
</td>
<td>
<input type="text" name="tester" value="" />
</td>
</tr>
<tr>
<td>3</td>
<input type="hidden" name="username" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number" value="" />
</td>
<td>
<input type="text" name="big" value="" />
</td>
<td>
<input type="text" name="test" value="" />
</td>
<td>
<input type="text" name="tester" value="" />
</td>
</tr>
#nisha,In your scenario only single row is inserted because variables are same name so it's overridden, Please try below code, It will give you array of fields so you can easily create for-loop & do multiple insert with your query.
<form method="post" name="userdata">
<tr>
<td>1</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<tr>
<td>2</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<tr>
<td>3</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<input type="submit" name="submit">
</form>
**Note:**you can worry about the security issue letter. read the answer with the comment.
Store them in array by adding [ ] this in your input field
<tr>
<td>1</td>
<form action="" method="POST">
<input type="hidden" name="username" value="<?php echo $login_session; ?>"/>
<td><input type="text" name="luck_number[]" value=""/></td>
<td><input type="text" name="big[]" value=""/></td>
<td><input type="text" name="test[]" value=""/></td>
<td><input type="text" name="tester[]" value=""/></td>
</tr>
<tr>
<td>2</td>
<input type="hidden" name="username" value="<?php echo $login_session; ?>"/>
<td><input type="text" name="luck_number[]" value=""/></td>
<td><input type="text" name="big[]" value=""/></td>
<td><input type="text" name="test[]" value=""/></td>
<td><input type="text" name="tester[]" value=""/></td>
</tr>
<tr>
<td>3</td>
<input type="hidden" name="username" value="<?php echo $login_session; ?>"/>
<td><input type="text" name="luck_number[]" value=""/></td>
<td><input type="text" name="big[]" value=""/></td>
<td><input type="text" name="test[]" value=""/></td>
<td><input type="text" name="tester[]" value=""/></td>
</tr>
<tr></td><input type="submit" name="submit" value="submit"/><tr></td>
</form>
<?php
//connect with your database
for($i=0;$i<count($_POST['luck_number']);$i++)
{
//set the value for variable
$luck_number=$_POST['luck_number'][$i];
$test=$_POST['test'][$i];
$tester=$_POST['tester'][$i];
//run your query
//INSERT INTO table_name (username, luck_number, test, tester) VALUES (('$username', '$luck_number', '$test', '$tester').
}
First of all change all field names by adding [] at the end.
Second step, to parsing all values you may use something like this
for($i=0; $i < $count($_GET['username']); $i++)
{
$username = $_GET['username'][$i];
$luck_number= $_GET['luck_number'][$i];
$big= $_GET['big'][$i];
$test= $_GET['test'][$i];
$tester= $_GET['tester'][$i];
// insert into database
}
The reason of inserting single row instead of multiple rows is your input field name. You are using same name in different input field so when the server gets the reply it replace the duplicate name and the last occurrence is outputted.
The thing you have to do is to use array. If you use known number of rows then you can simply use a for loop to insert data.
<tr>
<td>1</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<tr>
<td>2</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<tr>
<td>3</td>
<input type="hidden" name="username[]" value="<?php echo $login_session; ?>" />
<td>
<input type="text" name="luck_number[]" value="" />
</td>
<td>
<input type="text" name="big[]" value="" />
</td>
<td>
<input type="text" name="test[]" value="" />
</td>
<td>
<input type="text" name="tester[]" value="" />
</td>
</tr>
<?php
for ($i=0; $i<count($_POST['username']); $i++)
{
mysql_query("INSERT INTO table_name (`username`, `luck_number`, `test`, `tester`) VALUES (('".$_POST['username'][$i]."', '".$_POST['luck_number'][$i]."', '".$_POST['test'][$i]."', '".$_POST['tester'][$i]."')");
}
?>
Note: Sanitizing variable is always been a good practice and strongly recommended.
Hi,
I have a form and I want to insert its values into a MySQL database without refreshing the form and losing its values.
By clicking on the 'print' button the user should be able to generate a report from the data they entered in the form, but the form keeps refreshing on submit. So I would like to know how I can store the data in the database without having the form refreshed (i.e. using Ajax)?
Below is my form code:
<div class="commentpost"></div>
<form name="entry" id="entry" method="POST" action="">
<table border="1" bgcolor="Silver">
<tr>
<td>
</td>
<td>
<h2><b>Candidate Entry</b><h2>
</td>
</tr>
<tr>
<td>
Code
</td>
<td>
<input type="text" name="vouchno" value="New" onkeypress="return isNumberKey(event)" readonly="readonly" size="8" maxlength="8">
Date
<input type="text" id="vouchdt" name="vouchdt" id="popupDatepicker" tabindex="1" value="<?php echo (isset($_POST['vouchdt']) ? $_POST['vouchdt'] : ''); ?>"></td>
<td>
<input type="text" id='councode' name="councode" size="1" maxlength="2" value="<?php echo (isset($_POST['councode']) ? $_POST['councode'] : ''); ?>"><input type="text" id="counvouch" name="counvouch" size="8" value="<?php echo (isset($_POST['counvouch']) ? $_POST['counvouch'] : ''); ?>" maxlength="8">
<div id="cam">
</div>
<input type=button value="Configure..." onClick="webcam.configure()">
<input type=button value="Take Snapshot" onClick="take_snapshot()">
<div id="upload_results" style="background-color:#eee;"></div>
</td>
</tr>
<tr>
<td>
Name
</td>
<td>
<input type="text" id="name" name="name" value="<?php echo (isset($_POST['name']) ? $_POST['name'] : ''); ?>" maxlength="40" size="45" tabindex="2">
</td>
</tr>
<tr>
<td>
Address
</td>
<td>
<textarea name="add" id="add" row="3" cols="40" tabindex="3">
<?php echo (isset($_POST['vouchdt']) ? $_POST['vouchdt'] : ''); ?>
</textarea>
</td>
</tr>
<tr>
<td>
City
</td>
<td>
<input type="text" id="city" name="city" size="20" maxlength="20" value="<?php echo (isset($_POST['city']) ? $_POST['city'] : ''); ?>" tabindex="4">
Pin
<input type="text" id="pin" name="pin" size="6" maxlength="6" value="<?php echo (isset($_POST['pin']) ? $_POST['pin'] : ''); ?>" tabindex="5">
</td>
</tr>
<tr>
<td>
Nationality
</td>
<td>
<input type="text" id="ntn" name="ntn" value="<?php echo (isset($_POST['ntn']) ? $_POST['ntn'] : ''); ?>" size="10" maxlength="10" tabindex="6">
</td>
</tr>
<tr>
<td>
Mobile No
</td>
<td>
<input type="text" id="mob" name="mob" value="<?php echo (isset($_POST['mob']) ? $_POST['mob'] : ''); ?>" tabindex="7">
</td>
</tr>
<tr>
<td>
Date of Birth
</td>
<td>
<input type="text" id="dob" name="dob" value="<?php echo (isset($_POST['dob']) ? $_POST['dob'] : ''); ?>" id="popupDatepicker2" tabindex="8">
</td>
<td>
Age
</td>
<td width="9px">
<input type="text" id="age" name="age" size="3" maxlength="3" value="<?php echo (isset($_POST['age']) ? $_POST['age'] : ''); ?>" tabindex="9">
</td>
<td width="10px">
Sex
</td>
<td>
<select id="sex" name="sex" tabindex="12">
<?php
if(isset($_POST[sex])==m){
?>
<option value="<?php echo (isset($_POST['sex']) ? $_POST['sex'] : ''); ?>">Male</option>":
<?php }else{?>
<option value="<?php echo (isset($_POST['sex']) ? $_POST['sex'] : ''); ?>">Female</option>":
<?php }?>
<option value="m">Male</option>
<option value="f">Female</option>
</select>
</td>
</tr>
<tr>
<td>
Religion
</td>
<td>
<input type="text" id="rel" name="rel" value="<?php echo (isset($_POST['rel']) ? $_POST['rel'] : ''); ?>" size="20" maxlength="20" tabindex="11">
</td>
<td>
Martial Status
</td>
<td>
<select id ="status" name="status" tabindex="12">
<option value="">--select--</option>
<option value="1">Married</option>
<option value="2">Unmarried</option>
</select>
</td>
</tr>
<tr>
<td>
Passport No.
</td>
<td>
<input type="text" id="pass" name="pass" value="" size="15" maxlength="15" tabindex="13">
</td>
<td>
Place of Issue
</td>
<td>
<input type="text" id="poi" name="poi" size="20" maxlenght-20 tabindex="14">
</td>
<td>
Date of Issue
</td>
<td>
<input type="text" id="doi" name="doi" id="popupDatepicker4" tabindex="15">
</td>
</tr>
<tr>
<td>
Profession
</td>
<td>
<input type="text" id="prof" name="prof" size="20" maxlenght="20" value="" tabindex="16">
</td>
<td>
Amount
</td>
<td>
<input type="text" id="amt" name="amt" value="" size ="8" onblur="calculateText()" style="background-color:transparent; color:blue; text-align:right" tabindex="17">
</td>
</tr>
<tr>
<td>
Payment
</td>
<td>
<select id="pay" name="pay" tabindex="12">
<option value="">--select--</option>
<option value="f">Full</option>
<option value="p">Part</option>
<option value="n">None</option>
</select>
</td>
<td>
Received
</td>
<td>
<input type="text" id="resc" name="resc" value="" size ="8" onblur="calculateText()" style="background-color:transparent; color:green; text-align:right" tabindex="18">
</td>
</tr>
<tr>
<td>
Agent
</td>
<td>
<input type="tetx" id="agnt" name="agnt" value="" size="40" maxlength="40" tabindex="21">
</td>
<td>
Balance
</td>
<td>
<input type="text" id="bal" name="bal" readonly="readonly" value="" size ="8" style="background-color:transparent; color:red; text-align:right" onblur="calculateText()" tabindex="19">
</td>
</tr>
<tr>
<td>
Mofa No.
</td>
<td>
<input type="text" id="mofa" name="mofa" value="" size="20" maxlength="20" tabindex="22">
</td>
</tr>
<tr>
<td>
Remarks
</td>
<td>
<input type="text" id="rem" name="rem" size="60" maxlength="60" value="" tabindex="23">
</td>
</tr>
<table border="0" align="center">
<tr>
<td>
<input type="submit" name="save" value="Save"><input type="hidden" name="task" value="addComments" />
<td>
<input type="submit" name="print" value="Print">
</td>
<td>
<input type="submit" name="close" value="Cancel">
</td>
<td>
<input type="reset" name="Add" value="Add">
</td>
</tr>
</table>
</table>
</form>
</body>
</html>
Here is my JavaScript code:
<script type="text/javascript">
jQuery(document).ready(function($){
$("#entry").submit(function(){
ctask = this.task.value;
cvouchdt = this.vouchdt.value;
ccouncde = this.councode.value;
ccounvouch = this.counvouch.value;
cname = this.name.value;
ccity = this.city.value;
cpin = this.pin.value;
cntn = this.ntn.value;
cmob = this.mob.value;
cdob = this.dob.value;
cage = this.age.value;
csex = this.sex.value;
crel = this.rel.value;
cstatus = this.status.value;
cpass = this.pass.value;
crel = this.rel.value;
cpoi = this.poi.value;
cdoi = this.doi.value;
cprof = this.prof.value;
camt = this.amt.value;
cpay = this.pay.value;
cpass = this.pass.value;
crecd = this.recd.value;
cagnt = this.agnt.value;
cbal = this.bal.value;
cmofa = this.mofa.value;
crem = this.rem.value;
save = this.save;
if(cname=="" || ccounvouch=="" || ccouncde=="") { $("#errAll").html('<p>Invalid Captcha. Please try again.</p>'); }
$.post("submit.php", {task: ctask, name: cname, email: cemail, url: curl, message: cmessage}, function(data){
if(data=='0') { $("#errAll").html('<p>Please don\'t leave the requierd fields.</p>'); }
else if(data=='1') { $("#errAll").html('<p>Invalid Email Address, Please try again.</p>'); }
else { submitter.value="Value Saved"; save.disabled=false;} //$(data).appendTo($(".commentpost")); }
});
return false;
});
});
</script>
Here is my PHP code:
<?php
//include_once( 'config.php' );
require("includes/dbconnect.php");
$getmaxvou = mysql_query("SELECT MAX(`vouchno`) as `maxid` FROM `candidate` ") or die(mysql_error());
$max = mysql_fetch_array($getmaxvou);
$maxv =$max["maxid"]+1;
if(isset($_POST['task']) && $_POST['task'] == 'addComments')
{
$a = 1;
$date = mysql_real_escape_string($_POST["vouchdt"]);
$date = strtotime($date);
$date = date('Y-m-d',$date);
$cname = trim($_POST["name"]);
$add = trim($_POST["add"]);
$city = trim($_POST["city"]);
$pin = trim($_POST["pin"]);
$nations = trim($_POST["ntn"]);
$mob = trim($_POST["mob"]);
$dob = mysql_real_escape_string($_POST["dob"]);
$dob = strtotime($dob);
$dob = date('Y-m-d',$dob);
$age = trim($_POST["age"]);
$sex = trim($_POST["sex"]);
$rel = trim($_POST["rel"]);
$pass = trim($_POST["pass"]);
$status = trim($_POST["status"]);
$poi = trim($_POST["poi"]);
$doi = mysql_real_escape_string($_POST["doi"]);
$doi = strtotime($doi);
$doi = date('Y-m-d',$doi);
$prof = trim($_POST["prof"]);
$amt = trim($_POST["amt"]);
$pay = trim($_POST["pay"]);
$bal = trim($_POST["bal"]);
$recd = trim($_POST["resc"]);
$agnt = trim($_POST["agnt"]);
$mofa = trim($_POST["mofa"]);
$rem = trim($_POST["rem"]);
$councode = trim($_POST["councode"]);
$counvouch = trim($_POST["counvouch"]);
{
if (isset($_POST["code"])) {
$sql_check = mysql_query("SELECT * FROM candiidate WHERE code ='$councode' AND counvouch='$counvouch'");
if (mysql_num_rows($sql_check) > 0) {
$a = 0;
print '<script type="text/javascript">';
print 'alert("Code Already Exist For the Country")';
PRINT '</script>';
}
}
if($a ==1){
mysql_query("INSERT INTO `candidate`(vouchno, vouchdt, `name`, `add`, `city`, `pin`, `nationality`, mobile, dob, `religion`, `passport`, `profession`, amt, recd, bal, payment, `agent`, `mofa`, `age`, `gender`, `martial`, `poi`, doi, councode, counvouch, `rem` )
Values
('$maxv', '$date', '$cname', '$add', '$city', '$pin', '$nations', '$mob', '$dob', '$rel', '$pass', '$prof', '$amt', '$recd', '$bal', '$pay', '$agnt', '$mofa', '$age', '$sex', '$status', '$poi', '$doi', '$councode', '$counvouch', '$rem' )") or die(mysql_error());
echo ' <div class="commentbox">
<div class="commentboxt">Value Inserted </div>
</div>';
}
}
}?>
Change form tag to
<form name="entry" id="entry" method="GET" action="javascript:">
that will stop the page from refreshing.
Then look into jquery ajax http://api.jquery.com/jQuery.ajax/
For example.
var string ="FORMVALUE1=" + $('#FORMVALUE1ID').val() + "FORMVALUE2=" + $('#FORMVALUE2ID').val() + "REAPEAT FOR ALL YOUR VALUES";
$.ajax({
type: "GET",
url: "YOURPHPFILE.php",
data: string,
});
Then just get the form values in the php file by using $_GET['FORMVALUE1'];
You first seperate your PHP file where you insert or do some action.
PHP Action File: YourPHPPostFile.php
HTML File: index.html or whatever name you have.
Then in PHP file write all your code but in the begining add check that is
if(isset($_POST['task']) && $_POST['task'] == 'addComments')
{//Your all PHP Code here}
On the other hand in your html file make a AJAX request to this file and use POST Method in AJAX request and include your data within Request Parameters.
One more thing if you don't want to lose your Form data which is filled you can use:
<form name="entry" id="entry" method="GET" onsubmit="calltoAjax();return false;">
Now whenever user submit form then it will not reset the form and data also stored in your database.
Thanks,
well, now, i created a form, and this is it:
<html>
<body bgcolor="lightblue">
<form align="center" action="connect2.php" method="post" style="bgcolor:red">
<div style="margin-left:433px" >
Registration No.: <input type="text" name="reg" /><br />
</div>
</br>
Name: <input type="text" name="name" size="50" style="margin-left:7px" />
<span style="margin-left:6px">
Date of Birth: <input type="text" name="birth" size="30" /></br>
</span>
<div style="margin-left:12px">
Age: <input type="text" name="age" size="15" style="margin-left:7px" />
<span style="margin-left:167px">
Class at August 2012 <input type="text" name="class" size="30" />
</span>
</div>
School: <input type="text" name="school" size="102" style="margin-left:5px" />
</br></br>
Father's Name: <input type="text" name="father" size="94" style="margin-left:5px" /> </br>
Father's Occupation: <input type="text" name="focc" size="89" />
</br></br>
Mother's Name:<input type="text" name="mother" size="94" style="margin-left:3px" /> </br>
Mother's Occupation: <input type="text" name="mocc" size="88" />
</br></br>
<center>
<table bgcolor="pink" width="95" height="100"style="margin-left:0px; margin-top:5px" border="0">
<tr>
<td colspan="3">
Siblings, if any:
</td>
</tr>
<tr align="center"style="font-weight:bold">
<td width="5"></td>
<td width="20">Name</td>
<td width="50">Age</td>
<td width="20">School</td>
</tr>
<tr align="right">
<td>1.</td>
<td align="center"><input type="text" name="ssname" size="44" /></td>
<td align="center"><input type="text" name="sage1" size="5" /></td>
<td align="center"><input type="text" name="sschool1" size="44" /></td>
</tr>
<tr align="right">
<td>2.</td>
<td align="center"><input type="text" name="sname2" size="44" /></td>
<td align="center"><input type="text" name="sage2" size="5" /></td>
<td align="center"><input type="text" name="sschool2" size="44" /></td>
</tr>
<tr align="right">
<td >3.</td>
<td align="center"><input type="text" name="sname3" size="44" /></td>
<td align="center"><input type="text" name="sage3" size="5" /></td>
<td align="center"><input type="text" name="sschool3" size="44" /></td>
</tr>
</table>
</center>
</br>
Address: <input type="text" name="address" size="101" /> </br>
<p align="left" style="margin-left:271px">
Phone Number: <input type="text" name="phone" size="20" /> </br>
Cell Number (Mother/Father): <input type="text" name="cp" size="20" /></br>
Email (Mother/Father): <input type="text" name="email" size="28"/>
</p>
<input type="Submit" name="submit" value="submit" />
</form>
</body>
</html>
and then this is my php code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<body>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sy_database", $con);
$sq$sql="INSERT INTO sy_form (reg_no, name, birth, age, sclass, school, fname, focc, mname, mocc, address, phone, cp, email)
VALUES('$_POST[reg]','$_POST[name]','$_POST[birth]','$_POST[age]','$_POST[class]','$_POST[school]','$_POST[fname]','$_POST[focc]','$_POST[mname]','$_POST[mocc]','$_POST[address]','$_POST[phone]','$_POST[cp]','$_POST[email]'),
INSERT INTO siblings(sname,sage,sschool) values('$_POST[ssname]','$_POST[sage1]','$_POST[sschool1]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
</body>
</html>
i need to insert data into two tables from that single form.
the 1st table are for the person who wants to register and the second is for the siblings of that person.
and how come that the AGE won't appear? and the class at january does not appear also.
cellphone number would always be 2147483647?
gawd, I'm so ruined!
could anyone please help me with this? i really want to learn. :(
Ahh, you can't merge queries like that. Try following
$sql1="INSERT INTO sy_form (reg_no, name, birth, age, sclass, school, fname, focc, mname, mocc, address, phone, cp, email)".
"VALUES('$_POST[reg]','$_POST[name]','$_POST[birth]','$_POST[age]','$_POST[class]','$_POST[school]','$_POST[fname]','$_POST[focc]','$_POST[mname]','$_POST[mocc]','$_POST[address]','$_POST[phone]','$_POST[cp]','$_POST[email]')";
$sql2="INSERT INTO siblings(sname,sage,sschool)values('$_POST[ssname]','$_POST[sage1]','$_POST[sschool1]')";
if (!mysql_query($sql1,$con))
{
die('Error: ' . mysql_error());
}
if (!mysql_query($sql2,$con))
{
die('Error: ' . mysql_error());
}
Well that is just starting, to make your program run. There are lot to learn.
I've created a form which works fine, but when I put it in a table it always thinks the form is incomplete - is there a way I can put it in a table (so it looks nice!) without this problem?
-----My HTML------
<h2 class="green">Interested in making life easier?</h2>
<form method="post" action="sendemail.php">
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>
<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
Name:
<input type="text" name="visitor" size="25" />
<br />
Address:<input type="text" name="visitoradd" size="25" />
<br />
City:<input type="text" name="visitorcity" size="15" />
<br />
Postcode:<input type="text" name="visitorpost" size="15" />
<br />
Email:<input type="text" name="visitormail" size="25" />
<br />
Telephone Number:<input type="text" name="visitortel" size="25" />
<br />
Bookkeeping/Payroll:<select name="bp" size="1">
<option value=" Bookkeeping">Bookkeeping </option>
<option value=" Payroll ">Payroll</option>
</select>
<br />
Number of transactions: <input type="text" name="transcations" size="15" />
<br />
Number of employees:<input type="text" name="employees" size="15" />
<br />
Payroll weekly/monthly:<select name="pmw" size="1">
<option value=" Weekly">Weekly</option>
<option value=" Monthly">Monthly</option>
</select>
<br />
<br />
<INPUT TYPE="image" SRC="images/btnSubmit.png" ALT="Submit Form">
<br />
</form>
-----My PHP-----
<?php
$visitor = $_POST['visitor'];
$visitoradd = $_POST['visitoradd'];
$visitorcity= $_POST['visitorcity'];
$visitorpost= $_POST['visitorpost'];
$visitormail = $_POST['visitormail'];
$visitortel = $_POST['visitortel'];
$bp = $_POST['bp'];
$transcations = $_POST['transcations'];
$employees = $_POST['employees'];
$pmw = $_POST['pmw'];
if(!$visitormail == "" && (!strstr($visitormail,"#") || !strstr($visitormail,".")))
{
echo "<h2>Please enter valid e-mail.</h2>\n";
$badinput = "<h2>Click the back button to retry.</h2>\n";
echo $badinput;
die ("Thank you.");
}
if(empty($visitor) || empty($visitormail) || empty($visitorcity) || empty($visitorpost) || empty($visitoradd) || empty($visitortel) || empty($bp) || empty($transcations) || empty($employees) || empty($pmw) || empty($pmw))
{
echo "<h2>Please fill in all fields, click the back button to retry</h2>\n";
die ("Thank you.");
}
$message = "
Name: $visitor\n
Address: $visitoradd\n
City: $visitorcity\n
Post Code: $visitorpost\n
Email: $visitormail\n
Phone Number: $visitortel\n
Bookkeeping/Payroll: $bp\n
Number of Transactions: $transcations\n
Number Of Employees: $employees\n
Payroll Weekly/Monthly: $pmw\n"
;
$subject = "Payment Details";
mail("contact#email.com",$subject,$message,$visitormail);
?>
<p align="center">
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> )
<br />
<br />
Click here to Finish
</p>
<h2 class="green">Interested in making life easier?</h2>
<form method="post" action="sendemail.php">
<?php
$ipi = getenv("REMOTE_ADDR");
$httprefi = getenv ("HTTP_REFERER");
$httpagenti = getenv ("HTTP_USER_AGENT");
?>
<input type="hidden" name="ip" value="<?php echo $ipi ?>" />
<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />
<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />
<table>
<tr>
<td><label for="visitor">Name:</label></td>
<td><input type="text" name="visitor" size="25" /></td>
</tr>
<tr>
<td><label for="visitoradd">Address:</label></td>
<td><input type="text" name="visitoradd" size="25" /></td>
</tr>
<tr>
<td><label for="visitorcity">City:</label></td>
<td><input type="text" name="visitorcity" size="15" /></td>
</tr>
<tr>
<td><label for="visitorpost">Postcode:</label></td>
<td><input type="text" name="visitorpost" size="15" /></td>
</tr>
<tr>
<td><label for="visitormail">E-mail:</label></td>
<td><input type="text" name="visitormail" size="25" /></td>
</tr>
<tr>
<td><label for="visitortel">Telephone Number:</label></td>
<td><input type="text" name="visitortel" size="25" /></td>
</tr>
<tr>
<td><label for="bp">Bookkeeping/Payroll:</label></td>
<td>
<select name="bp" size="1">
<option value=" Bookkeeping">Bookkeeping </option>
<option value=" Payroll ">Payroll</option>
</select>
</td>
</tr>
<tr>
<td><label for="transcations">Number of transactions:</label></td>
<td><input type="text" name="transcations" size="15" /></td>
</tr>
<tr>
<td><label for="employees">Number of employees:</label></td>
<td><input type="text" name="employees" size="15" /></td>
</tr>
<tr>
<td><label for="pmw">Payroll weekly/monthly:</label></td>
<td>
<select name="pmw" size="1">
<option value=" Weekly">Weekly</option>
<option value=" Monthly">Monthly</option>
</select>
</td>
</tr>
</table>
<br />
<INPUT TYPE="image" SRC="images/btnSubmit.png" ALT="Submit Form">
<br />
</form>
Place the form tags outside of the table like so:
<form>
<TABLE>
<TR>
<TD>Name</TD>
<TD><input type="text" name="visitor" size="25" /></TD>
</TR>
<TR>
<TD>Address</TD>
<TD><input type="text" name="address" size="25" /></TD>
</TR>
</TABLE>
</form>
If you are needing to specify width, height, etc.. then use CSS.
Here is a great tutorial on it: http://www.w3schools.com/css/