I'm working on a profile page, where a registered user can update their information. Because the user has already submitted their information, I would like their information from the database to populate my HTML form.
Within PHP, I'm creating the HTML form with the values filled in. However, I've tried creating an IF statement to determine whether an option is selected as the default value. Right now, my website is giving me a default value of the last option, Undeclared. Therefore, I'm not sure if all IF statements are evaluation as true, or if it is simply skipping to selected=selected.
Here is my HTML, which is currently embedded with PHP(<?php ?>):
<?php
// Connect to MySQL
$db = mysql_connect("", "xxx", "xxx");
if (!$db)
{
exit("Error - Could not connect to MySQL");
}
$er = mysql_select_db("cs329e_fall11_nemo008", $db);
if (!$er)
{
exit("Error - Could not select the database");
}
$query = "SELECT *
FROM tblMembers
WHERE Username = 'fzr11017' ";
$result = mysql_query($query);
if (!$result)
{
print("Error - The query could not be executed");
$error = mysql_error();
print("<p>:" . $error . "</p>");
exit;
}
$row = mysql_fetch_array($result);
print <<<FORM
<form id="frmRegister" action="update.php" method="post" onsubmit="return Validate()" >
<table>
<tr>
<th><br /></th>
<td><br /></td>
</tr>
<tr>
<th align="left">Username:</th>
<td><input type="text" name="Username" maxlength="10" value=$row[Username] readonly="readonly"/></td>
</tr>
<tr>
<th align="left">First Name:</th>
<td><input type="text" name="FirstName" value=$row[FirstName] readonly="readonly" /></td>
</tr>
<tr>
<th align="left">Last Name:</th>
<td><input type="text" name="LastName" value=$row[LastName] readonly="readonly" /></td>
</tr>
<tr>
<th align="left">Email Address:</th>
<td><input type="text" name="Email" value=$row[Email] /></td>
</tr>
<tr>
<th align="left">Phone Number:</th>
<td><input type="text" name="Phone" maxlength="10" value=$row[Phone] /></td>
</tr>
<tr>
<th align="left">Year:</th>
<td>
<select name="Year" >
<option if(strcmp($row[Year], 'Freshman') == 0){ selected="selected"} >Freshman</option>
<option if(strcmp($row[Year], 'Sophomore') == 0){ selected="selected"} >Sophomore</option>
<option if(strcmp($row[Year], 'Junior') == 0){ selected="selected"} >Junior</option>
<option if(strcmp($row[Year], 'Senior') == 0){ selected="selected"} >Senior</option>
</select>
</td>
</tr>
<tr>
<th align="left">Primary Major:</th>
<td>
<select name="Major">
<option if($row[Major] == Accounting){ selected="selected"}>Accounting</option>
<option if($row[Major] == Business Honors Program){ selected="selected"}>Business Honors Program</option>
<option if($row[Major] == Engineering Route to Business){ selected="selected"}>Engineering Route to Business</option>
<option if($row[Major] == Finance){ selected="selected"}>Finance</option>
<option if($row[Major] == International Business){ selected="selected"}>International Business</option>
<option if($row[Major] == Management){ selected="selected"}>Management</option>
<option if($row[Major] == Management Information Systems){ selected="selected"}>Management Information Systems</option>
<option if($row[Major] == Marketing){ selected="selected"}>Marketing</option>
<option if($row[Major] == MPA){ selected="selected"}>MPA</option>
<option if($row[Major] == Supply Chain Management){ selected="selected"}>Supply Chain Management</option>
<option if($row[Major] == Undeclared){ selected="selected"}>Undeclared</option>
</select>
</td>
</tr>
<tr>
<th><br /></th>
<td><br /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="btnSubmit" value="Submit" /></td>
<td align="center"><input type="reset" value="Reset" /></td>
</tr>
</table>
</form>
FORM;
?>
You've mixed HTML and PHP without declaring PHP tags and you've also used 'selected' as an attribute...
<select name="Major">
<option <?php echo ($row['Major'] == "Accounting") ? " selected" : ""; ?>>Accounting</option>
....
</select>
I've done the first one, but you can follow the same pattern
That code looks like it could use a towel:
<select name="Major">
<?php
$options = array(
'Accounting'
, 'Business Honors Program'
, 'Engineering Route to Business'
, 'Finance'
, 'International Business'
, 'Management'
, 'Management Information Systems'
, 'Marketing'
, 'MPA'
, 'Supply Chain Management'
, 'Undeclared'
);
foreach( $options as $option )
{
printf(
"<option%s>%s</option>\n"
, ($row['Major'] == $option ? ' selected="selected"' : '')
, htmlentities($option)
);
}
?>
</select>
You might find some of this reading useful to help explain some of the concepts used above:
arrays
foreach loop
ternary operator (?:)
printf()
htmlentities()
You seem to be missing any tags in your code, which means that nothing is being processed. Something more along the lines of this should be used:
<option <?php if($row["Major"] == "Accounting"){ echo "selected"; } ?>>Accounting</option>
Related
I have some search fields that look across a few different tables.
"display_name" form field and "last" form field show different results then what it does directly into phpmyadmin.
If i echo out the mysql query in my php script and paste it into phpmyadmin. It lists of correct results. However on the php/html page it is not listing the same.
For example. If someones name full name is nathan spencer and i put spencer into the "last" form field it will only show 1 result or 2 results. HOWEVER there are actually 5 results found by pasting it directly into phpmyadmin and running it.
I have been battling for ages with this and its driving me nuts.
Here is the PHP up the top of the page:
<?php
// SEARCH
if(isset($_POST['submit'])) {
// define the list of fields
$fields = array('display_name', 'last', 'suburb', 'state', 'user_type', 'active');
$conditions = array();
// loop through the defined fields
foreach($fields as $field){
// if the field is set and not empty
if(isset($_POST[$field]) && $_POST[$field] != '') {
// create a new condition while escaping the value inputed by the user (SQL Injection)
$conditions[] = "`$field` LIKE '%".mysql_real_escape_string($_POST[$field])."%'";
}
}
// builds the query
$query = "SELECT display_name, first, last, suburb, state, user_type, active FROM nfw_users ";
// if there are conditions defined
if(count($conditions) > 0) {
// append the conditions
$query .= "WHERE " . implode (' AND ', $conditions) .""; // you can change to 'OR', but I suggest to apply the filters cumulative
}
else {
echo "No records found";
}
$result = mysql_query($query);
$score = mysql_fetch_assoc($result);
}
?>
and here is the html form
<form method="post" action="index.php">
<tr>
<td>Name:</td>
<td><input type="text" name="display_name" /></td>
</tr>
<tr>
<td>Street:</td>
<td><input type="text" name="last" /></td>
</tr>
<tr>
<td>Suburb:</td>
<td><input type="text" name="suburb" /></td>
</tr>
<tr>
<td>State:</td>
<td>
<select name="state">
<option>
<option value="qld">QLD</option>
<option value="sa">SA</option>
<option value="nt">NT</option>
<option value="wa">WA</option>
<option value="vic">VIC</option>
<option value="tas">TAS</option>
<option value="act">ACT</option>
</select>
</td>
</tr>
<tr>
<td>Type:</td>
<td>
<select name="user_type">
<option>
<option value="franchise">Franchisee</option>
<option value="regional">Regional</option>
<option value="state">State</option>
<option value="national">National</option>
<option value="office">Headoffice Staff</option>
</select>
</td>
</tr>
<tr>
<td>Active:</td>
<td>
<select name="active">
<option></option>
<option value="1">Active</option>
<option value="0">Not Active</option>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Search" /></td>
</tr>
</form>
<form method="post" action="index.php">
<tr>
<td>Name:</td>
<td><input type="text" name="display_name" /></td>
</tr>
<tr>
<td>Street:</td>
<td><input type="text" name="last" /></td>
</tr>
<tr>
<td>Suburb:</td>
<td><input type="text" name="suburb" /></td>
</tr>
<tr>
<td>State:</td>
<td>
<select name="state">
<option>
<option value="qld">QLD</option>
<option value="sa">SA</option>
<option value="nt">NT</option>
<option value="wa">WA</option>
<option value="vic">VIC</option>
<option value="tas">TAS</option>
<option value="act">ACT</option>
</select>
</td>
</tr>
<tr>
<td>Type:</td>
<td>
<select name="user_type">
<option>
<option value="franchise">Franchisee</option>
<option value="regional">Regional</option>
<option value="state">State</option>
<option value="national">National</option>
<option value="office">Headoffice Staff</option>
</select>
</td>
</tr>
<tr>
<td>Active:</td>
<td>
<select name="active">
<option></option>
<option value="1">Active</option>
<option value="0">Not Active</option>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Search" /></td>
</tr>
</form>
and here is the results that get printed into a table
<?php if(isset($score)){
while($score=mysql_fetch_assoc($result)){
$display_name = $score['display_name'];
$lastname = $score['last'];
$state = $score['state'];
$active = $score['active'];
if ($active=='1') {
$activeother = "<i class='fa fa-check' style='color:green;'></i>";
}
else {
$activeother = "<i class='fa fa-times' style='color:red;'></i>";
}
?>
<?php
$content = "<tr><td>" . $score['display_name'] . "</td><td>" . $score['first'] . "</td><td>" . $score['last'] . " </td><td>" . $score['email'] . " </td><td> " . $score['mobile'] . " </td><td> " . $score['landline'] . "</td><td>$activeother</td><td> " . $score['user_type'] . "</td><td> " . date('d-m-Y', strtotime($score['date_join'])) . "</td><td class='invoicing-columns'><a class='btn btn-yellow' href='view-invoices.php?id=" . $score['id_num'] . "'><i class='fa fa-eye'></i></a></td><td class='invoicing-columns'><a class='btn btn-red' href='del-customers.php?id=" . $score['id_num'] . "' onclick='return check();' class='delete'><i class='fa fa-minus-circle'></i></a></td></tr>";
echo $content;
}}
?>
If I got your code right there might be issue:
Here you actually fetching first row.
$result = mysql_query($query);
$score = mysql_fetch_assoc($result);
Then it seems that you simply skip it and go with loop:
if(isset($score)){
while($score=mysql_fetch_assoc($result)){
What you really want to do is:
$result = mysql_query($query);
if (!$result) {
//TODO: Query error handling
}
// This is how you check for results count
if (mysql_num_rows($result) == 0) {
while ($score = mysql_fetch_assoc($result)) {
//Here you go with result
}
}
You can also check this manual link as reference.
Next thing to check, get exact string from query and try it from phpMyAdmin. Make sure that you use same user as your code does, when doing query.
And one more thing, extension you are using is long time deprecated, you should consider to switching to MySQLi or PDO_MySQL
I'm trying to update the account's bill, but this error came out
"Cannot add or update a child row: a foreign key constraints fails". I've searched for the reason and most of it stated that it's because inserting value that are not available in the primary table. However I in my form for the bill registration, i use dropdown box that contains account number from that primary table,yet it still has this error.
the form
<div id="contact_form">
<form method="post" action="proses_daftar_bill.php" name="maklumat_bill" oninput= "JumlahBayaran.value = parseFloat(AmaunCaj.value) + parseFloat(AmaunTunggakan.value) + parseFloat(AmaunPenalti.value) + parseFloat(AmaunPelbagai.value) + parseFloat(CajPF.value) + parseFloat(GST.value)">
<table>
<tr>
<label for="NoAkaun">Nombor Akaun</label>
<?php
require ("dbase.php");
$sql = "SELECT NoAkaun FROM maklumatakaun";
$result = mysql_query($sql);
echo "<select name='NoAkaun' id='NoAkaun' class='input_field' required /><option></option>";
while($kod = mysql_fetch_array($result)){
echo "<option value=".$kod['NoAkaun'].">" .$kod['NoAkaun']."</OPTION>";
}
echo "</select>";
?>
</tr>
<tr>
<td><label for="BulanBil">Tarikh Bil:</label> </td>
<td><select class="required bill_caj" name="BulanBil" id="BulanBil" width="300px" required/>
<option value="">--Pilih Bulan--</option>
<option value="Januari">Januari</option>
<option value="Februari">Februari</option>
<option value="Mac">Mac</option>
<option value="April">April</option>
<option value="Mei">Mei</option>
<option value="Jun">Jun</option>
<option value="Julai">Julai</option>
<option value="Ogos">Ogos</option>
<option value="September">September</option>
<option value="Oktober">Oktober</option>
<option value="November">November</option>
<option value="Disember">Disember</option>
</select></td>
<label for="TahunBil"></label><td><input type="text" maxlength="4" size="4" id="TahunBil" name="TahunBil" class="required year_field" placeholder="Tahun" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" required/></td>
</tr>
<tr>
<td>
<div class="cleaner_h10"></div>
<div class="cleaner_h10"></div>
<div class="cleaner_h10"></div>
<div class="cleaner_h10"></div>
</td>
</tr>
<tr>
<td><label for="AmaunCaj">Amaun</label></td>
<td><input type="text" name="AmaunCaj" id="AmaunCaj" class="bill_caj" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" required></td>
<td><label for="AmaunTunggakan">Tunggakan</label></td>
<td><input type="text" name="AmaunTunggakan" id="AmaunTunggakan" class="bill_caj" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" required></td>
</tr>
<tr>
<td><label for="AmaunPenalti">Penalti</label></td>
<td><input type="text" name="AmaunPenalti" id="AmaunPenalti" class="bill_caj" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"required></td>
<td><label for="AmaunPelbagai">Pelbagai</label></td>
<td><input type="text" name="AmaunPelbagai" id="AmaunPelbagai" class="bill_caj" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"required></td>
</tr>
<tr>
<td><label for="GST">GST</label></td>
<td><input type="text" name="GST" id="GST" class="bill_caj" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"required></td>
</tr>
<tr>
<td><label for="checkbox_pf">PF<input type="checkbox" onclick="codename()" name="checkbox_pf" value="ON"></label></td>
<td><label for="BacaanPF">Bacaan PF:</label></td>
<td><input type="text" id="BacaanPF" name="BacaanPF" class="bill_caj" value="0" disabled onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"></td>
</tr>
<tr>
<td></td>
<td><label for="CajPF">Caj PF:</label></td>
<td><input type="text" id="CajPF" name="CajPF" class="bill_caj" value="0" disabled onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"></td>
</tr>
<tr>
<td><label for="JumlahBayaran">Jumlah Bayaran:</label></td>
<td><input id="JumlahBayaran" name="JumlahBayaran" class="bill_caj" for="AmaunCaj AmaunTunggakan" step="any" readonly></td>
<div class="cleaner_h10"></div>
</tr>
<tr>
<td><input type="submit" value="Daftar" id="submit" name="register-submit" class="submit_btn " /></td>
<td><input type="reset" value="Batal" id="reset" name="reset" class="submit_btn" /></td>
</tr>
</table>
</form>
the sql
<?php
require("dbase.php");
if ($_POST) {
$TarikhData = isset($_POST['TarikhData']) ? $_POST['TarikhData'] : '';
$username = isset($_POST['username']) ? $_POST['username'] : '';
$NoAkaun = isset($_POST['NoAkaun']) ? $_POST['NoAkaun'] : '';
$BulanBil = isset($_POST['BulanBil']) ? $_POST['BulanBil'] : '';
$TahunBil = isset($_POST['TahunBil']) ? $_POST['TahunBil'] : '';
$AmaunCaj = isset($_POST['AmaunCaj']) ? $_POST['AmaunCaj'] : '';
$AmaunTunggakan = isset($_POST['AmaunTunggakan']) ? $_POST['AmaunTunggakan'] : '';
$AmaunPenalti = isset($_POST['AmaunPenalti']) ? $_POST['AmaunPenalti'] : '';
$AmaunPelbagai = isset($_POST['AmaunPelbagai']) ? $_POST['AmaunPelbagai'] : '';
$GST = isset($_POST['GST']) ? $_POST['GST'] : '';
$BacaanPF = isset($_POST['BacaanPF']) ? $_POST['BacaanPF'] : '';
$CajPF = isset($_POST['CajPF']) ? $_POST['CajPF'] : '';
$JumlahBayaran = isset($_POST['JumlahBayaran']) ? $_POST['JumlahBayaran'] : '';
$sql = mysql_query("INSERT INTO maklumatbilakaun VALUES ('', '$TarikhData' , '$username' , '$NoAkaun' , '$BulanBil' , '$TahunBil' ,'$AmaunCaj' ,'$AmaunTunggakan' ,'$AmaunPenalti' ,'$AmaunPelbagai' , '$GST' , '$BacaanPF' ,'$CajPF' ,'$JumlahBayaran')");
echo mysql_error();
}
?>
what actually is the problem?
Without specifying the columns for your values in your insert statement, you're prone to having your values being inserted in the wrong columns.
$sql = mysql_query("INSERT INTO
maklumatbilakaun (TarikhData, username, NoAkaun, BulanBil, TahunBil, AmaunCaj, AmaunTunggakan, AmaunPenalti, AmaunPelbagai, GST, BacaanPF, CajPF, JumlahBayaran)
VALUES ('$TarikhData' , '$username' , '$NoAkaun' , '$BulanBil' , '$TahunBil' ,'$AmaunCaj' ,'$AmaunTunggakan' ,'$AmaunPenalti' ,'$AmaunPelbagai' , '$GST' , '$BacaanPF' ,'$CajPF' ,'$JumlahBayaran')");
You'll also need to supply DEFAULT to columns instead of empty values or omit the columns when building your insert statement (I prefer the latter approach, although I'm not sure how efficient string concatenation is in php).
I am using this code to serach database and I am using 4 fields in this code but this code does not serach database value.
where problem in this code tell me plz edit my code for full working serach with 4 fields
my code :
<?php
{
include ('connection.php');
if(isset($_REQUEST['submit'])){
$optid = $_POST['OPRID'];
$optdec = $_POST['OPRDEFNDESC'];
$empid = $_POST['EMPLID'];
$empmail = $_POST['EMAILID'];
$query ="SELECT * FROM OPERATOR WHERE OPRID LIKE '%".$optid."%'
or OPRDEFNDESC LIKE '%".$optdec."%' or EMPLID LIKE '%".$empid."%'
or EMAILID LIKE '%".$empmail."%' ";
}
else{
$query="SELECT * FROM OPERATOR";
$objParse = oci_parse ($ora_conn, $query);
}
?>
<form action="multi.php" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>">
<table width="500" border="1" align="center">
<tr>
<th>Operator ID
<input name="OPRID" type="text" id="OPRID" value="";>
<tr>
<th>Operator Name
<input name="OPRDEFNDESC" type="text" id="OPRDEFNDESC" value="";>
<tr>
<th>Person ID
<input name="EMPLID" type="text" id="EMPLID" value="";>
<tr>
<th>Email ID
<input name="EMAILID" type="text" id="EMAILID" value="";>
<input type="submit" value="Search"></th>
</tr>
</table>
</form>
<table>
<tr>
<td>Operator ID</td>
<td>Operator Name</td>
<td>Person ID</td>
<td>Email ID</td>
</tr>
<?
$success = oci_execute($objParse);
//while($objResult = oci_fetch_array($objParse,OCI_BOTH))
while($objResult = oci_fetch_array($objParse, OCI_RETURN_NULLS+OCI_ASSOC))
{
?>
<tr>
<td><div align="center"><?=$objResult["OPRID"];?></div></td>
<td><?=$objResult["OPRDEFNDESC"];?></td>
<td><?=$objResult["EMPLID"];?></td>
<td><div align="center"><?=$objResult["EMAILID"];?></div></td>
<td align="center"><a href="Optr_Edit.php?OprID=
<?=$objResult["OPRID"];?>">Edit</a></td>
</tr>
<?
}
?>
</table>
<?
oci_free_statement($objParse);
oci_close($ora_conn);
}
?>
Try like this
<tr>
<td><div align="right"><strong>Password Encrypted:</strong></div></td>
<td>
<select name="txtENCRYPTED">
<option value="">Select</option>
<option <?php if ($objResult["ENCRYPTED"] == "Y") {echo 'selected';} ?>value="Y">Y</option>
<option <?php if ($objResult["ENCRYPTED"] == "N") {echo 'selected';} ?> value="N">N</option>
</select>
</td>
</tr>
You are doing it wrong
Select element do not have value attribute
You have value attribute only in options element.
For eg:
<select name="txtENCRYPTED" id="txtENCRYPTED">
<option value="">Select</option>
<option value="Y">Y</option>
<option value="N">N</option>
</select>
In your code you have provided the db-retrived-data in tags setting .
The tag defines the menu. It can have the following settings
The name setting adds an internal name to the field so the program that handles the form can identify the fields.
The size option defines how many items should be visible at a time. Default is one item.
The multiple setting will allow for multiple selections if present.
The tag defines the single items in the menu.
The value setting defines what will be submitted if the item is selected.
one solution :-
<form method="post" action="" >
<select name="encrypt" value="encrypted" id='select'>
<option value="">Select</option>
<option value="<?php if($objResult["ENCRYPTED"]=='Y'){ echo 'Y'; } ?>">Y</option>
<option value="<?php if($objResult["ENCRYPTED"]=='N'){ echo 'N'; } ?>">N</option>
</select>
<input type="submit" value="submit" id='form'/>
</form>
</td>
</tr>
//script type jquery.js
//script type javascript
$(document).ready(function(){
$('form').submit(function(){
alert($('#select').val());
});
});
</script>
I would like to insert datetime stamp into a variable once the if-condition is satisfied. But I get the following error:
Notice: Undefined index: status in C:\wamp\www\business\edit_log_widget.php on line 55
The following is the php code:
<?php
include 'scripts/init.php';
include 'html/header.php';
$page = 'servers';
$id =$_SESSION['logid'];
$query = "SELECT *FROM log WHERE logid = $id";
$query_submit = mysql_query($query) or die(mysql_error);
$row = mysql_fetch_assoc($query_submit);
?>
<div class="article">
<h2><span>Edit Logs</span></h2>
<div class="clr"></div>
<form action="" method="POST" >
<p>
<table border="0">
<tr>
<td><label for="Task Name">Task Name:*</label></td>
<td><input type="text" name="task_name" size="45" value="<?php echo $row['task_name'] ?>"/></td>
</tr>
<tr>
<td><label for="description">Problem Description:*</label></td>
<td><textarea name="description" cols="33" rows="10" ><?php echo $row['description'] ?></textarea></td>
</tr>
<tr>
<td><label for="solution">Solution Description:*</label></td>
<td><textarea name="solution" cols="33" rows="10" ><?php echo $row['solution'] ?></textarea></td>
</tr>
<tr>
<td><label for="status">Status:*</label></td>
<td>
<select id="Select2" name="status">
<option>-Select-</option>
<option>Resolved</option>
<option>Un-resolved</option>
<option>In-Progress</option>
</select>
</td>
</tr>
</table>
</p>
<p>
<td><input id="Submit" type="submit" value="Submit" /></td>
<td><input id ="Clear and Restart" type ="reset" value= "Clear and Restart" /></td>
</p>
<?php
if($_POST['status']== 'Resolved')
{
$today = DateTime::createFromFormat('!Y-m-d',date('Y-m-d')); // This is Line 55
}
if(isset($_GET['success']) && empty($_GET['sucess']))
{
echo 'the log has been captured';
}
else
{
if(empty($_POST) === false && empty($errors)=== true)
{
//Update Log details
$update_log = array(
'task_name'=>$_POST['task_name'],
'description' => $_POST['description'],
'solution' =>$_POST['solution'],
'status'=>$_POST['status'],
'closed_date'=>$today,
'userid' =>$_SESSION['userid']);
update_log($update_log);
//redirect
header('Location: edit_log_widget.php?success');
exit();
}
else if(empty($errors) === false)
{
//output errors if the errors array is not empty
echo output($errors);
}
}
?>
</form>
<?php
include 'html/side_menu.php';
include 'html/footer.php';
?>
Update: edit_log.php.
<?php
include 'scripts/init.php';
include 'html/header.php';
$page = 'servers';
$id = $_GET['logid'];
$_SESSION['logid'] = $id;
$query = "SELECT *FROM log WHERE logid = $id";
$query_submit = mysql_query($query) or die(mysql_error);
$row = mysql_fetch_assoc($query_submit);
?>
<div class="article">
<h2><span>Edit Logs</span></h2>
<div class="clr"></div>
<form action="edit_log_widget.php" method="POST" >
<p>
<table border="0">
<tr>
<td><label for="Task Name">Task Name:*</label></td>
<td><input type="text" name="task_name" size="45" value="<?php echo $row['task_name'] ?>"/></td>
</tr>
<tr>
<td><label for="description">Problem Description:*</label></td>
<td><textarea name="description" cols="33" rows="10" ><?php echo $row['description'] ?></textarea></td>
</tr>
<tr>
<td><label for="solution">Solution Description:*</label></td>
<td><textarea name="solution" cols="33" rows="10" ><?php echo $row['solution'] ?></textarea></td>
</tr>
<tr>
<td><label for="status">Status:*</label></td>
<td>
<select id="Select2" name="status">
<option>-Select-</option>
<option value="Resolved">Resolved</option>
<option value="Un-resolved">Un-resolved</option>
<option value="In-Progress">In-Progress</option>
</select>
</td>
</tr>
</table>
</p>
<p>
<td><input id="Submit" type="submit" value="Submit" /></td>
<td><input id ="Clear and Restart" type ="reset" value= "Clear and Restart" /></td>
</p>
</form>
<?php
include 'html/side_menu.php';
include 'html/footer.php';
?>
You haven't specified any value to your options ;)
<option value="Resolved">Resolved</option>
The PHP code is executed before the form has been submitted, and therefor $_POST['status'] has not yet been defined.
$_POST['status']
the entry status of the array $_POST is not defined
You are trying to access variables that are not yet set.
To avoid that you could check first, if the form was submitted before e.g.
<?php
if(!empty($_POST['Submit'])){
if($_POST['status']== 'Resolved')
{
$today = DateTime::createFromFormat('!Y-m-d',date('Y-m-d')); // This is Line 55
}
if(isset($_GET['success']) && empty($_GET['sucess']))
{
echo 'the log has been captured';
}
else
{
if(empty($_POST) === false && empty($errors)=== true)
{
//Update Log details
$update_log = array(
'task_name'=>$_POST['task_name'],
'description' => $_POST['description'],
'solution' =>$_POST['solution'],
'status'=>$_POST['status'],
'closed_date'=>$today,
'userid' =>$_SESSION['userid']);
update_log($update_log);
//redirect
header('Location: edit_log_widget.php?success');
exit();
}
else if(empty($errors) === false)
{
//output errors if the errors array is not empty
echo output($errors);
}
}
}
?>
You're missing some html props, your <option> must have a the value prop like so:
<td>
<select id="Select2" name="status">
<option value="0">-Select-</option>
<option value="1">Resolved</option>
<option value="2">Un-resolved</option>
<option value="3">In-Progress</option>
</select>
</td>
You're getting that error because you're missing it on your first html snippet, while you have it on your second, so there's nothing for PHP to get
I moved all the php to the top of the html form and now it works fine. Thanks guys for trying to help me out
i have done one php project and i have uploaded it on server.I had devlopveped it on windowas and now i am trying to deploy it on remote linux server. But i am geting error.
Some parts of page are not shown i donr know why?
For example i have one page appply as follows . i can see only top part other parts i cant see.
<?php
require 'inc/header.php';
require 'inc/config.php';
require 'inc/functions.php';
$QUERY0 = "
SELECT *
FROM states
";
$result0 = send_query($QUERY0);
$i=0;
while($row = mysql_fetch_array($result0))
{
$states_names[$i]=$row['sname'];
$states_val[$i] =$row['id'];
$i++;
}
$QUERY1 = "
SELECT *
FROM courses
";
$result1 = send_query($QUERY1);
$i=0;
while($row = mysql_fetch_array($result1))
{
$courses_names[$i]=$row['cname'];
$courses_val[$i]=$row['id'];
$i++;
}
$QUERY2 = "
SELECT *
FROM jobprofile
";
$result2 = send_query($QUERY2);
$i=0;
while($row = mysql_fetch_array($result2))
{
$jobprofiles_names[$i]=$row['jobname'];
$jobprofile_val[$i]=$row['jobid'];
$i++;
}
$QUERY3 = "
SELECT *
FROM edu
";
$result3 = send_query($QUERY3);
$i=0;
while($row = mysql_fetch_array($result3))
{
$edu_names[$i]=$row['eduq'];
$edu_val[$i]=$row['id'];
// echo "***********" .$edu_names[$i];
$i++;
}
?>
<div class="left">
<div class="left_articles">
<h2>Register</h2>
<p class="description">Please submit the folloing form</p>
<p>
<form action="check.php" method="post">
<table border="0">
<tbody>
<tr>
<td>First name</td>
<td><input type="text" name="fname" value="" /></td>
</tr>
<tr>
<td>Last name</td>
<td><input type="text" name="lname" value="" /></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="address" value="" /></td>
</tr>
<tr>
<td>age</td>
<td><input type="text" name="age" value="" /></td>
</tr>
<tr>
<td>State of origin</td>
<td>
<select name="origin">
<? $i=0;
foreach( $states_names as $state )
{
$val= $states_val[$i] ;
?>
<option value="<? echo $val; ?>"><? echo $state; ?> </option>
<?
$i++;
}
?>
</select>
</td>
</tr>
<tr>
<td>Mobile no</td>
<td><input type="text" name="mobile" value="" /></td>
</tr>
<tr>
<td>Sex</td>
<td><select name="sex">
<option value="1">Male</option>
<option value="0">Female</option>
</select></td>
</tr>
<tr>
<td>Marrital Status</td>
<td><select name="ms">
<option value="0">Single</option>
<option value="1">Married</option>
</select></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" value="" /></td>
</tr>
<tr>
<td>Job Applying For</td>
<td><select name="jobtype">
<? $i=0;
foreach( $jobprofiles_names as $job )
{
$val= $jobprofile_val[$i] ;
?>
<option value="<? echo $val; ?>"><? echo $job; ?> </option>
<?
$i++;
}
?>
</select>
</td>
</tr>
<tr>
<td>Have u worked in this sector before</td>
<td><select name="exp">
<option value="0">no</option>
<option value="1">yes</option>
</select></td>
</tr>
<tr>
<td>Which department of this sector u have worked?</td>
<td> <input type="text" name="exptype" value="" />
</td>
</tr>
<tr>
<td>Years of experinece in this sector</td>
<td><input type="text" name="yrsexp" value="" /></td>
</tr>
<tr>
<td>Higest Educational qualification</td>
<td><select name="eduq">
<? $i=0;
foreach( $edu_names as $ed)
{
$val= $edu_val[$i];
?>
<option value="<? echo $val; ?>"><? echo $ed; ?> </option>
<?
$i++;
}
?>
</select>
</td>
</tr>
<tr>
<td>Course taken in above educational qualification</td>
<td><select name="crc">
<? $i=0;
foreach( $courses_names as $crc)
{
$val= $courses_val[$i];
?>
<option value="<? echo $val; ?>"><? echo $crc; ?> </option>
<?
$i++;
}
?>
</select>
</td>
</tr>
<tr>
<td>Grade obtained in the above educational qualification</td>
<td><select name="grade">
<option value="0">A</option>
<option value="1">B</option>
<option value="2">C</option>
<option value="3">D</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Apply now" /></td>
</tr>
</tbody>
</table>
<input type="hidden" name="action" value="check" />
</form>
</p>
</div>
</div>
<? require 'inc/right.php' ?>
<? require 'inc/footer.php' ?>
my file description are as follows.
header contains header
righ.php contains right side of page
why are my pages not shown fully? does there is a problem with slash / postion ??
is it different on windows and linux?
Are the files and directories for inc and inc/headers.php all lowercase in the filesystem? Unix filenames are case sensitive. Change the includes to require to see if it causes an error.
You're experiencing Windows and Linux are handling relative paths differently.
Use absolute paths (note that php on both Windows and Linux both accept the forward slash directory separator).
Assuming (a Linux server example) your application is always executing from absolute path:
/home/www/index.php
And your include scripts are located:
/home/www/inc/header.php
...
Then you can define an absolute path and concatenate it to each include string:
<?php
define('ABSPATH', dirname(__FILE__));
...
include ABSPATH . '/inc/header.php';
...
include ABSPATH . '/inc/footer.php';
?>
You should also check the line endings in all your files. If you developed on Windows, chances are pretty high that you have cr/lf line endings throughout your files, or even a mixed state. Depending on how you transferred the files to the Linux server, they might get converted or not. Especially a mixed state can cause trouble.
Another check would be the encoding of the files - these should also be consistent throughout your project. If they are in UTF-8, make sure that they don't have a Byte-order mark (BOM), as this can cause trouble with included files.
What do you mean by the "top parts"?
Also, try changing your php tags to explicitly label themselves as php, so
<?php ... ?>
instead of
<? ... ?>
The DIRECTORY_SEPARATOR constant will help you here.
Replace:
require 'inc/header.php';
with:
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'header.php';
And do something similar for the rest.