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".
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 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
It is a regitration page in php where image is also uploading along with other user data but it is always showing error please help me to figure out the problem.It is always showing fail but i am using correct image. I also want to know how to set default value for profile image in phpmyadmin and how to query to update it when user enter his choice along with other user data that is to be inserted into database with insert query. and how to do insertion and updation at same time i.e inserting user data and updating default image.
<?php
include_once 'conn.inc';
if(isset($_POST["btnsave"])) {
$filename=$_FILES['file']['name'];
$size=$_FILES['file']['name'];
$extenstion=pathinfo($filename,PATHINFO_EXTENSION);
if($extenstion=='jpeg' || $extenstion=='png' || $extenstion=='jpg' && $size<=30000) {
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
}
else {
echo "failhhhhhhhhhh";
}
$name=mysql_real_escape_string($_POST["txtname"]);
$fname=mysql_real_escape_string($_POST["txtfname"]);
$gender=mysql_real_escape_string($_POST["gender"]);
$image=$_FILES['file']['name'];
$des=mysql_real_escape_string($_POST["des"]);
$job=mysql_real_escape_string($_POST["txtjob"]);
$country=mysql_real_escape_string($_POST["txtcountry"]);
$state=mysql_real_escape_string($_POST["txtstate"]);
$city=mysql_real_escape_string($_POST["txtcity"]);
$contact=mysql_real_escape_string($_POST["txtcontact"]);
$contactst=mysql_real_escape_string($_POST["contactst"]);
$email=mysql_real_escape_string($_POST["txtemail"]);
$emailst=mysql_real_escape_string($_POST["emailst"]);
$query="insert into tblregistration values
('','$name','$fname','$gender','$image','$des','$job','$country','$state','$city','$contact','$contactst','$email','$emailst')" or die('neverve'.mysql_error());
$res=mysql_query($query) or die('error 1'.mysql_error());
if(mysql_affected_rows())
{
echo "success";
}
else {
echo "failure";
}
}
?>
html form
<form method="post" action="registration.php" enctype="multipart/form-data">
<table>
<tr>
<td><label for="txtname">Name</label></td>
<td><input type="text" name="txtname" value="Enter your name"/></td>
</tr>
<tr>
<td><label for="txtfname">Father Name</label></td>
<td><input type="text" name="txtfname" value="Enter your father's name"/></td>
</tr>
<tr>
<td><label>Gender</label></td>
<td>Male<input type="radio" name="gender" checked="checked" value="m" />
Female<input type="radio" name="gender" value="f" />
</td>
</tr>
<tr>
<td>
<input onchange="readURL(this);" type="file" name="file" /></td>
<td><img alt="Image Display Here" id="test" src="./upload/icon3.jpg" height="100px" width="100px" /></td>
</tr>
<tr>
<td><label>Designation</label></td>
<td><select name="des">
<option value="-1">Select Designation</option>
<option value="Employed">Employed</option>
<option value="selfemployed">Self-Employed</option>
<option value="retired">Retired</option>
</select></td>
</tr>
<tr>
<td>
<label>Title of Job</label></td>
<td><input type="text" name="txtjob" value="title of job" /></td>
</tr>
<tr>
<td>
<label>Country</label></td>
<td><input type="text" name="txtcountry" value="Enter your country" /></td>
</tr>
<tr>
<td>
<label>State</label></td>
<td><input type="text" name="txtstate" value="Enter your State" /></td>
</tr>
<tr>
<td>
<label>City</label></td>
<td><input type="text" name="txtcity" value="Enter your city" /></td>
</tr>
<tr>
<td>
<label>Contact no</label></td>
<td><input type="tel" name="txtcontact" value="Enter your contact no" />
Private<input type="radio" name="contactst" value="0" /> Public<input type="radio" name="contactst" checked="checked" value="1"/>
</td>
</tr>
<tr>
<td>
<label>Email</label></td>
<td><input type="email" name="txtemail" value="Enter your email" />
Private<input type="radio" name="emailst" value="0" /> Public<input type="radio" name="emailst" checked="checked" value="1" />
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="btnsave" value="submit" /></td>
</tr>
</table>
</form>
$size=$_FILES['file']['name']; please check this condition
Replace
$size=$_FILES['file']['name'];
with
$size=$_FILES['file']['size'];
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 wonder whether someone may be able to help me please.
I've put together a form and php code (below) that allows an administrator to search for member records from a mysql database using the email address as the search criteria.
HTML Form
<form name="memberpasswordresetform" id="memberpasswordresetform" method="post" action="search.php">
<div class="container">
<p align="justify">Member Details </p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="26%" height="25"><strong>Email Address </strong></td>
<td width="4%"> </td>
<td width="70%"><input name="email" type="email" id="email" size="50" /></td>
</tr>
<tr>
<td height="25"><strong>Confirm Email Address </strong></td>
<td> </td>
<td><input name="conf_email" type="email" id="conf_email" size="50" /></td>
</tr>
<tr>
<td height="25"><label>
<input type="submit" name="Submit" value="search" />
</label></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="25"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="25"><strong>First Name </strong></td>
<td> </td>
<td><input name="fname" type="text" id="fname" size="30" /></td>
</tr>
<tr>
<td height="25"><strong>Last Name </strong></td>
<td> </td>
<td><input name="lname" type="text" id="lname" size="30" /></td>
</tr>
<tr>
<td height="25"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="25"><strong>New Password</strong></td>
<td> </td>
<td><input name="newpass" type="password" id="newpass" size="30" /></td>
</tr>
<tr>
<td height="25"><strong>Confirm New Password </strong></td>
<td> </td>
<td><input name="conf_newpass" type="password" id="conf_newpass" size="30" /></td>
</tr>
<tr>
<td height="25"><input type="submit" name="save" value="save" /></td>
<td> </td>
<td> </td>
</tr>
</table>
</div>
</form>
PHP Script
<?php
include("admin/link.php");
include("admin/opendb.php");
mysql_select_db ("userdetails");
$term = $_POST['email'];
$sql = mysql_query("select forename, surname, email address from userdetails where emailaddress like '%$email%'");
while ($row = mysql_fetch_array($sql)){
echo '<br/> First Name: '.$row['forename'];
echo '<br/> Last Name: '.$row['surname'];
echo '<br/><br/>';
}
?>
The search functionality works fine, but I can't work out how to populate the forename and surname fields on my form from the records retrieved from my database. I've been looking for, and found examples on how to do this, if I want to simply show the data as a table, but I can't find any that explain how to populate the fields in a form.
I just wondered whether it would be at all possible that someone could provide some guidance please on how I can do this.
Many thanks
The previous answer will work fine if short tags are enabled on the server. You should stick to the long syntax as below in case you change hosting providers at a later date.
<input name="fname" type="text" id="fname" size="30" value="<?php echo $row['surname']; ?>" />
just set the value of your input element
<tr>
<td height="25"><strong>First Name </strong></td>
<td> </td>
<td><input name="fname" type="text" id="fname" size="30" value="<?= $row['surname'] ?>" /></td>
</tr>