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.
Related
I have some combobox with onchange event, and they're reset each other when selected the orther one of them, does any suggest how to retain the value on the page? this my script :
<form method="POST" name="form1" action="<?php $_SERVER['PHP_SELF'];?>">
<table border="0">
<tr>
<td colspan="6"></td>
</tr>
<tr>
<td>
<select name="select_petugas1" style="width:18px;" onchange="this.form.submit('select_petugas1');"> //first combobox
<option></option>
<?php include 'dbconn.php';
$sql_peg1="SELECT * FROM users"; $result_peg1=$conn->query($sql_peg1);
while( $row_peg1=$result_peg1->fetch_assoc() ){
echo "<option>".$row_peg1['nama']."</option>";
}
?>
</select>
</td>
<td>
<?php
if(isset($_POST['select_petugas1'])){
$select_petugas1=$_POST['select_petugas1'];
echo "<input type='text' name='select_petugas1' value='".$select_petugas1."'>"; // Throw 1st result into the text box
$sql_NIP1="SELECT NIP FROM users WHERE nama='$select_petugas1'";
$result_NIP1=$conn->query($sql_NIP1);
$row_NIP1=$result_NIP1->fetch_assoc();
$NIP1=$row_NIP1['NIP'];
?>
</td>
<td> NIP</td>
<td>:</td>
<td><input type="text" name='NIP1' value="<?php echo $NIP1; ?>"></td>
</tr> <!-- child of first result -->
<tr>
<td colspan="5" bgcolor="blue"></td>
</tr>
<tr>
<td>
<select name="peg_2" style="width:18px;" onchange="submit(this)"><!--2nd combobox-->
<option></option>
<?php
$sql_peg2="SELECT nama FROM users";
$result_peg2=$conn->query( $sql_peg2 );
while ($row_peg2=$result_peg2->fetch_assoc()){
echo "<option value='".$row_peg2['nama']."'>".$row_peg2['nama']."</option>";
}
?>
</select>
</td>
<td>
<?php
if( isset($_POST['peg_2']) ){
$peg_2=$_POST['peg_2'];
echo "<input type='text' name='peg2' value='".$peg_2."'>"; // 2nd result throw into 2nd texbox
$sql_NIP2="SELECT NIP FROM users WHERE nama='$peg_2'";
$result_NIP2=$conn->query($sql_NIP2);
$row_NIP2=$result_NIP2->fetch_assoc();
?>
</td>
<td> NIP</td>
<td>:</td>
<td><input type='text' name='NIP2' value="<?php echo $row_NIP2['NIP'];?>"> <!--2nd child of result-->
<?php
}
}
if(isset($_POST['NIP2'])){
$NIP2=$_POST['NIP2'];
echo "<br /> NIP2 :".$NIP2."<br />";
}
mysqli_close($conn);
?>
</td>
</tr>
</table>
</form>
<form method="POST" name="wilayah" id="wilayah" action="<?php $_SERVER['PHP_SELF'];?>">
<table border="1">
<tr>
<td>
<select name="select_provinsi" onchange="submit(this)" style="width:18;">
<option selected>PROVINSI</option>
<?php
include 'dbconn.php';
$sql_prov="SELECT * FROM wilayah GROUP BY provinsi";
$result_prov=$conn->query($sql_prov);
echo "";
while($row_prov=$result_prov->fetch_assoc()){
$provinsi=$row_prov['provinsi'];
echo "<option value='".$provinsi."'>".$provinsi."</option>";
}
?>
</select>
<?php
if(isset($_POST['select_provinsi'])){
$select_provinsi=$_POST['select_provinsi'];
echo "
<input type='text' name='select_provinsi' value='".$select_provinsi."' placeholder='PROVINSI'>
</td>
</tr>";
$sql_kabkota="SELECT * FROM wilayah WHERE provinsi='$select_provinsi' GROUP BY kab_kota";
$result_kabkota=$conn->query($sql_kabkota);
?>
<tr>
<td>
<select name="select_kabkota" style="width:18px;" onchange="submit(this)"><option>KAB/KOTA</option>
<?php
while($row_kabkota=$result_kabkota->fetch_assoc()){
echo "<option>".$row_kabkota['kab_kota']."</option>";
}
?>
</select>
<?php
}
if(isset($_POST['select_kabkota'])){
$select_kabkota=$_POST['select_kabkota'];
?>
<input type="text" name="kab_kota" value="<?php echo $select_kabkota;?>">
<?php
}
mysqli_close($conn);
?>
</td>
</tr>
</table>
</form>
hope any suggestion for resolved of my problem with them,,
onchange="submit(this)" means that you want to submit the form when the value of the combobox changes. So, when the form is sent, the page reloads and you get the default value of your form.
To restore the chosen value, I would do something like :
<select name="select_kabkota" style="width:18px;" onchange="submit(this)">
<option>KAB/KOTA</option>
<?php
if(isset($_POST['select_kabkota']))
$select_kabkota=$_POST['select_kabkota'];
while($row_kabkota=$result_kabkota->fetch_assoc())
{
$selected = $select_kabkota == $row_kabkota['kab_kota'] ? 'selected="selected"' : '';
echo "<option ".$selected." >".$row_kabkota['kab_kota']."</option>";
}
?>
</select>
Im trying to display my database value into the textbox using drop down menu. which is i did and it is displaying. the problem here is that when i choose an item in the drop down list, it goes back to the first choice or last choice, the explanation i got was, my loop is selecting all of the items in the field causing the drop down menu to go back to the first choice when i click on other items. can you help me with the code on how to stop going back to the first choice when i select other options. Here is my whole code. i also use functions.
home.php
<?php
session_start();
include('dbconnect.php');
include('functions.php');
if(isset($_POST['brandname'])){
$id = $_POST['brandname'];
$result = mysql_query("SELECT * FROM tblstore WHERE brandname = '$id'");
while($row = mysql_fetch_array($result)){
$price = $row['price'];
$stocks = $row['stocks'];
}
}
?>
<html>
<body>
<form method="POST" name="">
<table align="center">
<tr>
<td>Choose here:</td>
<td>
<select name = "brandname" onchange = "this.form.submit()">
<?php dropdown() ?>
</select>
</td>
</tr>
<tr>
<td>Quantity:</td>
<td><input type="text" name="qty" id="qty" value="" /></td>
</tr>
<tr>
<td>Price:</td>
<td><input type="text" name="price" id="price" value="<?php echo $price ?>" disabled/></td>
</tr>
<tr>
<td>Stocks:</td>
<td><input type="text" name="stocks" id="stocks" value="<?php echo $stocks ?>" disabled/></td>
</tr>
<tr>
<td>Total:</td>
<td><input type="text" name="total" id="total" disabled/></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</form>
<div align = "center">
hi' <?php echo $userRow['username']; ?> Sign Out
</div>
</body>
</html>
functions.php
<?php
function dropdown(){
$all = mysql_query("SELECT * FROM tblstore");
while($row = mysql_fetch_array($all)){
echo "<option value = '".$row['brandname']."' selected='selected'>" .$row['brandname'] . "</option>";
}
}
feel free to edit the whole code.. im a beginner in php and learning my way to it. thanks
Can add the multiple option if you need to select multiple
<select name="brandname" multiple>
<option value="Select">Select</option>
<?php
do {
?>
<option value="<?php echo $row['brandname']?>"> <?php echo $row['brandname'] ?></option>
<?php
} while ($row = mysql_fetch_assoc($all));
?>
</select>
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'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>