I am building a PHP registration form which takes the following fields for up to 20 athletes:
First Name Middle Initial Last Name
Federation Number Address City State
Zip DOB SSN Phone Email
I am only through 7 of the fields for each fighter and my php file is very large (over 40kb). Is there ANY way to consolidate this code at all? I am also having to validate the information on each field (as I said - 20 athletes x 12 fields = 240 validations on a single page).
If I can send any further code let me know!
<form id="Form" action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="Form" onsubmit="return Enroll_Form_Validator(this)">
<p class="title">Your Fighters' Information</p>
<p>Please complete the following fields with your <span style="color:red;"> Fighters' Information</span> to continue your enrollment.</p>
<br />
<?php
// if $errors is not empty, the form must have failed one or more validation
// tests. Loop through each and display them on the page for the user
if (!empty($errors))
{
echo "<div class='error'>Please fix the following errors:\n<ul>";
foreach ($errors as $error)
echo "<li>$error</li>\n";
echo "</ul></div>";
}
?>
<?php if ($_SESSION['Num_Fighters'] > "0") { ?>
<table class="demoTable">
<tr>
<td>First Name: </td>
<td><input type="text" name="F1FirstName" onkeyup="if(!this.value.match(/^([a-z]+\s?)*$/i))this.value=this.value.replace(/[^a-z ]/ig,'').replace(/\s+/g,' ')" value="<?php echo $fields['F1FirstName']; ?>" /></td>
</tr>
<tr>
<td>Middle Initial: </td>
<td><input type="text" name="F1MI" size="2" maxlength="1" onkeyup="if(!this.value.match(/^([a-z]+\s?)*$/i))this.value=this.value.replace(/[^a-z ]/ig,'').replace(/\s+/g,' ')" value="<?php echo $fields['F1MI']; ?>" /></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input type="text" name="F1LastName" onkeyup="if(!this.value.match(/^([a-z]+\s?)*$/i))this.value=this.value.replace(/[^a-z ]/ig,'').replace(/\s+/g,' ')" value="<?php echo $fields['F1LastName']; ?>" /></td>
</tr>
<tr>
<td>Federation No: </td>
<td><input type="text" name="F1FedNum" maxlength="10" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F1FedNum']; ?>" /></td>
</tr>
<tr>
<td>SSN: </td>
<td><input type="text" name="F1SSN1" size="3" maxlength="3" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F1SSN1']; ?>" /> -
<input type="text" name="F1SSN2" size="2" maxlength="2" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F1SSN2']; ?>" /> -
<input type="text" name="F1SSN3" size="4" maxlength="4" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F1SSN3']; ?>" />
</td>
</tr>
<tr>
<td>Date of Birth</td>
<td>
<select name="F1DOB1">
<option value="">Month</option>
<?php
for ($i=1; $i<=12; $i++)
{
echo "<option value='$i'";
if ($fields["F1DOB1"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select> /
<select name="F1DOB2">
<option value="">Day</option>
<?php
for ($i=1; $i<=31; $i++)
{
echo "<option value='$i'";
if ($fields["F1DOB2"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select> /
<select name="F1DOB3">
<option value="">Year</option>
<?php
for ($i=date('Y'); $i>=1900; $i--)
{
echo "<option value='$i'";
if ($fields["F1DOB3"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Address: </td>
<td><input type="text" name="F1Address" value="<?php echo $fields['F1Address']; ?>" /></td>
</tr>
<tr>
<td>City: </td>
<td><input type="text" name="F1City" onkeyup="if(!this.value.match(/^([a-z]+\s?)*$/i))this.value=this.value.replace(/[^a-z ]/ig,'').replace(/\s+/g,' ')" value="<?php echo $fields['F1City']; ?>" /></td>
</tr>
<tr>
<td>State: </td>
<td><select name="F1State"><option value="">Choose a State</option><?php showOptionsDrop($states_arr, null, true); ?></select></td>
</tr>
<tr>
<td>Zip Code: </td>
<td><input type="text" name="F1Zip" size="6" maxlength="5" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F1Zip']; ?>" /></td>
</tr>
<tr>
<td>Contact Telephone No: </td>
<td>( <input type="text" name="F1Phone1" size="3" maxlength="3" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F1Phone1']; ?>" /> )
<input type="text" name="F1Phone2" size="3" maxlength="3" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F1Phone2']; ?>" /> -
<input type="text" name="F1Phone3" size="4" maxlength="4" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F1Phone3']; ?>" />
</td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="F1Email" value="<?php echo $fields['F1Email']; ?>" /></td>
</tr>
</table>
<?php } ?>
<br />
<?php if ($_SESSION['Num_Fighters'] > "1") { ?>
<table class="demoTable">
<tr>
<td>First Name: </td>
<td><input type="text" name="F2FirstName" onkeyup="if(!this.value.match(/^([a-z]+\s?)*$/i))this.value=this.value.replace(/[^a-z ]/ig,'').replace(/\s+/g,' ')" value="<?php echo $fields['F2FirstName']; ?>" /></td>
</tr>
<tr>
<td>Middle Initial: </td>
<td><input type="text" name="F2MI" size="2" maxlength="1" onkeyup="if(!this.value.match(/^([a-z]+\s?)*$/i))this.value=this.value.replace(/[^a-z ]/ig,'').replace(/\s+/g,' ')" value="<?php echo $fields['F2MI']; ?>" /></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input type="text" name="F2LastName" onkeyup="if(!this.value.match(/^([a-z]+\s?)*$/i))this.value=this.value.replace(/[^a-z ]/ig,'').replace(/\s+/g,' ')" value="<?php echo $fields['F2LastName']; ?>" /></td>
</tr>
<tr>
<td>Federation No: </td>
<td><input type="text" name="F2FedNum" maxlength="10" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F2FedNum']; ?>" /></td>
</tr>
<tr>
<td>SSN: </td>
<td><input type="text" name="F2SSN1" size="3" maxlength="3" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F2SSN1']; ?>" /> -
<input type="text" name="F2SSN2" size="2" maxlength="2" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F2SSN2']; ?>" /> -
<input type="text" name="F2SSN3" size="4" maxlength="4" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F2SSN3']; ?>" />
</td>
</tr>
<tr>
<td>Date of Birth</td>
<td>
<select name="F2DOB1">
<option value="">Month</option>
<?php
for ($i=1; $i<=12; $i++)
{
echo "<option value='$i'";
if ($fields["F2DOB1"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select> /
<select name="F2DOB2">
<option value="">Day</option>
<?php
for ($i=1; $i<=31; $i++)
{
echo "<option value='$i'";
if ($fields["F2DOB2"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select> /
<select name="F2DOB3">
<option value="">Year</option>
<?php
for ($i=date('Y'); $i>=1900; $i--)
{
echo "<option value='$i'";
if ($fields["F2DOB3"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Address: </td>
<td><input type="text" name="F2Address" value="<?php echo $fields['F2Address']; ?>" /></td>
</tr>
<tr>
<td>City: </td>
<td><input type="text" name="F2City" onkeyup="if(!this.value.match(/^([a-z]+\s?)*$/i))this.value=this.value.replace(/[^a-z ]/ig,'').replace(/\s+/g,' ')" value="<?php echo $fields['F2City']; ?>" /></td>
</tr>
<tr>
<td>State: </td>
<td><select name="F2State"><option value="">Choose a State</option><?php showOptionsDrop($states_arr, null, true); ?></select></td>
</tr>
<tr>
<td>Zip Code: </td>
<td><input type="text" name="F2Zip" size="6" maxlength="5" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F2Zip']; ?>" /></td>
</tr>
<tr>
<td>Contact Telephone No: </td>
<td>( <input type="text" name="F2Phone1" size="3" maxlength="3" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F2Phone1']; ?>" /> )
<input type="text" name="F2Phone2" size="3" maxlength="3" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F2Phone2']; ?>" /> -
<input type="text" name="F2Phone3" size="4" maxlength="4" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F2Phone3']; ?>" />
</td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="F2Email" value="<?php echo $fields['F2Email']; ?>" /></td>
</tr>
</table>
<?php } ?>
<br />
<?php if ($_SESSION['Num_Fighters'] > "2") { ?>
<table class="demoTable">
<tr>
<td>First Name: </td>
<td><input type="text" name="F3FirstName" onkeyup="if(!this.value.match(/^([a-z]+\s?)*$/i))this.value=this.value.replace(/[^a-z ]/ig,'').replace(/\s+/g,' ')" value="<?php echo $fields['F3FirstName']; ?>" /></td>
</tr>
<tr>
<td>Middle Initial: </td>
<td><input type="text" name="F3MI" size="2" maxlength="1" onkeyup="if(!this.value.match(/^([a-z]+\s?)*$/i))this.value=this.value.replace(/[^a-z ]/ig,'').replace(/\s+/g,' ')" value="<?php echo $fields['F3MI']; ?>" /></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input type="text" name="F3LastName" onkeyup="if(!this.value.match(/^([a-z]+\s?)*$/i))this.value=this.value.replace(/[^a-z ]/ig,'').replace(/\s+/g,' ')" value="<?php echo $fields['F3LastName']; ?>" /></td>
</tr>
<tr>
<td>Federation No: </td>
<td><input type="text" name="F3FedNum" maxlength="10" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F3FedNum']; ?>" /></td>
</tr>
<tr>
<td>SSN: </td>
<td><input type="text" name="F3SSN1" size="3" maxlength="3" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F3SSN1']; ?>" /> -
<input type="text" name="F3SSN2" size="2" maxlength="2" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F3SSN2']; ?>" /> -
<input type="text" name="F3SSN3" size="4" maxlength="4" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F3SSN3']; ?>" />
</td>
</tr>
<tr>
<td>Date of Birth</td>
<td>
<select name="F3DOB1">
<option value="">Month</option>
<?php
for ($i=1; $i<=12; $i++)
{
echo "<option value='$i'";
if ($fields["F3DOB1"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select> /
<select name="F3DOB2">
<option value="">Day</option>
<?php
for ($i=1; $i<=31; $i++)
{
echo "<option value='$i'";
if ($fields["F3DOB2"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select> /
<select name="F3DOB3">
<option value="">Year</option>
<?php
for ($i=date('Y'); $i>=1900; $i--)
{
echo "<option value='$i'";
if ($fields["F3DOB3"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Address: </td>
<td><input type="text" name="F3Address" value="<?php echo $fields['F3Address']; ?>" /></td>
</tr>
<tr>
<td>City: </td>
<td><input type="text" name="F3City" onkeyup="if(!this.value.match(/^([a-z]+\s?)*$/i))this.value=this.value.replace(/[^a-z ]/ig,'').replace(/\s+/g,' ')" value="<?php echo $fields['F3City']; ?>" /></td>
</tr>
<tr>
<td>State: </td>
<td><select name="F3State"><option value="">Choose a State</option><?php showOptionsDrop($states_arr, null, true); ?></select></td>
</tr>
<tr>
<td>Zip Code: </td>
<td><input type="text" name="F3Zip" size="6" maxlength="5" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F3Zip']; ?>" /></td>
</tr>
<tr>
<td>Contact Telephone No: </td>
<td>( <input type="text" name="F3Phone1" size="3" maxlength="3" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F3Phone1']; ?>" /> )
<input type="text" name="F3Phone2" size="3" maxlength="3" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F3Phone2']; ?>" /> -
<input type="text" name="F3Phone3" size="4" maxlength="4" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F3Phone3']; ?>" />
</td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="F3Email" value="<?php echo $fields['F3Email']; ?>" /></td>
</tr>
</table>
<?php } ?>
<br />
<?php if ($_SESSION['Num_Fighters'] > "3") { ?>
<table class="demoTable">
<tr>
<td>First Name: </td>
<td><input type="text" name="F4FirstName" onkeyup="if(!this.value.match(/^([a-z]+\s?)*$/i))this.value=this.value.replace(/[^a-z ]/ig,'').replace(/\s+/g,' ')" value="<?php echo $fields['F4FirstName']; ?>" /></td>
</tr>
<tr>
<td>Middle Initial: </td>
<td><input type="text" name="F4MI" size="2" maxlength="1" onkeyup="if(!this.value.match(/^([a-z]+\s?)*$/i))this.value=this.value.replace(/[^a-z ]/ig,'').replace(/\s+/g,' ')" value="<?php echo $fields['F4MI']; ?>" /></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input type="text" name="F4LastName" onkeyup="if(!this.value.match(/^([a-z]+\s?)*$/i))this.value=this.value.replace(/[^a-z ]/ig,'').replace(/\s+/g,' ')" value="<?php echo $fields['F4LastName']; ?>" /></td>
</tr>
<tr>
<td>Federation No: </td>
<td><input type="text" name="F4FedNum" maxlength="10" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F4FedNum']; ?>" /></td>
</tr>
<tr>
<td>SSN: </td>
<td><input type="text" name="F4SSN1" size="3" maxlength="3" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F4SSN1']; ?>" /> -
<input type="text" name="F4SSN2" size="2" maxlength="2" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F4SSN2']; ?>" /> -
<input type="text" name="F4SSN3" size="4" maxlength="4" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F4SSN3']; ?>" />
</td>
</tr>
<tr>
<td>Date of Birth</td>
<td>
<select name="F4DOB1">
<option value="">Month</option>
<?php
for ($i=1; $i<=12; $i++)
{
echo "<option value='$i'";
if ($fields["F4DOB1"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select> /
<select name="F4DOB2">
<option value="">Day</option>
<?php
for ($i=1; $i<=31; $i++)
{
echo "<option value='$i'";
if ($fields["F4DOB2"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select> /
<select name="F4DOB3">
<option value="">Year</option>
<?php
for ($i=date('Y'); $i>=1900; $i--)
{
echo "<option value='$i'";
if ($fields["F4DOB3"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Address: </td>
<td><input type="text" name="F4Address" value="<?php echo $fields['F4Address']; ?>" /></td>
</tr>
<tr>
<td>City: </td>
<td><input type="text" name="F4City" onkeyup="if(!this.value.match(/^([a-z]+\s?)*$/i))this.value=this.value.replace(/[^a-z ]/ig,'').replace(/\s+/g,' ')" value="<?php echo $fields['F4City']; ?>" /></td>
</tr>
<tr>
<td>State: </td>
<td><select name="F4State"><option value="">Choose a State</option><?php showOptionsDrop($states_arr, null, true); ?></select></td>
</tr>
<tr>
<td>Zip Code: </td>
<td><input type="text" name="F4Zip" size="6" maxlength="5" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F4Zip']; ?>" /></td>
</tr>
<tr>
<td>Contact Telephone No: </td>
<td>( <input type="text" name="F4Phone1" size="3" maxlength="3" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F4Phone1']; ?>" /> )
<input type="text" name="F4Phone2" size="3" maxlength="3" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F4Phone2']; ?>" /> -
<input type="text" name="F4Phone3" size="4" maxlength="4" onkeyup="this.value=this.value.replace(/[^0-9]/ig, '')" value="<?php echo $fields['F4Phone3']; ?>" />
</td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="F4Email" value="<?php echo $fields['F4Email']; ?>" /></td>
</tr>
</table>
<?php } ?>
<div align="right"><input class="enrbutton" type="submit" name="submit" value="Continue" /></div>
</form>
This only goes through 4 athletes and I need it to capture 20. Any ideas? I am forced to keep all 200+ elements in SESSION assuming somebody enrolls 20 athletes.
Throw this code away.
Seperate your html files from your php code.
Use a MVC pattern if you
are ambitious.
Use a validation
class.
Profit!
Forms can be a real pain. I'm with Byron, but I'd like to further point out that you don't have to use Zend's MVC components to use Zend Form. I've gotten a lot of mileage out plugging Zend Form into some of my non-mvc projects.
Related
I want to update multiple records of type radio (field "status"). Below is the codes. But as you can see the result here:
http://lamoncheri.com/admin/dapur.php?id=21
It only recognize the status of one record.
<?php
$i = 1;
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"> <input name="nama_menu[]" type="text" id="nama_menu" value="<?php echo $rows['nama_menu']; ?>" readonly style="width: 484px; font-size:medium"> </td>
<td align="center"> <input name="qty[]" type="int" id="qty" value="<?php echo $rows['qty']; ?>" readonly style="width: 484px; font-size:medium"> </td>
<td> <input type="radio" name="status[]" id='status' value="order" <?php if ($rows['status'] == "order"){echo "checked";} ?> class ="auto-style5" required>Order<br>
<input type="radio" name="status[]" id='status' value="process" <?php if ($rows['status'] == "process"){echo "checked";} ?> class ="auto-style5" required>Process<br>
<input type="radio" name="status[]" id='status' value="finish" <?php if ($rows['status'] == "finish"){echo "checked";} ?> class ="auto-style5" required> Finish<br>
</td>
<td style="align:center; color:white"><input name="id[]" type="text" id="id" value="<?php echo $rows['id']; ?>" readonly style="border:0; color:white; width: 10px"> </td>
</tr>
<tr>
<td colspan="4" align="center"> </td>
</tr>
<?php
$i++;
}
?>
name put some thing like this
<?php
$i = 1;
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center"> <input name="nama_menu<?php echo $i; ?>[]" type="text" id="nama_menu" value="<?php echo $rows['nama_menu']; ?>" readonly style="width: 484px; font-size:medium"> </td>
<td align="center"> <input name="qty<?php echo $i; ?>[]" type="int" id="qty" value="<?php echo $rows['qty']; ?>" readonly style="width: 484px; font-size:medium"> </td>
<td> <input type="radio" name="status<?php echo $i; ?>[]" id='status' value="order" <?php if ($rows['status'] == "order"){echo "checked";} ?> class ="auto-style5" required>Order<br>
<input type="radio" name="status<?php echo $i; ?>[]" id='status' value="process" <?php if ($rows['status'] == "process"){echo "checked";} ?> class ="auto-style5" required>Process<br>
<input type="radio" name="status<?php echo $i; ?>[]" id='status' value="finish" <?php if ($rows['status'] == "finish"){echo "checked";} ?> class ="auto-style5" required> Finish<br>
</td>
<td style="align:center; color:white"><input name="id<?php echo $i; ?>[]" type="text" id="id" value="<?php echo $rows['id']; ?>" readonly style="border:0; color:white; width: 10px"> </td>
</tr>
<tr>
<td colspan="4" align="center"> </td>
</tr>
<?php
$i++;
}
?>
Good morning I am seeking for a help regarding on my php code. I have a problem updating a value in database using get method.
Here is the function I have a form method which is GET and i have a forloop where in inside that loop counts the number of data with the same tracking code now. for example i have a 3 same tracking code so i have a 3 textbox and also i have a 3 submit button. Now i want to update the textbox 1 and click submit it will automatically updated.
For reference here is my code:
enter code here<form method="get" action="view-reservation.php">
<table class="table table-striped">
<tr>
<td>January</td>
<td>February</td>
<td>March</td>
<td>April</td>
<td>May</td>
<td>June</td>
<td>July</td>
<td>August</td>
<td>September</td>
<td>October</td>
<td>November</td>
<td>December</td>
<td></td>
</tr>
<?php foreach ($view as $key => $data):?>
<tr>
<td><input type="hidden" name="track" size="1" value="<?php echo $data->track?>">
<input type="hidden" name="pid" size="1" value="<?php echo $data->pid?>">
<input type="text" name="jan" size="1" value="<?php echo $data->jan?>"></td>
<td><input type="text" name="feb" size="1" value="<?php echo $data->feb?>"></td>
<td><input type="text" name="mar" size="1" value="<?php echo $data->mar?>"></td>
<td><input type="text" name="apr" size="1" value="<?php echo $data->apr?>"></td>
<td><input type="text" name="may" size="1" value="<?php echo $data->may?>"></td>
<td><input type="text" name="jun" size="1" value="<?php echo $data->jun?>"></td>
<td><input type="text" name="jul" size="1" value="<?php echo $data->jul?>"></td>
<td><input type="text" name="aug" size="1" value="<?php echo $data->aug?>"></td>
<td><input type="text" name="sep" size="1" value="<?php echo $data->sept?>"></td>
<td><input type="text" name="oct" size="1" value="<?php echo $data->oct?>"></td>
<td><input type="text" name="nov" size="1" value="<?php echo $data->nov?>"></td>
<td><input type="text" name="dec" size="1" value="<?php echo $data->dec?>"></td>
<td>
<a href="view-reservation.php?track=<?php echo $data->track?>&&pid=<?php echo $data->pid?>&&jan=<?php echo $data->jan?>"
class="label label-danger">Update Payment</a></td>
</tr>
<?php endforeach;?>
<?php endif?>
</form>
</table>
Here is my query when i execute:
if(isset($_GET['track']) && isset($_GET['pid']) && isset($_GET['jan']))
{
//
$jan = filter($_GET['jan']);
$track = filter($_GET['track']);
$pid = filter($_GET['pid']);
$query = $con->query("update payment set jan = '500' where track = '$track' and pid='$pid'") or die(mysqli_errno());
if($query)
{
echo'updated';
}
}
I'm very new to php and databases. So I need you to help me out please.
I want to edit the data of my database online in my php site. But the form is empty and I don't know why.
I don't know if you need more information so this is the code of the table with the form. If you need more let me know.
<table>
<?php
$con=mysqli_connect("x","y","z","xyz");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Transparente");
while($row = mysqli_fetch_array($result))
mysqli_close($con);
?>
<form method="post" action="edit_data.php">
<input type="text" name="id" value="<? echo "$row[id]"?>">
<tr>
<td>Firma</td>
<td>
<input type="text" name="name"
size="40" value="<? echo "$row[Name]"?>">
</td>
</tr>
<tr>
<td>Wer</td>
<td>
<input type="text" name="wer" size="40"
value="<? echo "$row[Wer]"?>">
</td>
</tr>
<tr>
<td>Erhalten</td>
<td>
<input type="text" name="erhalten" size="40"
value="<? echo "$row[Erhalten]"?>">
</td>
</tr>
<tr>
<td>Digital</td>
<td>
<input type="text" name="digital" size="40"
value="<? echo "$row[Digital]"?>">
</td>
</tr>
<tr>
<td>Betrag in Euro</td>
<td>
<input type="text" name="betrag" size="40"
value="<? echo "$row[Betrag]"?>">
</td>
</tr>
<tr>
<td>Bezahlt am</td>
<td>
<input type="text" name="bezahlt" size="40"
value="<? echo "$row[Bezahlt]"?>">
</td>
</tr>
<tr>
<td>Anmerkung</td>
<td>
<input type="text" name="anmerkung" size="40"
value="<? echo "$row[Anmerkung]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
Try below code
1)If data base contain more rows it shows multiple form
2)You need to show one form you need to restrict in query using where class
<?php
$con=mysqli_connect("x","y","z","xyz");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Transparente");
while($row = mysqli_fetch_array($result))
{
?>
<table>
<form method="post" action="edit_data.php">
<input type="text" name="id" value="<?php echo $row['id'];?>">
<tr>
<td>Firma</td>
<td>
<input type="text" name="name"
size="40" value="<?php echo $row['Name'];?>">
</td>
</tr>
<tr>
<td>Wer</td>
<td>
<input type="text" name="wer" size="40"
value="<?php echo $row['Wer']?>">
</td>
</tr>
<tr>
<td>Erhalten</td>
<td>
<input type="text" name="erhalten" size="40"
value="<?php echo $row['Erhalten']?>">
</td>
</tr>
<tr>
<td>Digital</td>
<td>
<input type="text" name="digital" size="40"
value="<?php echo $row['Digital']?>">
</td>
</tr>
<tr>
<td>Betrag in Euro</td>
<td>
<input type="text" name="betrag" size="40"
value="<?php echo $row['Betrag']?>">
</td>
</tr>
<tr>
<td>Bezahlt am</td>
<td>
<input type="text" name="bezahlt" size="40"
value="<?php echo "$row[Bezahlt]"?>">
</td>
</tr>
<tr>
<td>Anmerkung</td>
<td>
<input type="text" name="anmerkung" size="40"
value="<?php echo $row['Anmerkung'];?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
<?php } ?>
Edit:
change query like below
$result = mysqli_query($con,"SELECT * FROM Transparente where id={$_REQUEST['id']}");
<table>
<?php
$con=mysqli_connect("x","y","z","xyz");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Transparente");
while($row = mysqli_fetch_array($result))
?>
<form method="post" action="edit_data.php">
<input type="text" name="id" value="<? echo "$row[id]"?>">
<tr>
<td>Firma</td>
<td>
<input type="text" name="name"
size="40" value="<? echo "$row[Name]"?>">
</td>
</tr>
<tr>
<td>Wer</td>
<td>
<input type="text" name="wer" size="40"
value="<? echo "$row[Wer]"?>">
</td>
</tr>
<tr>
<td>Erhalten</td>
<td>
<input type="text" name="erhalten" size="40"
value="<? echo "$row[Erhalten]"?>">
</td>
</tr>
<tr>
<td>Digital</td>
<td>
<input type="text" name="digital" size="40"
value="<? echo "$row[Digital]"?>">
</td>
</tr>
<tr>
<td>Betrag in Euro</td>
<td>
<input type="text" name="betrag" size="40"
value="<? echo "$row[Betrag]"?>">
</td>
</tr>
<tr>
<td>Bezahlt am</td>
<td>
<input type="text" name="bezahlt" size="40"
value="<? echo "$row[Bezahlt]"?>">
</td>
</tr>
<tr>
<td>Anmerkung</td>
<td>
<input type="text" name="anmerkung" size="40"
value="<? echo "$row[Anmerkung]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
<?php mysqli_close($con);?>
// close connection at the end of the code
You are not opening the while loop.Try this it will show you the values in the form
<table>
<?php
$con=mysqli_connect("x","y","z","xyz");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Transparente");
while($row = mysqli_fetch_array($result))
{
mysqli_close($con);
?>
<form method="post" action="edit_data.php">
<input type="text" name="id" value="<? echo "$row[id]"?>">
<tr>
<td>Firma</td>
<td>
<input type="text" name="name"
size="40" value="<? echo "$row[Name]"?>">
</td>
</tr>
<tr>
<td>Wer</td>
<td>
<input type="text" name="wer" size="40"
value="<? echo "$row[Wer]"?>">
</td>
</tr>
<tr>
<td>Erhalten</td>
<td>
<input type="text" name="erhalten" size="40"
value="<? echo "$row[Erhalten]"?>">
</td>
</tr>
<tr>
<td>Digital</td>
<td>
<input type="text" name="digital" size="40"
value="<? echo "$row[Digital]"?>">
</td>
</tr>
<tr>
<td>Betrag in Euro</td>
<td>
<input type="text" name="betrag" size="40"
value="<? echo "$row[Betrag]"?>">
</td>
</tr>
<tr>
<td>Bezahlt am</td>
<td>
<input type="text" name="bezahlt" size="40"
value="<? echo "$row[Bezahlt]"?>">
</td>
</tr>
<tr>
<td>Anmerkung</td>
<td>
<input type="text" name="anmerkung" size="40"
value="<? echo "$row[Anmerkung]"?>">
</td>
</tr>
<tr>
<td align="right">
<input type="submit"
name="submit value" value="Edit">
</td>
</tr>
</form>
</table>
<?php }?>
I don't know why but my table cuts off right after the second <td> tag... can anyone help, I have constantly looked over it over and over. Can someone help me find where the problem is?
<tr>
<td>Username:</td>
<td>
<input name="username" type="text" value='<?
if($form->value("username")==""){
echo($req_user_info["username"]);
}else{
echo $form->value("username");
}
?>' size="56" maxlength="30">
</td>
<td>
<? echo($form->error("username")); ?>
</td>
</tr>
<tr>
<td>New Password:</td>
<td>
<input name="newpass" type="password" value='<?
echo($form->value("newpass"));
?>' size="56" maxlength="30">
</td>
<td>
<? echo($form->error("newpass")); ?>
</td>
</tr>
Btw, that code is only the first two rows.
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>
<form action="adminprocess.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr>
<td>Username:</td>
<td>
<input name="username" type="text" value='<?php
if($form->value("username")==""){
echo($req_user_info["username"]);
}else{
echo $form->value("username");
}
?>' size="56" maxlength="30">
</td>
<td>
<?php echo($form->error("username")); ?>
</td>
</tr>
<tr>
<td>New Password:</td>
<td>
<input name="newpass" type="password" value='<?php
echo($form->value("newpass"));
?>' size="56" maxlength="30">
</td>
<td>
<?php echo($form->error("newpass")); ?>
</td>
</tr>
<tr>
<td>Confirm New Password:</td>
<td><input name="conf_newpass" type="password" value='
<?php echo $form->value("newpass"); ?>' size="56" maxlength="30"></td>
<td><?php echo $form->error("newpass"); ?></td>
</tr>
</tr>
<td>Edit motto:</td>
<td><input type="text" size="56" name="motto" value='<?php
if($form->value("motto") == ""){
echo $req_user_info['motto'];
}else{
echo $form->value("motto");
}
?>'></td>
<tr>
<tr>
<td>Edit profile bio:</td>
<td><textarea cols="40" rows="10" name="profile" value=""><?php
if($form->value("profile") == ""){
echo $req_user_info['profile'];
}else{
echo $form->value("profile");
}
?></textarea></td>
<tr>
<tr>
<td>Email:</td>
<td><input name="email" type="text" value='
<?php
if($form->value("email") == ""){
echo $req_user_info["email"];
}else{
echo $form->value("email");
}
?>' size="56" maxlength="50">
</td>
<td><?php echo $form->error("email"); ?></td>
</tr>
<tr>
<td>User level:</td>
<td><input name="userlevel" type="text" value='
<?php
if($form->value("userlevel") == ""){
echo $req_user_info["userlevel"];
}else{
echo $form->value("userlevel");
}
?>' size="4" maxlength="10"></td>
<td><?php echo $form->error("userlevel"); ?></td>
</tr>
<tr><td align="right">
<input type="hidden" name="subedit" value="1">
<input type="hidden" name="usertoedit" value="<?php echo $usertoedit; ?>">
<input type="submit" name="button" value="Edit Account">
</td>
<td colspan="2" style="text-align:right;">
<input type="submit" name="button" value="Delete" onclick="return confirm ('Are you sure you want to delete this user, this cannot be undone?\n\n' + 'Click OK to continue or Cancel to Abort!')">
</td>
</tr>
</table>
</form>
I've changed your syntax a little..
<tr>
<td>Username:</td>
<td><input name="username" type="text" value="<?php echo htmlspecialchars(($form->value("username")=="" ? $req_user_info["username"] : $form->value("username"))); ?>" size="56" maxlength="30"></td>
<td><?php echo $form->error("username"); ?></td>
</tr>
<tr>
<td>New Password:</td>
<td><input name="newpass" type="password" value="<?php echo htmlspecialchars($form->value("newpass")); ?>" size="56" maxlength="30"></td>
<td><?php echo $form->error("newpass"); ?></td>
</tr>
For additional php error logging, put this at the top of the page:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
?>
I have a form which loops if the value indicated is less than or equal the number of 'enrollee's needed. The while loop works perfectly with one exception, I use DOB fields which ALSO use FOR loops to display their values. If I remove the DOB fields, the form loop works fine, when left in, it errors out. Any ideas?
<form id="Enroll_Form" action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="Enroll_Form" >
<?php
$i=1;
while ($i <= ($_SESSION['Num_Members'])): {?>
<table class="demoTable">
<tr>
<td>First Name: </td>
<td><input type="text" name="F1FirstName" value="<?php echo $fields['F1FirstName']; ?>" /></td>
</tr>
<tr>
<td>Middle Initial: </td>
<td><input type="text" name="F1MI" size="2" maxlength="1" value="<?php echo $fields['F1MI']; ?>" /></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input type="text" name="F1LastName" value="<?php echo $fields['F1LastName']; ?>" /></td>
</tr>
<tr>
<td>Federation No: </td>
<td><input type="text" name="F1FedNum" maxlength="10" value="<?php echo $fields['F1FedNum']; ?>" /></td>
</tr>
<tr>
<td>SSN: </td>
<td><input type="text" name="F1SSN1" size="3" maxlength="3" value="<?php echo $fields['F1SSN1']; ?>" /> -
<input type="text" name="F1SSN2" size="2" maxlength="2" value="<?php echo $fields['F1SSN2']; ?>" /> -
<input type="text" name="F1SSN3" size="4" maxlength="4" value="<?php echo $fields['F1SSN3']; ?>" />
</td>
</tr>
<tr>
<td>Date of Birth</td>
<td>
<select name="F1DOB1">
<option value="">Month</option>
<?php
for ($i=1; $i<=12; $i++)
{
echo "<option value='$i'";
if ($fields["F1DOB1"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select> /
<select name="F1DOB2">
<option value="">Day</option>
<?php
for ($i=1; $i<=31; $i++)
{
echo "<option value='$i'";
if ($fields["F1DOB2"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select> /
<select name="F1DOB3">
<option value="">Year</option>
<?php
for ($i=date('Y'); $i>=1900; $i--)
{
echo "<option value='$i'";
if ($fields["F1DOB3"] == $i)
echo " selected";
echo ">$i</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>Address: </td>
<td><input type="text" name="F1Address" value="<?php echo $fields['F1Address']; ?>" /></td>
</tr>
<tr>
<td>City: </td>
<td><input type="text" name="F1City" value="<?php echo $fields['F1City']; ?>" /></td>
</tr>
<tr>
<td>State: </td>
<td><select name="F1State"><option value="">Choose a State</option><?php showOptionsDrop($states_arr, null, true); ?></select></td>
</tr>
<tr>
<td>Zip Code: </td>
<td><input type="text" name="F1Zip" size="6" maxlength="5" value="<?php echo $fields['F1Zip']; ?>" /></td>
</tr>
<tr>
<td>Contact Telephone No: </td>
<td>( <input type="text" name="F1Phone1" size="3" maxlength="3" value="<?php echo $fields['F1Phone1']; ?>" /> )
<input type="text" name="F1Phone2" size="3" maxlength="3" value="<?php echo $fields['F1Phone2']; ?>" /> -
<input type="text" name="F1Phone3" size="4" maxlength="4" value="<?php echo $fields['F1Phone3']; ?>" />
</td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="F1Email" value="<?php echo $fields['F1Email']; ?>" /></td>
</tr>
</table>
<br />
<?php } $i++; endwhile; ?>
<div align="right"><input class="enrbutton" type="submit" name="submit" value="Continue" /></div>
</form>
You are using $i in your while loop, and in all of your for loops. You need to change it to something else.
That is probably causing you some problems (not to mention it being terribly hard to understand)