J_90
11-12-2011, 01:43 PM
Hi All,
I've had a go at modifying a script so my users can update a field, submit it and their update replaces the information currently stored on their details held on my DB. The problem i have is i cannot get or set the users id as they login, so that it updates only their information.
What i have so far, i have a page called dispatched.php, with the following code:
<?php
//make connection to dbase
$connection = @mysql_connect($server, $dbusername, $dbpassword)
or die(mysql_error());
$db = @mysql_select_db($db_name,$connection)
or die(mysql_error());
// get value of id that sent from address bar
$id=$_GET['id'];
//build and issue the query
$sql ="SELECT * FROM $table_name";
$result = @mysql_query($sql,$connection) or die(mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.header { color: #D2A77B;
}
</style>
</head>
<body>
<p> </p>
<p><span class="header"><?php echo $_SESSION[user_name]; ?></span></p>
<p> </p>
<p> </p>
<p> </p>
<table width="667" border="1">
<tr>
<td width="72">Index</td>
<td width="80">Flight Number</td>
<td width="97">Departure ICAO</td>
<td width="75">Arrival ICAO</td>
<td width="50">Type</td>
<td width="161">Comments</td>
<td width="86">Complete?</td>
<td width="86">Approved</td>
</tr>
<tr>
<td>1.</td>
<td><span class="header"><?php echo $_SESSION[flt_no1]; ?></span></td>
<td><span class="header"><?php echo $_SESSION[dep_ICAO1]; ?></span></td>
<td><span class="header"><?php echo $_SESSION[arr_ICAO1]; ?></span></td>
<td><span class="header"><?php echo $_SESSION[type1]; ?></span></td>
<td><span class="header"><?php echo $_SESSION[comments1]; ?></span></td>
<td><label for="complete_1"></label>
<input name="complete1" type="text" id="complete1" value="<? echo $_SESSION[complete1]; ?>" size="15" /></td>
<td><span class="header"><?php echo $_SESSION[approved1]; ?></span></td>
</tr>
<tr>
<td>2.</td>
<td> </td>
<td><span class="header"><?php echo $_SESSION[dep_ICAO2]; ?></span></td>
<td> </td>
<td> </td>
<td> </td>
<td><label for="checkbox2"></label></td>
<td> </td>
</tr>
<tr>
<td>3.</td>
<td> </td>
<td><span class="header"><?php echo $_SESSION[dep_ICAO3]; ?></span></td>
<td> </td>
<td> </td>
<td> </td>
<td><label for="checkbox3"></label></td>
<td> </td>
</tr>
<tr>
<td>4.</td>
<td> </td>
<td><span class="header"><?php echo $_SESSION[dep_ICAO4]; ?></span></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>5.</td>
<td> </td>
<td><span class="header"><?php echo $_SESSION[dep_ICAO5]; ?></span></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>6.</td>
<td> </td>
<td><span class="header"><?php echo $_SESSION[dep_ICAO6]; ?></span></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>" /></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<form name="form1" method="post" action="dispatch_update.php">
<input type="submit" name="Submit" id="Submit" value="Submit" />
</form>
<p> </p>
</body>
</html>
So what's happening here is the pilot can see many fields that are populated from info currently held on the database. The field i wish them to be able to change is complete1, so they can type Yes/No if its been completed. Once they type this in the complete box and hit submit, the form is checked/processed by the next page dispatch_update.php.
dispatch_update.php
[code]
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
/* obtain the form data */
$id = $_POST['id'];
$user_name = $_POST['username'];
$complete1 = $_POST['complete1'];
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// update data in mysql database
$sql="UPDATE $tbl_name SET complete1='$complete1' WHERE id = '$id'";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='list_records.php'>View result</a>";
}
else {
echo "ERROR";
}
?>
[code]
So what is mean't to happen here is the database grabs the user id, from when they logged in and it posts the field altered by the pilot (yes or no), so when they go back to the dispatched.php page it will now show in the complete field yes/no. What actually happens is if i hit submit, it tell me the change has been successfull, but doesn't actually update the info held on the database for that particular user.
I hope you can help me with this
Kind regards
Josh
I've had a go at modifying a script so my users can update a field, submit it and their update replaces the information currently stored on their details held on my DB. The problem i have is i cannot get or set the users id as they login, so that it updates only their information.
What i have so far, i have a page called dispatched.php, with the following code:
<?php
//make connection to dbase
$connection = @mysql_connect($server, $dbusername, $dbpassword)
or die(mysql_error());
$db = @mysql_select_db($db_name,$connection)
or die(mysql_error());
// get value of id that sent from address bar
$id=$_GET['id'];
//build and issue the query
$sql ="SELECT * FROM $table_name";
$result = @mysql_query($sql,$connection) or die(mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.header { color: #D2A77B;
}
</style>
</head>
<body>
<p> </p>
<p><span class="header"><?php echo $_SESSION[user_name]; ?></span></p>
<p> </p>
<p> </p>
<p> </p>
<table width="667" border="1">
<tr>
<td width="72">Index</td>
<td width="80">Flight Number</td>
<td width="97">Departure ICAO</td>
<td width="75">Arrival ICAO</td>
<td width="50">Type</td>
<td width="161">Comments</td>
<td width="86">Complete?</td>
<td width="86">Approved</td>
</tr>
<tr>
<td>1.</td>
<td><span class="header"><?php echo $_SESSION[flt_no1]; ?></span></td>
<td><span class="header"><?php echo $_SESSION[dep_ICAO1]; ?></span></td>
<td><span class="header"><?php echo $_SESSION[arr_ICAO1]; ?></span></td>
<td><span class="header"><?php echo $_SESSION[type1]; ?></span></td>
<td><span class="header"><?php echo $_SESSION[comments1]; ?></span></td>
<td><label for="complete_1"></label>
<input name="complete1" type="text" id="complete1" value="<? echo $_SESSION[complete1]; ?>" size="15" /></td>
<td><span class="header"><?php echo $_SESSION[approved1]; ?></span></td>
</tr>
<tr>
<td>2.</td>
<td> </td>
<td><span class="header"><?php echo $_SESSION[dep_ICAO2]; ?></span></td>
<td> </td>
<td> </td>
<td> </td>
<td><label for="checkbox2"></label></td>
<td> </td>
</tr>
<tr>
<td>3.</td>
<td> </td>
<td><span class="header"><?php echo $_SESSION[dep_ICAO3]; ?></span></td>
<td> </td>
<td> </td>
<td> </td>
<td><label for="checkbox3"></label></td>
<td> </td>
</tr>
<tr>
<td>4.</td>
<td> </td>
<td><span class="header"><?php echo $_SESSION[dep_ICAO4]; ?></span></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>5.</td>
<td> </td>
<td><span class="header"><?php echo $_SESSION[dep_ICAO5]; ?></span></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td>6.</td>
<td> </td>
<td><span class="header"><?php echo $_SESSION[dep_ICAO6]; ?></span></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>" /></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
<form name="form1" method="post" action="dispatch_update.php">
<input type="submit" name="Submit" id="Submit" value="Submit" />
</form>
<p> </p>
</body>
</html>
So what's happening here is the pilot can see many fields that are populated from info currently held on the database. The field i wish them to be able to change is complete1, so they can type Yes/No if its been completed. Once they type this in the complete box and hit submit, the form is checked/processed by the next page dispatch_update.php.
dispatch_update.php
[code]
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
/* obtain the form data */
$id = $_POST['id'];
$user_name = $_POST['username'];
$complete1 = $_POST['complete1'];
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// update data in mysql database
$sql="UPDATE $tbl_name SET complete1='$complete1' WHERE id = '$id'";
$result=mysql_query($sql);
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='list_records.php'>View result</a>";
}
else {
echo "ERROR";
}
?>
[code]
So what is mean't to happen here is the database grabs the user id, from when they logged in and it posts the field altered by the pilot (yes or no), so when they go back to the dispatched.php page it will now show in the complete field yes/no. What actually happens is if i hit submit, it tell me the change has been successfull, but doesn't actually update the info held on the database for that particular user.
I hope you can help me with this
Kind regards
Josh