I currently have an edit form, where all values are echoed from the db as the "values" for each input, the user would then retype and "save" the value to append to the db. All echoes work but i have been unable to echo the database value for the options... anybody knows how to?
& Thanks
Code below:
<fieldset>
<form id="input-form" method="POST" action="../php/edit-import-record.php">
Airway Bill Number*:
<input type=text name=AwbNo size=30 class="input" value="<?php echo $awb ?>" required>
Client Code:
<?php //OPEN DROP DOWN BOX
include("../login/dbinfo.inc.php");
$comm=#mysql_connect(localhost,$username,$password);
$rs=#mysql_select_db($database) or die( "Unable to select database");
$sql= "SELECT DISTINCT ClientCode, ClientName FROM tbl_client ORDER BY ClientCode";
$result = mysql_query($sql);
echo "<select name='ClientCode'>";
while ($row = mysql_fetch_array($result)) {
echo "<option value='" . $row['ClientCode'] ."'>" . $row['ClientName'] ."</option>";
}
echo "</select><br>"; //CLOSE DROP DOWN BOX
?><br>
Vessel Name*:
<input type=text name=VesselName class=form-control id=inputSuccess size=30 class="input" value="<?php echo $vsl ?>" required>
Number of Pieces:
<input type=number name=Pieces size=30 class="input" value="<?php echo $pcs ?>" >
Total Weight (kg):
<input type=number name=Weight size=30 class="input" value="<?php echo $wgt ?>" >
Carrier:
<input type=text name=Carrier size=30 class="input" value="<?php echo $car ?>" >
Sender:
<input type=text name=Sender size=30 class="input" value="<?php echo $snd ?>" >
Status:
<input type=text name=Status size=30 class="input" value="<?php echo $stt ?>" >
Arrival Date:
<input type=date name=ArrivalDate size=30 class="input" value="<?php echo $ard ?>" >
Customs:
<input type=text name=Customs size=30 class="input" value="<?php $ctm ?>" >
<br><small>Fields marked with * are required to be filled in.</small>
<div class="inputformbutton">
<button type="reset" class="btn btn-default btn-sm">Reset</button>
<button type="submit" class="btn btn-primary btn-sm">Create Record</button>
</div>
</fieldset>
Related
I wish to display the record to the user that I am deleting in PHP?
I am trying to display the record in a form that I want to delete but only the input type = text values are being displayed and the radio button values are not being displayed?
<?php
require('/home/s3022041/sqlC/dbConnect.php');
if(isset($_POST['search']))
{
$search = mysqli_real_escape_string($connection, $_POST['id']);
$id = $_POST['id'];
$stp1 = preg_replace("/[^a-zA-Z0-9]/", "", $id); //grab only the alphanumerics
$stp2 = strtoupper($stp1); //Make all alphabets uppercase
$stp3 = preg_replace('/\d+/', '',$stp2); //extract the alphabets part
$newsearchid = str_replace($stp3,"-".$stp3."-",$stp2); //put hyphens before and after the alphabet part
$query = "SELECT * FROM cars WHERE Registration_Number = '$newsearchid' ";
$query_run = mysqli_query($connection, $query);
while($row = mysqli_fetch_array($query_run))
{
?>
<form action="delete_process.php" method="POST" class="form">
<h2>Car Registration Form</h2>
<div class="mb-3">
<input type="radio" name="Car" id="Toyota" value=" <?php echo $row['make']; ?>" />
<label for="Toyota" class="form-label">Toyota</label>
<select name="Models[Toyota]" class="form-control" value=" <?php echo $row['model']; ?>">
<option value="">None</option>
<option value="Camri">Camri</option>
<option value="Corolla">Corolla</option>
<option value="Estima">Estima</option>
</select><br>
<input type="radio" name="Car" id="Nissan" value=" <?php echo $row['make']; ?>"/>
<label for="Nissan" class="form-label">Nissan</label>
<select name="Models[Nissan]" class="form-control" value=" <?php echo $row['model']; ?>">
<option value="">None</option>
<option value="Micra">Micra</option>
<option value="roller">roller</option>
<option value="fushe">fushe</option>
</select><br>
<input type="radio" name="Car" id="Mercedez" value=" <?php echo $row['make']; ?>"/>
<label for="Mercedez" class="form-label">Mercedez</label>
<select name="Models[Mercedez]" class="form-control" value=" <?php echo $row['model']; ?>">
<option value="">None</option>
<option value="5series">5series</option>
<option value="x7">x7</option>
<option value="x5">x5</option>
</select><br>
<label for="vehicleidentificationnumber" class="form-label">vehicle identification
number(VIN)</label>
<input type="text" disabled="disabled" name="vehicleidentificationnumber" class="form-control" maxlength=20 value=" <?php echo $row['VIN']; ?>" required >
<br>
<label for="ManufacturingYear" class="form-label">Manufacturing Year</label>
<input type="text" name="Manufacture_Year" class="form-control" maxlength=20 value=" <?php echo $row['Manufacture_Year']; ?>" required >
<label for="Enginesize" class="form-label">Engine size</label>
<input type="text" name="Engine_Size" class="form-control" maxlength=20 value=" <?php echo $row['Engine_Size']; ?>" required>
<label for="TransmissionType" class="form-label">TransmissionType</label><br>
<input type="radio" name="Transmission_Type" id="TransmissionType" value=" <?php echo $row['Transmission_Type']; ?>" />
<label for="Automatic" class="form-label">Automatic</label><br>
<input type="radio" name="Transmission_Type" id="TransmissionType" value=" <?php echo $row['Transmission_Type']; ?>" />
<label for="Manual" class="form-label">Manual</label><br>
<input type="radio" name="Transmission_Type" id="TransmissionType" value=" <?php echo $row['Transmission_Type']; ?>" />
<label for="SemiAutomatic" class="form-label">Semi-Automatic</label><br>
<label for="NoofSeats" class="form-label">No. of Seats</label>
<input type="number" name="NoOfSeats" class="form-control" value="<?php echo $row['NoOfSeats']; ?>" maxlength=20 required>
<label for="Noofdoors" class="form-label">No. of doors</label>
<input type="number" name="NoOfDoors" class="form-control" maxlength=20 value="<?php echo $row['NoOfDoors']; ?>" required>
<label for="Fueltype" class="form-label">Fuel type</label>
<input type="text" name="Fuel_Type" class="form-control" maxlength=20 value=" <?php echo $row['Fuel_Type']; ?>" required>
<label for="Colour" class="form-label">Colour</label>
<input type="text" name="Colour" class="form-control" maxlength=20 value=" <?php echo $row['Colour']; ?>" required>
<label for="RegistrationNumber" class="form-label">Registration Number (use Dublin
registration) </label>
<input type="hidden" disabled="disabled" name="Registration_Number" class="form-control" maxlength=20 value=" <?php echo $row['Registration_Number']; ?>" required>
<label for="Dateoffirstregistration" class="form-label">Date of first registration</label>
<input type="date" name="DateOfRegestration" class="form-control" maxlength=20 value=" <?php echo $row['DateOfRegestration']; ?>" required>
</div>
<button type="submit" name="search" class="btn btn-primary">Delete</button>
</form>
<?php
}
}
else{
echo "<h1> No records found </h1>";
echo "<a href='index.php'>home</a>";
}
?>
</div>
<div class="modal-footer">
</form>
Here I am trying to delete the above record that is displayed but it says deleted successfully but when I go and check the records it is not deleted it's still there?
<?php
require('/home/s3022041/sqlC/dbConnect.php');
if(isset($_POST['search']))
{
$search = mysqli_real_escape_string($connection, $_POST['search']);
$id = $_POST['Registration_Number'];
$query = "DELETE FROM `cars` WHERE Registration_Number='$id' ";
$query_run = mysqli_query($connection, $query) or die ("not done");
if($query_run)
{
echo "<h1> deleted successfully</h1>";
echo "<a href='index.php'>home</a>";
}
else
{
echo "<h1> not deleted </h1>";
echo "<a href='index.php'>home</a>";
echo 'Error! ' . mysqli_error($connection);
}
}
Change
1. Form
<input type="radio" name="Car" id="Toyota" value="<?=$row['make']; ?>" />
to
<input type="radio" name="Car" id="Toyota" <?=($row['make'] == 'Toyota' ? 'value="'.$row['make'].'" checked':NULL); ?> />
<!-- or better yet -->
<input type="radio" name="Car" id="Toyota" value="Toyota" <?=($row['make'] == 'Toyota' ? 'checked':NULL); ?> />
2. Database
File: delete_process.php
// Change
if($query_run) // << This only tell the script the sql statement run with no errors
// To
if(mysql_affected_rows()<=1) // << This confirms that one or more rows where changed by the sql statement
Explained
PHP Shorthand If/Else Using Ternary Operators (?:)
/* basic usage */
$var = 5;
$var_is_greater_than_two = ($var > 2 ? true : false); // returns true
Reason for error
If a radio button are not being displayed, it most-likely an 'Undefined variable' when getting $row['make'].
Other thing, remove the white spacing from. As this may play a part when using a MYSQL Statement.
<!-- From -->
value=" <?php echo $row['Registration_Number']; ?>"
<!-- To -->
value="<?=$row['Registration_Number']; ?>"
*Shorthand one line echo/print <?=
Good Evening, Everybody..
i am using php form to submit data of students in database using the below code...
<?php
if(isset($_POST['submit1']))
{
$a1=mysql_real_escape_string($_POST['a1']);
$a2=mysql_real_escape_string($_POST['a2']);
$a3=mysql_real_escape_string($_POST['a3']);
$a=mysql_real_escape_string($_POST['a']);
$a4=mysql_real_escape_string($_POST['a4']);
$a5=mysql_real_escape_string($_POST['a5']);
$a6=mysql_real_escape_string($_POST['a6']);
$color=mysql_real_escape_string($_POST['color']);
$date=mysql_real_escape_string($_POST['date']);
$query1=mysql_query("insert into student_table values('','$a1','$a2','$a3','$a','$a4','$a5','$a6','$color','$date')");
if($query1)
{
echo "Open Updated Successfully";
}
}
?>
<div class="RECORD" align="center"><font color="red" size="4">! STUDENT RESULTS !</font><div class="HEADLINES">! Live Result !<br>
<font color="yellow"><?php
$query1 = "SELECT CONCAT(a1,a2,a3,' - ',a,' - ',a4,a5,a6) FROM student_table ORDER BY id DESC
LIMIT 1;";
$result = mysql_query($query1);
$data = mysql_fetch_array($result);
echo $data[0];
?></font></div><hr>
<form method="post" action="" autocomplete="off">
DATE:<input type="text" name="date" size="6" align="absmiddle" value="<?php
$current_dayname = date("l");
echo $date = date("d/m/y",strtotime('monday this week')).' <br>to<br> '.date("d/m/y",strtotime("sunday this week"));
?>">
<br><br>Open:
<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']; ?>"> -
<input type="text" name="a" size="2" value="<?php echo $query2['a']; ?>">
<input type="submit" name="submit1">
</form>
<?php
$query1 = "SELECT id FROM student_table ORDER BY id DESC
LIMIT 1;";
$result = mysql_query($query1);
$data = mysql_fetch_array($result);
?>
Now By using the above code it shows desired result....
but i want to add one more result along with previous result, due to this i have to required edit page of above result, the desired code of edit page is below...
<?php
if(isset($_GET['id']))
{
$id=$_GET['id'];
if(isset($_POST['submit2']))
{
$a1=$_POST['a1'];
$a2=$_POST['a2'];
$a3=$_POST['a3'];
$a=$_POST['a'];
$a4=$_POST['a4'];
$a5=$_POST['a5'];
$a6=$_POST['a6'];
$color=$_POST['color'];
$date=$_POST['date'];
$query3=mysql_query("update student_table set a1='$a1', a2='$a2', a3='$a3', a='$a', a4='$a4', a5='$a5', a6='$a6', color='$color', date='$date' where id='$id'");
if($query3)
{
echo "</br> Close Updated Successfully";
}
}
$query1=mysql_query("select * from student_table where id='$id'");
$query2=mysql_fetch_array($query1);
?>
<form method="post" action="" autocomplete="off">
<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']; ?>">
<input type="text" name="a" size="2" value="<?php echo $query2['a']; ?>"><select type="text" name="color" value="<?php echo $query2['color']; ?>"> <option value="#000000">Black</option><option value="#FF0000">Red</option></select>
<input type="submit" name="submit2"><br>
<div style="background:black; color:black; font-size:1px">DATE:<input type="text" name="date" size="5" align="absmiddle" value="<?php
$current_dayname = date("l");
echo $date = date("d/m/y",strtotime('monday this week')).' <br>to<br> '.date("d/m/y",strtotime("sunday this week"));
?>"><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']; ?>"></div>
</form>
<?php
}
?>
Now my question is that....is it possible to perform both submitting of students numbers and having an option to add one more same result with editable function of previous result entry on the same page...
please refer below image...
can anybody help me in order to perform both functioning on same page with editable option
How would I display student.Student instead of student_id
<?php
for ($i = 0; $i < $chkcount; $i++) {
$id = $chk[$i];
$res = $MySQLiconn->query("SELECT Student.ID, student.Student, student.School,student.PR, Jumps.dis_ft_1, Jumps.dis_in_1, Jumps.dis_ft_2, Jumps.dis_in_2, Jumps.dis_ft_3, Jumps.dis_in_3, Jumps.dis_ft_4, Jumps.dis_in_4, Jumps.dis_ft_5, Jumps.dis_in_5, Jumps.dis_ft_6, Jumps.dis_in_6
FROM Student LEFT JOIN Jumps ON Student.ID = Jumps.student_id WHERE ID=" . $id);
while ($row = $res->fetch_array()) {
?>
<tr>
<td>
<input type="hidden" name="id[]" value="<?php echo $row['ID']; ?>"/>
Student ID: <input type="text" name="st[]" value="<?php echo $row['student_id']; ?>"
class="form-control"/>
Attempt 1 <input type="text" name="df1[]" value="<?php echo $row['dis_ft_1']; ?>"
class="form-control"/>
<input type="text" name="di1[]" value="<?php echo $row['dis_in_1']; ?>"
class="form-control"/>
Attempt 2 <input type="text" name="df2[]" value="<?php echo $row['dis_ft_2']; ?>"
class="form-control"/>
<input type="text" name="di2[]" value="<?php echo $row['dis_in_2']; ?>"
class="form-control"/>
Attemp 3 <input type="text" name="df3[]" value="<?php echo $row['dis_ft_3']; ?>"
class="form-control"/>
<input type="text" name="di3[]" value="<?php echo $row['dis_in_3']; ?>"
class="form-control"/>
Attempt 4 <input type="text" name="df4[]" value="<?php echo $row['dis_ft_4']; ?>"
class="form-control"/>
<input type="text" name="di4[]" value="<?php echo $row['dis_in_4']; ?>"
class="form-control"/>
Attempt 5 <input type="text" name="df5[]" value="<?php echo $row['dis_ft_5']; ?>"
class="form-control"/>
<input type="text" name="di5[]" value="<?php echo $row['dis_in_5']; ?>"
class="form-control"/>
Attempt 6 <input type="text" name="df6[]" value="<?php echo $row['dis_ft_6']; ?>"
class="form-control"/>
<input type="text" name="di6[]" value="<?php echo $row['dis_in_6']; ?>"
class="form-control"/>
</td>
</tr>
<?php
}
}
?>
Not sure it can be done. But Student name would be better than student id.
Wouldn't post with more text so just typing so it will post.
I am learning PHP.
If there is only one field called Student i.e Student.Student, then you could just output the name <?php echo $row['Student']; ?>.
However, if there are ever name clashes, you can always give the field a new name for PHP to access.
SELECT Student.ID, Student.Student AS some_new_name FROM ....
<?php echo $row['some_new_name']; ?>
I have a data entry page where a few drop downs exist. The selected item in the drop down stores in my mysql database with no issue.
I've made a 2nd page to edit individual records. I can display the data from the drop down in a text box with no problem. However, I want to be able to edit the result with the same drop down choices.
I can add the drop down menu on my edit.php page with all the correct options, but the stored value from the database does not appear. Instead I get the first choice by default and not the stored value.
<?php
$position_sql = "SELECT id, position FROM ref_positions ORDER BY position ASC";
$position_result = mysql_query($position_sql);
echo "<select name='position'>";
while ($row = mysql_fetch_array($position_result)) {
echo "<option value='" . $row['id'] . "'>" . $row['position'] . "</option>";
}
echo "</select>";
?>
I'm using POST and GET to get the correct record ID.
My text boxes, which work fine are as follows:
Department:<input type="text" name="department" size="20" value="<?php echo "$row[department]"; ?>">
I'm assuming I have to build some sort of if statement to display the stored value?
not sure if this helps, but this is my how I grab the ID for the record I want to edit:
<?php
$id= ($_GET["id"]);
$sql = "SELECT * FROM people
WHERE id='$id' LIMIT 1";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
?>
Entire Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Form Edit Data</title>
</head>
<body>
<?php
$BASE_PATH = 'C:\xampp\htdocs\OGS';
include_once($BASE_PATH . "\includes\layouts\header.php");
?>
<div id="main">
<div id="subnavigation">
<?php include_once($BASE_PATH . "\mods\main_menu\index.html");?>
</div>
<div id="page"
<br><br>
<table border=1>
<tr>
<td align=center>Update Employee Information</td>
</tr>
<tr>
<td>
<table>
<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('ogs');
?>
<?php
$id= ($_GET["id"]);
$sql = "SELECT * FROM people
WHERE id='$id' LIMIT 1";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
?>
<form method="post" action="edit_data.php">
<input type="hidden" name="id" value="<?php echo "$row[id]"; ?>">
<fieldset>
<legend><b>Name</b></legend>
First Name:<input type="text" name="first_name" size="20" value="<?php echo "$row[first_name]"; ?>">
Last Name:<input type="text" name="last_name" size="40" value="<?php echo "$row[last_name]"; ?>">
</fieldset>
<br><br>
<fieldset>
<legend><b>Contact Information</b></legend>
Town:<input type="text" name="town" size="20" value="<?php echo "$row[town]"; ?>">
Address:<input type="text" name="address" size="40" value="<?php echo "$row[address]"; ?>">
Province:<input type="text" name="province" size="20" value="<?php echo "$row[province]"; ?>">
Postal Code:<input type="text" name="postal_code" size="40" value="<?php echo "$row[postal_code]"; ?>">
<br><br>
Home Phone:<input type="text" name="home_phone" size="20" value="<?php echo "$row[home_phone]"; ?>">
Cell Phone:<input type="text" name="cell_phone" size="40" value="<?php echo "$row[cell_phone]"; ?>">
</fieldset>
<br><br>
<fieldset>
<legend><b>Emergency Contact</b></legend>
Emergency Contact Name:<input type="text" name="first_name" size="20" value="<?php echo "$row[first_name]"; ?>">
Emergency Contact Number:<input type="text" name="last_name" size="40" value="<?php echo "$row[last_name]"; ?>">
</fieldset>
<br><br>
<fieldset>
<legend><b>Work Information</b></legend>
Role:<input type="text" name="role" size="20" value="<?php echo "$row[role]"; ?>">
Employer:<input type="text" name="company_works_for" size="40" value="<?php echo "$row[company_works_for]"; ?>">
<br><br>
Department:<input type="text" name="department" size="20" value="<?php echo "$row[department]"; ?>">
Position:
<?php
$position_sql = "SELECT id, position FROM ref_positions ORDER BY position ASC";
$position_result = mysql_query($position_sql);
echo "<select name='position'>";
// You should use PHP to get the existing value here, I have made it up here as 14
$existing_id = '$row[id]';
while ($row = mysql_fetch_array($position_result))
{
// Check if the existing id is the same as the current id we are displaying
// If it is, set the selected attribute
if($existing_id == $row['id'])
echo "<option selected='selected' value='" . $row['id'] . "'>" . $row['position'] . "</option>";
else
echo "<option value='" . $row['id'] . "'>" . $row['position'] . "</option>";
}
echo "</select>";
?>
<br><br>
Is Supervisor?:
<input type="radio" name="is_supervisor" value="<?php echo "$row[is_supervisor]"; ?>"> Yes
<input type="radio" name="is_supervisor" value="<?php echo "$row[is_supervisor]"; ?>"> No
<br><br>
Is Active?:
<input type="radio" name="active_employee" value="<?php echo "$row[active_employee]"; ?>"> Yes
<input type="radio" name="active_employee" value="<?php echo "$row[active_employee]"; ?>"> No
<br><br>
Start Date:<input type="text" name="start_date" size="40" value="<?php echo "$row[start_date]"; ?>">
</fieldset>
<input type="submit"
name="submit value" value="Update">
</form>
</div>
</div>
</body>
</html>
The record for Nicholas Furlong shows him as a Health & Safety Coordinator.
http://prntscr.com/3o34g2
But when I click edit, and go to my edit page, it has him listed as controller. (This is the first option in the column.)
http://prntscr.com/3o36qu
Its not entirely clear what you are asking. But I will try
<?php
$position_sql = "SELECT id, position FROM ref_positions ORDER BY position ASC";
$position_result = mysql_query($position_sql);
echo "<select name='position'>";
// You should use PHP to get the existing value here, I have made it up here as 14
$existing_id = 14;
while ($row = mysql_fetch_array($position_result))
{
// Check if the existing id is the same as the current id we are displaying
// If it is, set the selected attribute
if($existing_id == $row['id'])
echo "<option selected='selected' value='" . $row['id'] . "'>" . $row['position'] . "</option>";
else
echo "<option value='" . $row['id'] . "'>" . $row['position'] . "</option>";
}
echo "</select>";
?>
I have a comment form that I have created. It gets the id from the database and prints out the data that goes with that id, but it also prints out the information into the form. How can I get a blank form, so that the user can add a comment to the record?
This the code for the form:
<form method="post" action="pv.php?id=<?php echo $row['ID']?>&action=<?php echo $form_action ?>">
<fieldset>
<legend></legend>
<p>
<label for="cname">Date Of Birth</label> *
<input id="cname" name="dateofbirth" class="required date" value="<?php echo $row['Date_Of_Birth']?>" /> (eg 1978.11.11)
</p>
<p>
<label for="cgender">Gender</label> *
<input type="radio"
name="gender"
value="Male"
<?php if($row['Gender']=='male'){echo 'checked';}?>/>
Male
<input type="radio"
name="gender"
value="Female"
<?php if($row['Gender']=='female'){echo 'checked';}?>/> Female </td>
</p>
<p>
<label for="curl">Title</label> *
<select name="title" id="title" class="required">
<option value="">Please Select</option>
<option value="Mr" <?php if($row['Title']=='Mr'){echo 'selected';}?>>Mr</option>
<option value="Ms" <?php if($row['Title']=='Ms'){echo 'selected';}?>>Ms</option>
<option value="Mrs" <?php if($row['Title']=='Mrs'){echo 'selected';}?>>Mrs</option>
<option value="Miss" <?php if($row['Title']=='Miss'){echo 'selected';}?>>Miss</option>
<option value="Other" <?php if($row['Title']=='Other'){echo 'selected';}?>>Other</option>
</select>
</p>
<p>
<label for="ccomment">First Name</label> *
<input type="text" name="firstname" value="<?php echo $row['First_Name']?>" maxlength="50" />
</p>
<p>
<label for="cemail">Last Name</label> *
<input id="cemail" type="text" name="lastname"
value="<?php echo $row['Last_Name']?>" maxlength="75" />
</p>
<p>
<label for="ccomment">Address 1</label>*
<input type="text" name="address1"
value="<?php echo $row['Address_Line_1']?>" maxlength="50" />
</p>
<p>
<label for="ccomment">Address 2</label>
<input type="text" name="address2"
value="<?php echo $row['Address_Line_2']?>" maxlength="50" />
</p>
<p>
<label for="ccomment">City</label>*
<input type="text" name="city"
value="<?php echo $row['City']?>" maxlength="50" />
</p>
<p>
<label for="ccomment">Postcode</label>*
<input type="text" name="postcode"
value="<?php echo $row['Postcode']?>" maxlength= "10" /> (eg LE5 5QE)
</p>
<p>
<label for="ccomment">Contact No</label>*
<input type="text" name="contactno"
value="<?php echo $row['Contact_No']?>" maxlength= "12" /> (eg 077448825723)
</p>
<p>
<label for="ccomment">Email</label>*
<input type="text" name="email"
value="<?php echo $row['Email']?>" maxlength= "40"/> (eg info#example.com)
</p>
<p>
<label for="ccomment">Comment</label>
<textarea rows="10" cols="30" name="note"
maxlength= "500"><?php echo $row['Additional_Comment']?></textarea>
</p>
<p>
<input class="submit" type="submit" value="Submit"/>
</p>
<p>
<a href='pv.php'>Main Page</a>
</p>
</fieldset>
</form>
This is the code for printing out the data on the page:
if($_GET['action'] == 'comment') {
$form_action = 'comment_ok';
$id = $_GET['id'];
$result = mysql_query("SELECT * FROM project_data WHERE id='$id'");
$row = mysql_fetch_array($result);
echo'<b>';
echo $row['Date_Of_Birth'];
echo '  ';
echo $row['Gender'];
echo '  ';
echo $row['Title'];
echo '  ';
echo $row['First_Name'];
echo '  ';
echo $row['Last_Name'];
echo '  ';
echo $row['Address_Line_1'];
echo '  ';
echo $row['Address_Line_2'];
echo '  ';
echo $row['City'];
echo '  ';
echo $row['Postcode'];
echo '  ';
echo $row['Contact_No'];
echo '  ';
echo $row['Email'];
echo '  ';
echo $row['Additional_Comment'];
echo '</b>';
}
And a snippet of the code I am using to send the id to the form:
echo "<td><a href='pv.php?action=edit&id=" . $row['ID'] .
"'>Edit</a>  <a href='pv.php?action=delete_ok&id=" . $row['ID'] .
"'>Delete</a>  **<a href='pv.php?action=comment&id=" . $row['ID'] .
"'>Comment</a></td>"**;
echo "</tr>";
How can I do it?
If you want one page that allows the user to fill in a blank form, see a filled out form and update a form.
You can do the blank form or filled form by checking if an id exist, like this:
<?
if (isset(id)) // Here you can check if the id exists, which means you will be doing an update to the SQL query
echo'
<form method="post" action="pv.php?id=' . $row['ID'] . '&action=' . $form_action . '">
<!-- Your form here with values -->
e.g. <label for="cemail">Last Name</label> *
<input id="cemail" type="text" name="lastname" value="' . $row['Last_Name'] . '" maxlength="75" />
</form>';
// Put your SQL update here to take the values from the above form
}
elseif (!isset(id)) // Here there is no id so you will want to insert
{
echo'
<form method="post" action="pv.php?id=' . $row['ID'] . '&action=' . $form_action . '">
<!-- Your form here with values -->
e.g. <label for="cemail">Last Name</label> *
<input id="cemail" type="text" name="lastname" maxlength="75" /> // No value here because will insert new record
</form>';
// Put your SQL insert here to create a new record
}
?>
If you may want the user to be able to add a new comment entirely rather than editing the one already associated with their id, I think you would have to do this by giving them the option to add another comment. To do this, I would create a new table and then insert the comments into that, so you have one table, example_users with the user information, and then another table, user_comments, with the user comments, for example:
Table example_users
id = 1
fname=Joe
lname=Bloggs
email=jbloggs#example.com
Table user_comments
id=1
user_id=1
comment=Comment will be saved here
This way, any user can have any number of comments. You could render this on the page by using a foreach statement to render a text box with all their existing comments and then have a blank one at the end for any new ones. Then they can edit any comment and add a new comment.
If you want the form to be blank, then just set the value attribute to empty. E.g value=''. Except for the id field.