I am new in the field of PHP.
I am working on a form to get information from a patient regarding a specific disease.
In this form i have multiple check-boxes and text fields with each check-box. If one check bos is checked then values of its text fields and checkbox values has to insert in database.
Please tell me the code to insert checked values along with textfields into database.
<form>
<table>
<tr>
<td colspan="4">Past Medical History:</td>
</tr>
<tr valign="top">
<td colspan="4" height="290"><table border="0" width="100%">
<tbody>
<tr>
<td width="26%"><div align="center">Problem</div></td>
<td width="18%"><div align="center">From (Year)</div></td>
<td width="56%"><div align="center">Details</div></td>
</tr>
<tr>
<td><input name="chkBP" id="chkBP" value="BP" type="checkbox" />
Blood Pressure</td>
<td><div align="center">
<input name="txtBPfrom" id="txtBPfrom" size="15" value="" type="text" />
</div></td>
<td><input name="txtBPDetail" id="txtBPDetail" size="40" value="" type="text" /></td>
</tr>
<tr>
<td><input name="chkDiabetes" id="chkDiabetes" value="Diabetes" type="checkbox" />
Diabetes</td>
<td><div align="center">
<input name="txtDiabetesfrom" id="txtDiabetesfrom" size="15" value="" type="text" />
</div></td>
<td><input name="txtDiabetesDetail" id="txtDiabetesDetail" size="40" value="" type="text" /></td>
</tr>
<tr>
<td><input name="chkHighCholes" id="chkHighCholes" value="HighCholesterol" type="checkbox" />
High Cholesterol</td>
<td><div align="center">
<input name="txtHighCholesfrom" id="txtHighCholesfrom" size="15" value="" type="text"/>
</div></td>
<td><input name="txtHighCholesDetail" id="txtHighCholesDetail" size="40" value="" type="text" /></td>
</tr>
<tr>
<td><input name="chkArthritis" id="chkArthritis" value="Arthritis" type="checkbox" />
Arthritis</td>
<td><div align="center">
<input name="txtArthritisfrom" id="txtArthritisfrom" size="15" value="" type="text" />
</div></td>
<td><input name="txtArthritisDetail" id="txtArthritisDetail" size="40" value="" type="text" /></td>
</tr>
<tr>
<td><input name="chkAsthma" id="chkAsthma" value="Asthma" type="checkbox" />
Asthma</td>
<td><div align="center">
<input name="txtAsthmafrom" id="txtAsthmafrom" size="15" value="" type="text" />
</div></td>
<td><input name="txtAsthmaDetail" id="txtAsthmaDetail" size="40" value="" type="text" /></td>
</tr>
<tr>
<td><input name="chkCirculation" id="chkCirculation" value="Circulation" type="checkbox" />
Circulation</td>
<td><div align="center">
<input name="txtCirculationfrom" id="txtCirculationfrom" size="15" value="" type="text" />
</div></td>
<td><input name="txtCirculationDetail" id="txtCirculationDetail" size="40" value="" type="text" /></td>
</tr>
</table></td>
</tr>
</form>
You will need to establish a connection to the database.
When the form is posted collect this data and insert into the database accordingly using $_POST.
Helpful example can be found here to connect
And to insert data
$link = mysqli_connect("localhost","root","","web_table");
mysqli_query($link,"INSERT INTO web_formitem (`ID`, `formID`, `caption`, `key`, `sortorder`, `type`, `enabled`, `mandatory`, `data`)
VALUES (105, 7, 'Tip izdelka (6)', 'producttype_6', 42, 5, 1, 0, 0)")
or die(mysqli_error($link));
first add any method attribute to your form tag like, get or post
<form>
to
<form action= "" method="post">
and add a submit button too in your form
now on submit your form will post your form value
and you can catch them by php as to insert in database
<?php
if(isset($_POST['submit_btn_name']))
{
//your database connect
//catch all value, for example
$val=$_POST['check_value'];
//your insert query
}
?>
A checkbox will only post when it's checked.
A textfield will always get posted even when it's empty.
Use a form:
<form name="contactform" method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
Add a submit button:
<tr>
<td><input type="submit" value="Submit"></td>
</tr>
PHP:
<?php
//var_dump($_POST);
$chkBP = $_POST['chkBP'];
$txtBPfrom = $_POST['txtBPfrom'];
$txtBPDetail = $_POST['txtBPDetail'];
//echo "-- $txtBPfrom $txtBPDetail --";
if ($chkBP == "BP"){
//echo"Bloodpressure = checked";
$sql="INSERT INTO patient_details (from, detail)
VALUES ('$txtBPfrom', '$txtBPDetail')";
mysql_query($sql);
}else{
echo"Bloodpressure = not checked";
}
?>
Demo: here
Related
I want to insert value in a database and it inserted empty. I want help for this necessary.
This is the variable of time :
$rm_time = $_POST['rm-time'];
PHP
if(empty($_POST['rm-name']) or empty($_POST['rm-details'])){
?>
<h3 style="margin-top: 30px;text-align: center;font-size: 25px;color: red;" dir="rtl">Error</h3>
<?php
}else{
$rm_name = $_POST['rm-name'];
$rm_details = $_POST['rm-details'];
$rm_date = $_POST['rm-date'];
$rm_time = $_POST['rm-time'];
$rm_insert_query = $db->query("INSERT INTO reminders (r_name, r_details, r_date, r_time) VALUES ('$rm_name', '$rm_details', '$rm_date', '$rm_time')");
}
}
?>
<form action="reminder.php?rm=make" method="post">
<table class="rm" width="auto" border="0px">
<tr>
<td class="rm-form-text">Reminder date/time :</td>
<td><input autofocus="" name="rm-date" type="date" id="rm" /> / <input name"rm-time" type="time" id="rm" /></td>
</tr>
<tr>
<td class="rm-form-text">Remimnder name :</td>
<td><input name="rm-name" type="text" id="rm" /></td>
</tr>
<tr>
<td class="rm-form-text">Reminder details :</td>
<td><textarea dir="rtl" name="rm-details" id="rm-ta"></textarea></td>
</tr>
<tr>
<td colspan="2"><input name="save-reminder" type="submit" class="sp-submit" value="Save!" /></td>
</tr>
</table>
</form>
<?
exit;
here your syntax is wrong.
Use
<input name= "rm-time" type="time" id="rm" />
instead of
<input name"rm-time" type="time" id="rm" />
change this
FROM : <input name"rm-time" type="time" id="rm" /></td>
TO : <input name="rm-time" type="time" id="rm" /></td>
I have a webpage where I ask input from the user and when he clicks the add button, it should insert the input from the user into the database. I always thought that you couldn't use POST and GET at the same time but according to this and this answers it should be possible. Yet, I can't seem to get their solutions working.
The script inserts something in the db (an id is generated) but the seriesName field remains empty.
The PHP script:
<?php
$con=mysqli_connect("localhost","user","passwd","database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$issueSeries = mysqli_real_escape_string($con, $_GET['addSeries']);
mysqli_query($con,"INSERT INTO series (seriesName) VALUES ('$issueSeries')");
mysqli_close($con);
?>
The HTML:
<div id="issueAddInformationLayout">
<div id="issueAddCredits">
<form action="addIssue.php" method="post">
<table>
<tr id="lblAddCreator">
<td><p>NR</p></td>
<td><p>Series</p></td>
<td><p>Volume</p></td>
<td><p>Title</p></td>
<td><p>Publisher</p></td>
</tr>
<tr>
<td><input type="text" id="addNR" size="3%"/></td>
<td><input type="text" id="addSeries" size="25%" /></td>
<td><input type="text" id="addVolume" size="25%" /></td>
<td><input type="text" id="addTitle" size="30%" /></td>
<td><input type="text" id="addPublisher" size="30%" /></td>
</tr>
</table>
<table>
<tr id="lblAddCreator">
<td><p>Writer</p></td>
<td></td>
<td></td>
</tr>
<tr id="txtAddCreator">
<td><input type="text" id="addWriter1" size="30%" /></td>
<td><input type="text" id="addWriter2" size="30%" /></td>
<td><input type="text" id="addWriter3" size="30%"/></td>
<td><input type="text" id="addWriter4" size="30%"/></td>
</tr>
<tr id="lblAddCreator">
<td><p>Editor</p></td>
<td></td>
<td></td>
</tr>
<tr id="txtAddEditor">
<td><input type="text" id="addEditor1" size="30%" /></td>
<td><input type="text" id="addEditor2" size="30%"/></td>
<td><input type="text" id="addEditor3" size="30%"/></td>
<td><input type="text" id="addEditor4" size="30%"/></td>
</tr>
<tr id="lblAddCreator">
<td><p>Letterer</p></td>
<td></td>
<td></td>
</tr>
<tr id="txtAddLetterer">
<td><input type="text" id="addLetterer1" size="30%"/></td>
<td><input type="text" id="addLetterer2" size="30%"/></td>
<td><input type="text" id="addLetterer3" size="30%"/></td>
<td><input type="text" id="addLetterer4" size="30%"/></td>
</tr>
<tr id="lblAddCreator">
<td><p>Colourist</p></td>
<td></td>
<td></td>
</tr>
<tr id="txtAddColourist">
<td><input type="text" id="addColourist1" size="30%"/></td>
<td><input type="text" id="addColourist2" size="30%"/></td>
<td><input type="text" id="addColourist3" size="30%"/></td>
<td><input type="text" id="addColourist4" size="30%"/></td>
</tr>
<tr id="lblAddCreator">
<td><p>Cover Artist</p></td>
<td></td>
<td></td>
</tr>
<tr id="txtAddCoverArtist">
<td><input type="text" id="addCoverArtist1" size="30%"/></td>
<td><input type="text" id="addCoverArtist2" size="30%"/></td>
<td><input type="text" id="addCoverArtist3" size="30%"/></td>
<td><input type="text" id="addCoverArtist4" size="30%"/></td>
</tr>
<tr id="lblAddCreator">
<td><p>Inker</p></td>
<td></td>
<td></td>
</tr>
<tr id="txtAddInker">
<td><input type="text" id="addInker1" size="30%"/></td>
<td><input type="text" id="addInker2" size="30%"/></td>
<td><input type="text" id="addInker3" size="30%"/></td>
<td><input type="text" id="addInker4" size="30%"/></td>
</tr>
<tr id="lblAddCreator">
<td><p>Penciler</p></td>
<td></td>
<td></td>
</tr>
<tr id="txtAddPenciler">
<td><input type="text" id="addPenciler1" size="30%"/></td>
<td><input type="text" id="addPenciler2" size="30%"/></td>
<td><input type="text" id="addPenciler3" size="30%"/></td>
<td><input type="text" id="addPenciler4" size="30%"/></td>
</tr>
<tr id="lblAddCreator">
<td><p>Trade Paper Back</p></td>
<td><p id="lblAddCover">Cover</p></td>
</tr>
</table>
<table>
<tr id="txtAddTPB">
<td><input type="text" id="addTPB" size="30%"/></td>
<td>
<p id="btnAddCover" enctype="multipart/form-data" action="parse_file.php" method="post">
<input type="file" name="uploaded_file">
</p>
</td>
<td>
<id="btnAddIssue"><input type="submit" value="Add">
</td>
</tr>
</table>
</form>
</div>
</div>
There seemed to be some confusion about the HTML so I added the full HTML code. Keep in mind: this is purely for myself and I don't really care about stuff like that tables are outdated :)
In HTTP, you can't use GET and POST at the same time but you can make a POST request which has a query string as part of the URL.
PHP will populate $_POST with the body of the request and $_GET with the query string, even if the request was a POST request.
Since the form is POST, the data from the inputs will be put into the body and not the query string (so will appear in $_POST not $_GET).
If the value of addSeries was fixed then you could use it with $_GET like so:
<form id="btnAddIssue" action="addIssue.php?addSeries=someValue" method="post">
… but since you are taking user input, use $_POST to read the value after you put the input inside the form.
Your input is outside of your form so it isn't submitted.
<form id="btnAddIssue" action="addIssue.php" method="post">
<input type="text" id="addSeries" size="25%" />
<input type="submit" value="Add">
</form>
You then need to change $_GET['addSeries'] to $_POST['addSeries'] since your form is set to POST (or change your form to submit via GET).
Your input is outside the form tag which won't be considered when user submits the form.
<form id="btnAddIssue" action="addIssue.php" method="post">
<input type="text" id="addSeries" size="25%" />
<input type="submit" value="Add">
</form>
And since you are making a post request onto php side it would be $_POST to reference that input's value
Also, sometimes it would be good to make use of $_REQUEST which contains data from both GET and POST so you have proper data from request everytime
$issueSeries = mysqli_real_escape_string($con, $_REQUEST['addSeries']);
Your text filed is placed outside the form and so no value (of that text filed) will be submitted to the action page.
Change it to
<form id="btnAddIssue" action="addIssue.php" method="post">
<input type="text" id="addSeries" size="25%" />
<input type="submit" value="Add">
</form>
Also use $_POST, or you can even use $_REQUEST (you can use $_REQUEST for both get and post variables)
Hi everyone, i'm new to programming. I need to develop a rating system with check boxes and text-fields where user clicks the subjects from the list and add his rating/experience in the text field. All these subjects and ratings are added to the database with the subject id and the rating. So the issue is, I don't know how to write the associate array to get the selected subjects and their appropriate rating to insert into the database. Can anyone please provide me some codes or samples similar to this. So, I can get some idea how to do this. Thanks in advance :)
This is the HTML sample code
<form action="" method="post">
<table width="372" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="24"><input type="checkbox" name="subid1" value="1" id="subid1"></td>
<td width="203">Maths</td>`enter code here`
<td width="145"><input type="text" name="sub1" id="sub1"></td>
</tr>
<tr>
<td><input type="checkbox" name="subid2" value="2" id="subid2" /></td>
<td>Physics</td>
<td><input type="text" name="subid2" id="subid2" /></td>
</tr>
<tr>
<td><input type="checkbox" name="subid3" value="3" id="subid3" /></td>
<td>Computing</td>
<td><input type="text" name="subid3" id="subid3" /></td>
</tr>
<tr>
<td><input type="checkbox" name="subid4" value="4" id="subid4" /></td>
<td>Chemistry</td>
<td><input type="text" name="subid4" id="subid4" /></td>
</tr>
<tr>
<td><input type="checkbox" name="subid5" value="5" id="subid5" /></td>
<td>Biology</td>
<td><input type="text" name="subid5" id="subid5" /></td>
</tr>
<tr>
<td><input type="checkbox" name="subid7" value="6" id="subid7" /></td>
<td>Human Biology</td>
<td><input type="text" name="subid6" id="subid6" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="button" id="button" value="Submit" /></td>
<td> </td>
</tr>
</table>
</form>
This will do the job on client side:
<input type="checkbox" name="cb[myID1]" value="1" />
<input type="text" name="t[myID1]" value="" />
<input type="checkbox" name="cb[myID2]" value="1" />
<input type="text" name="t[myID2]" value="" />
and this can be used on server side:
$usedTexts = array();
if ( array_key_exists("t", $_POST) && is_array($_POST["t"])
&& array_key_exists("cb", $_POST) && is_array($_POST["cb"])
)
{
$usedTexts = array_intersect_key($_POST["t"], $_POST["cb"]);
}
see manual for server side: http://us3.php.net/array_intersect_key
edit: fixed to POST; added array_key_exists() and is_array()
I have my login table in mysql is like this
id
fname
lname
email
contactno
userid
password
acctype
status
Now my form is like this
<form name="frm" method="post" action="registerform.php">
<table id="new-account" class="create-an-account" width="100%" border="1" cellspacing="10px" cellpadding="10px">
<tr>
<td width="45%">
<label for="firstname">First Name</label>
<input type="text" style="width:230px;" name="Firstname" id="Firstname" /></td>
<td width="10%"></td>
<td width="45%">
<label for="lastname">Last Name:</label>
<input type="text" style="width:230px;" name="LastName" id="LastName" />
</td>
</tr>
<tr>
<td>
<label for="">Account Type</label>
<select class="select" name="at" id="ValidSelection" style="width:245px;" >
<option value="0">Select Account Type</option>
<option value="agent">agent</option>
<option value="admin">admin</option>
</select>
</td>
</tr>
<tr>
<td><label for="">Email Id:</label></td>
</tr>
<tr>
<td><input type="text" name="email" id="ValidEmail" style="width:230px;"/></td>
</tr>
<tr>
<td><label for="">Contact Number</label></td>
</tr>
<tr>
<td><input type="text" name="contact" id="ValidNumber" style="width:230px" /></td>
</tr>
<tr>
<td><label for=""><strong>Choose Your Login Id:</strong></label>
<input type="text" style="width:230px;" name="LoginId" id="LoginId"/>
</td>
</tr>
<tr>
<td><label for=""><strong>Password: <br /></strong></label></td>
</tr>
<tr>
<td><input type="password" style="width:230px;" name="Password" id="ValidPassword" /></td>
</tr>
<tr>
<td><label for="">Confirm Password:</label></td>
</tr>
<tr>
<td>
<input type="password" style="width:230px;" name="ConfirmPassword" id="ValidConfirmPassword"
/>
</td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="signup" value="Create Account" style="margin-top:20px" /></td>
</tr>
</table>
and for insert data my php code is like this
<?php
if(isset($_REQUEST['signup'])) {
mysql_query("insert into login (`fname`,`lname`,`email`,`contactno`,`userid`,`password`,`acctype`,`status`) values('".$_REQUEST['Firstname']."','".$_REQUEST['LastName']."','".$_REQUEST['email']."','".$_REQUEST['contact']."','".$_REQUEST['LoginId']."','".$pswd."','".$_REQUEST['at']."','active')");
}
?>
Now here when I am reloading the page it is automatically inserting the last entered values to the database. So here can someone kindly tell me what is the issue here? Any help and suggestions are welcome.
If you reload the page after submitting a form, it will keep the POST data. To solve this follow the below things :
You can redirect to some other page after inserting the data, use header("location:new_page.php")
You can unset REQUEST, use unset($_REQUEST) after insert
after inserting the $_POST data use redirect to avoid this situation .
even you can redirect to same page like this :-
header('Location: '.$_SERVER['PHP_SELF']);
exit;
I'm new to PHP and after looking on the web for the last hour I couldn't find out what was wrong with my code so I come to you. Im trying to have a place to update my data collected from a from. I get this error. Undefined index: id in /Users/mm1/Desktop/php/backend form/edit_ac.php on line 12. Here is what I have so far. Can someone please help..
<?php require("database.php"); ?>
<?php require("functions.php"); ?>
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$id= mysql_prep($_GET['id']);
$last= mysql_prep($_POST['last']);
$first= mysql_prep($_POST['first']);
// update data in mysql database
$sql="UPDATE $tbl_name SET first='{$first}', last='{$last}' WHERE id='{$id}'";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='edit_info.php'>View result</a>";
}
else {
echo "ERROR";
}
?>
Here is the form (I know it all isn't complete I'm just trying to get it to work first.)
<?php require("database.php"); ?>
<?php // Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<form name="form1" method="post" action="edit_ac.php">
<table width="700" border="0" cellpadding="5">
<tr>
<td colspan="2" class="center"><h3>PARTICIPANT IDENTIFICATION</h3></td>
</tr>
<tr>
<td width="218">First</td>
<td width="456"><input name="first" type="text" maxlength="50" id="first" value="<? echo $rows['first']; ?>" /></td>
</tr>
<tr>
<td width="218">Last</td>
<td width="456"><input name="last" type="text" maxlength="50" id="last" value="<? echo $rows['last']; ?>" /></td>
</tr>
<tr>
<td width="218">Middles</td>
<td width="456"><input name="middle" type="text" maxlength="50" id="middle" value="<? echo $rows['middle']; ?>"/></td>
</tr>
<tr>
<td>Address</td>
<td><input name="address" type="text" maxlength="50" id="address" value="<? echo $rows['address']; ?>"/></td>
</tr>
<tr>
<td>City</td>
<td><input name="city" type="text" maxlength="50" id="city" value="<? echo $rows['city']; ?>"/></td>
</tr>
<tr>
<td>State</td>
<td><input name="state" type="text" maxlength="15" id="state" value="<? echo $rows['state']; ?>"/></td>
</tr>
<tr>
<td>Zip</td>
<td><input name="zip" type="text" maxlength="15" id="zip" value="<? echo $rows['zip']; ?>" /></td>
</tr>
<tr>
<td>Home Phone</td>
<td><input name="home_phone" type="text" id="home_phone" value="<? echo $rows['home_phone']; ?>" /></td>
</tr>
<tr>
<td>Daytime Phone</td>
<td><input name="daytime_phone" type="text" id="daytime_phone" value="<? echo $rows['daytime_phone']; ?>" /></td>
</tr>
<tr>
<td>Email Address</td>
<td><input name="email_address" type="text" id="email_address" value="<? echo $rows['email_address']; ?>" /></td>
</tr>
<tr>
<td>Birthday</td>
<td><input name="month" type="text" id="month" size="3" maxlength="2" value=""/> / <input name="day" type="text" id="day" size="3" maxlength="2" value=""/> / <input name="year" type="text" id="year" size="5" maxlength="4" value=""/></td>
</tr>
<tr>
<td>Social Security Number</td>
<td><input name="ss_1" type="text" id="ss_1" size="5" maxlength="3" value=""/> - <input name="ss_2" type="text" id="ss_2" size="5" maxlength="2" value=""/> - <input name="ss_3" type="text" id="ss_3" size="5" maxlength="4" value="" /></td>
</tr>
<tr>
<td colspan="2" class="center"><h3>PHOTO IDENTIFICATION </h3></td>
</tr>
<tr>
<td>Type of ID</td>
<td>
<input type="text" name="type_of_id" id="type_of_id" value=""/></td>
</tr>
<tr>
<td>ID Number</td>
<td>
<input type="text" name="id_number" id="id_number" value="" /></td>
</tr>
<tr>
<td>Issuing Jurisdiction</td>
<td><input type="text" name="issuing_state" id="issuing_state" value=""/></td>
</tr>
<tr>
<td>Expiration Date</td>
<td><input type="text" name="expiration_date" id="expiration_date" value=""/></td>
</tr>
<tr>
<td>Issue Date</td>
<td><input type="text" name="issue_date" id="issue_date" value="" /></td>
</tr>
<tr>
<td colspan="2" class="center"><h3>ESTABLISHING YOUR ACCOUNT</h3></td>
</tr>
<tr>
<td colspan="2" class="center">Designate Account Type</td>
</tr>
<tr>
<td>
Acount Type
</td>
<td>
<label>
<input type="radio" name="traditional" value="1" id="traditional" />
Traditional</label>
<br />
<label>
<input type="radio" name="roth" value="1" id="roth" />
Roth</label>
<br />
<label>
<input type="radio" name="sep" value="1" id="sep" />
SEP</label>
<br />
<label>
<input type="radio" name="simple" value="1" id="simple" />
SIMPLE</label>
<br /></td>
</tr>
<tr>
<td colspan="2" class="center">Fund Your Account</td>
</tr>
<tr>
<td colspan="2"><input name="rollover" type="radio" value="1" id="rollover" />I will rollover cash from an existing IRA or qualified retirement plan
</td>
</tr>
<tr>
<td>Prior Custodian Plan Name</td>
<td><input name="prior_plan_name" type="text" maxlength="50" id="prior_plan_name" value=""/></td>
</tr>
<tr>
<td>Expected Rollover Amount</td>
<td><input name="rollover_amount" type="text" maxlength="50" id="rollover_amount" value=""/></td>
</tr>
<tr>
<td colspan="2"><input name="transfer" type="radio" value="1" id="transfer" /> I will transfer assets from another IRA and have attached a TRANSFER AUTHORIZATION form </td>
</tr>
<tr>
<td colspan="2"><input name="contribution" type="radio" value="1" id="contribution"/> I have attached a contribution check as follows</td>
</tr>
<tr>
<td>IRA Cash Contribution for the Year</td>
<td><input name="cash_contributions_1" type="text" id="cash_contributions_1" value=""/></td>
</tr>
<tr>
<td>in the amount of</td>
<td><input name="amount_1" type="text" id="amount_1" value=""/></td>
</tr>
<tr>
<td>IRA Cash Contribution for the Year</td>
<td><input name="cash_contributions_2" type="text" id="cash_contributions_2" value="" /></td>
</tr>
<tr>
<td>in the amount of</td>
<td><input name="amount_2" type="text" id="amount_2" value="" /></td>
</tr>
<tr>
<td>Employer OR Employee (circle one) SEP/SIMPLE Contribution for the Year</td>
<td><input name="employer_contributions" type="text" id="employer_contributions" value="" /></td>
</tr>
<tr>
<td>in the amount of</td>
<td><input name="amount_3" type="text" id="amount_3" value="" /></td>
</tr>
<tr>
<td></td>
<td style="text-align:right"><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>
</table>
<?php
// close connection
mysql_close();
?>
Add the id into the form as a hidden field.
<input type="hidden" name="id" value="<?php print $rows['id'] ?>">
An undefined index simply means that the index of a certain array doesn't exist. So in this case $_GET has not index of id.
Perhaps you should be checking if the variables are set before anything.
if(!empty($_GET['id']) && !empty($_POST['last']) && !empty($_POST['first'])){
// other code
}
You may also be using the wrong superglobal, like GeoPhoenix said, are you sure it's not $_POST['id'] you're looking for?
If you aren't including the parameters in the call to the page you are getting errors because you turned error reporting all the way up in the first few lines:
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
Often PHP (and therefore PHP tutorials) assume a lower setting where PHP will either throw a warning or ignore index errors on arrays. Therefore when you hit:
$id= mysql_prep($_GET['id']);
$last= mysql_prep($_POST['last']);
$first= mysql_prep($_POST['first']);
It throws an error, but your references might assume it fails quietly.
Your form appears to provide the ID number in the id_number instead of just id. So switching to $id=mysql_prep($_GET['id_number']); is likely to get more effective results.
Since you are new to PHP I also strongly suggest changing your PHP library away from the old mysql lib to either mysqli or PDO. Changes people are suggesting will likley get you the results you expect but not fix the multiple SQL Injection vulnerabilities this script has.
I don't see anything in your form that has the name "id".
If your using $_get['id'] you must have a link or submit button that tranfers to a url that looks like this.
<a href="phpfile.php?id=PUT_VALUE_HERE>
Notice the url has the variable name id after the question mark and you tell what the variable is after the =.
Otherwise if your not going to put your variable in a url. You use $_POST['id'].
In order for $_POST['id'] to work you need an input in your form that has the name attribute set to id. For example
<input name="id" type="text">
I do not see anything in your form with a name attribute set to "id".