Can someone please help me out and point me in the right direction of what I'm doing wrong here?
modify_inventory.php
Code: Select all
<html>
<head>
<title>Modify Current Inventory</title>
<link rel="stylesheet" href="CSS\standard.css">
</head>
<body align="center">
<h2>Modify Current Inventory</h2>
Select the part number from the drop-down list to modify.
<?php
include 'admin\db_inventory.php';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to database');
mysql_select_db($dbname);
$query = "SELECT DISTINCT partnum FROM parts;";
if($result = mysql_query($query))
{
if($success = mysql_num_rows($result) > 0)
{
echo "<form method='post' name='partnum' action='get_inventory.php'>";
echo "<select name='partnum' onchange='getInventory(this.value);'>\n";
echo "<option>-- Part Number --</option>\n";
while ($row = mysql_fetch_array($result))
echo "<option value='$row[partnum]'>$row[partnum]</option>\n";
echo "</select>\n<p />";
echo "<div align='center' id='txtHint'></div>";
}
else { echo "No results found."; }
}
else { echo "Failed to connect to database."; }
mysql_close();
?>
<script type="text/javascript">
function getInventory(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","get_inventory.php?q="+str,true);
xmlhttp.send();
}
</script>
<br />
<FORM>
<INPUT TYPE="button" VALUE="Home" onclick="window.location.href='index.php';" />
<INPUT TYPE="button" VALUE="View Inventory" onclick="window.location.href='current_inventory.php';" />
</FORM>
</body>
</html>Code: Select all
<?php
$q=$_GET["q"];
include 'admin\db_inventory.php';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to database');
mysql_select_db($dbname,$conn);
$query="SELECT p.partnum, p.quantity, p.description, p.manufacturer, p.model, s.status FROM parts p JOIN status s ON p.statusid = s.statusid WHERE partnum='".$q."'";
$result = mysql_query($query);
$stat_query="SELECT status FROM status ORDER BY statusid";
$stat_result = mysql_query($stat_query);
mysql_close($conn);
echo "
<table width='75%' class='inventory_list'>
<tr>
<th class='desc'>Part Number</th>
<th class='quan'>Quantity</th>
<th class='desc'>Description</th>
<th class='desc'>Manufacturer</th>
<th class='desc'>Model</th>
<th class='quan'>Status</th>
</tr>
<FORM ACTION='modify.php' METHOD='POST'>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['partnum'] . "</td>";
echo "<td><input type='text' class='quan' name='quan' value=" . $row['quantity'] . " /></td>";
echo "<td><input type='text' class='desc' name='desc' value=" . $row['description'] . " /></td>";
echo "<td><input type='text' class='desc' name='man' value=" . $row['manufacturer'] . " /></td>";
echo "<td><input type='text' class='desc' name='mod' value=" . $row['model'] . " /></td>";
echo "<td><select><option selected=".$row['status'].">".$row['status']."</option>\n";
while($stat_row = mysql_fetch_array($stat_result))
{
echo "<option name='stats' value='".$stat_row[status]."'>$stat_row[status]</option>\n";
}
echo "</select></td>";
echo "</tr>";
}
echo "</table>";
echo "
<INPUT type='submit' value='Submit Change' />
<INPUT type='button' value='Cancel' onclick='history.go(-1)' />
</FORM>";
?>Code: Select all
<html>
<head>
<title>Modify Part Inventory</title>
<link rel="stylesheet" href="CSS\standard.css">
</head>
<body>
<?php
include 'admin\db_inventory.php';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to SQL Database');
mysql_select_db($dbname);
$stat = "$_POST[status]";
$statquery="SELECT DISTINCT statusid FROM status WHERE status= '".$stat."'";
$result=mysql_query($statquery);
$num=mysql_num_rows($result);
while ($row=mysql_fetch_assoc($result))
{
$statid=$row["statusid"];
}
$insert="UPDATE parts SET quantity='$_POST[quan]', description='$_POST[desc]', manufacturer='$_POST[man]', model='$_POST[mod], statusid='$_POST[stats]')
WHERE partnum='$_POST[partnum]'";
if (!mysql_query($insert,$conn))
{
die("Error: ".mysql_error());
}
echo "Record changed";
mysql_close($conn)
?>
</body>
</html>