$answers = $_POST['answer'];
// Loop through it
for ($i = 0; $i < count($answers); $i++) {
echo $answers[$i].'<br />';
}
$answers = $_POST['answer'];
// Loop through it
for ($i = 0; $i < count($answers); $i++) {
echo $answers[$i].'<br />';
}
Change your query string from
$query = "SELECT userid, username, password, userdesc FROM login WHERE (UserName='$u' AND Password='$p') and DelCategory='0'";
to:
$query = "SELECT userid, username, password, userdesc FROM login WHERE (UserName='".addslashes($u)."' AND Password='".addslashes($u)."') and DelCategory='0'";
Here I added slashes for parameters before executing query to avoid the SQL injections and make the $query be valid query.
Try this:
1) Make a HTML more clear by using three separated fields for DOB filed:
<select name="yearOfBirth">
<option value="">---Select year---</option>
<?php for ($i = 1980; $i < date('Y'); $i++) : ?>
<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
<?php endfor; ?>
</select>
<select name="monthOfBirth">
<option value="">---Select month---</option>
<?php for ($i = 1; $i <= 12; $i++) : ?>
<option value="<?php echo ($i < 10) ? '0'.$i : $i; ?>"><?php echo $i; ?></option>
<?php endfor; ?>
</select>
<select name="dateOfBirth">
<option value="">---Select date---</option>
<?php for ($i = 1; $i <= 31; $i++) : ?>
<option value="<?php echo ($i < 10) ? '0'.$i : $i; ?>"><?php echo $i; ?></option>
<?php endfor; ?>
</select>
2) Get the posted data:
$yearOfBirth = $_POST['yearOfBirth'];
$monthOfBirth = $_POST['monthOfBirth'];
$dateOfBirth = $_POST['dateOfBirth'];
// Validate
if ($yearOfBirth != '' && $monthOfBirth != '' && $dateOfBirth != '') {
// Generate date of birth in format of YYYY-mm-dd
$date = $yearOfBirth.'-'.$monthOfBirth.'-'.$dateOfBirth;
// Then insert to database as normal
...
}
Try this:
UPDATE your_table
SET age_field = IF(age_field < DATEDIFF(DATE_FORMAT(now(), '%Y-%m-%d'), created_date), DATEDIFF(DATE_FORMAT(now(), '%Y-%m-%d'), created_date), age_field);
You have to use global keyword for variable if it has been defined out of function.
So, the following code should work:
$filename = "names.txt";
$data = array();
$key = 1;
# get the data from current file
if (file_exists($filename)) {
$data = parse_ini_file($filename, true);
}
function txtupdate($k) {
global $data;
$fp = fopen($filename, 'w');
ksort($data);
foreach ($data as $key => $dataArray) {
fwrite($fp, "[$key]\n");
foreach ($dataArray as $k => $v) {
fwrite($fp, "$k=$v\n");
}
fwrite($fp, "\n");
}
fclose($fp);
}
Name the form elements as array by using [] at the end of name property.
1) Form:
<?php
while (&row=mysql_fetch_array($reclooptbl)) {
?>
<tr>
<td><input type="text" name="ratings[]" /></td>
<td><input type="text" name="courseIds[]" value="<?php echo $row['courseid']; ?>" /></td>
</tr>
<?php
}
?>
2) Process form when user click on submit button:
$ratings = $_POST['ratings'];
$courseIds = $_POST['courseIds'];
if (is_array($courseIds)) {
for ($i = 0; $i < count($courseIds); $i++) {
$sql = 'UPDATE tbl SET rating='.addslashes($ratings[$i]).' WHERE course_id='.addslashes($courseIds[$i]);
// Execute query
...
}
}
Check the length of the field you want to insert.
If length of this filed is 2, so it should insert "on" instead of full string as "On Process".