Team,
I have two PHP pages. pointerface shows the 50 most recent entries in a MySQL DB in descending order. Next to each row entry is and EDIT link. This opens purchaseorder.php.
I have been fighting these two scripts for a few days now, and am getting very frustrated. I need the EDIT link to open the data for that particular row in purchaseorder.php. The link works, but no data is carried over. I have attempted to put the [ID] in the string, but it just isn’t cooperating. I’d appreciate some input here. I’m a noob, but I’m still trying.
ppointerface.php:
[php]<?php
{ // Secure Connection Script
include(’…/htconfig/dbConfig.php’);
$tbl_name=“members”; // Table name
// Connect to server and select databse.
mysql_connect("$hostname","$username","$password");
mysql_select_db("$database")or die(“cannot select DB”);
// username and password sent from form
$myusername=$_POST[‘myusername’];
$mypassword=$_POST[‘mypassword’];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql=“SELECT * FROM $tbl_name WHERE username=’$myusername’ and password=’$mypassword’”;
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file “login_success.php”
session_register(“myusername”);
session_register(“mypassword”);
?>
<label><a href="newpo.htm" target="_blank" onClick="window.open('newpo.htm', 'NewTextWindowName','width=510,height=800')"> New PO</a>
</form> </td>
<td width="705"> </td>
<td width="130"> </td>
<td width="130"> </td>
<td width="124"><div align="right"></div></td>
</tr>
<tr>
<td colspan="5"><p align="right"><?php echo "$myusername"; ?></p>
<p align="center"><img style="width: 261px; height: 155px;" alt="Rental Xpress Logo" src="../rxtrans.gif"></p>
<p align="center">Rental Xpress Purchase Order System</p> </td>
</tr>
|
<?php
$table = ‘POs’;
if (!mysql_select_db($database))
die(“Can’t select database”);
// sending query
$result = mysql_query(“SELECT * FROM {$table} ORDER BY ID DESC LIMIT 50”);
if (!$result) {
die(“Query to show fields from table failed”);
}
$fields_num = mysql_num_fields($result);
$bg_shade = ($i++ % 2 == 0) ? ‘#EfEfEf’ : ‘#dddddd’;
echo “
”;
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo "<td>{$field->name}</td>";
}
echo “
\n”;
// printing table rows
while($row = mysql_fetch_row($result))
{
$bg_shade = ($i++ % 2 == 0) ? '#EfEfEf' : '#99CCFF';
echo "<tr bgcolor=".$bg_shade.">";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo “
<a href = 'purchaseorder.php?id=”.$row[‘ID’]."’>Edit | ";
echo “\n”;
}
mysql_free_result($result);
?>
<?php
}
else {
echo "Wrong Username or Password";
}
}
?>
[/php]
purchaseorder.php:
[php]
<?php
include('../htconfig/dbConfig.php');
$tbl_name="POs"; // Table name
if(isset($_GET['ID'])) {
$id = $_GET['ID'];
}
else {
echo Error;
exit();
}
// do something here…
// example:
“SELECT * FROM database WHERE ID = $ID LIMIT 1”
?>
Purchase Order
![RXlogo]() |
PURCHASE ORDER
Date:
PO #: <?php echo $ID["ID"]?>
Vendor:
Shop:
|
|
Items:
Notes:
|
|
Amount:
|
Authorized by
Date:
|
Rental Xpress, LLC PO Box 181140 Corpus Christi, TX 78480 Phone (361) 854-1111 Fax (361) 723-2114 |
[/php]
|