467,074 Members | 825 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,074 developers. It's quick & easy.

Updating Records

I'm trying to put together a system that upgrades records in a
database and apparently have run into a bit of a glitch. I think the
problem is with the $HTTP_POST_VARS portion of the code. Is there
some variable that has to be set for this to work properly or what?
Ideas anyone? TIA

The Input form: (1 of 3 forms)
<html>
<head>
<title>SystemsDoc Update</title>
</head>
<body bgcolor="white">
<form method="POST" action="sysdocupdate.php">
<table>
<col span="1" align="right">
<tr>
<td><font color="blue">UID to Update:</font></td>
<td><input type="text" name="UID" size=100></td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>

This one populates the fields for updating:
<?php
foreach($HTTP_POST_VARS as $varname => $value)
$formVars[$varname]=$value;
require_once("config.php");
$db1=mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db("sysops");
$query="SELECT * FROM systemsdoc WHERE UID =
\"".$formVars["UID"]."\"";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$formVars = array();
$formVars["manu"]=$row["manu"];
$formVars["model"]=$row["model"];
$formVars["addr"]=$row["addr"];
$formVars["zip"]=$row["zip"];
$formVars["phone"]=$row["phone"];
$formVars["deploy_date"]=$row["deploy_date"];
$formVars["sernum"]=$row["sernum"];
$formVars["assetnum"]=$row["assetnum"];
$formVars["machname"]=$row["machname"];
$formVars["sysversion"]=$row["sysversion"];
$formVars["UID"]=$row["UID"];
mysql_close($db1);
?>
<html>
<head>
<title>SystemsDoc Update</title>
</head>
<body bgcolor="white">
<form method="post" action="postupdate.php">
<table>
<col span="1" align="right">
<tr>
<td><font color="blue">Manufacturer:</font></td>
<td><input type="text" name="manu"
value="<? echo $formVars["manu"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Model:</font></td>
<td><input type="text" name="model"
value="<? echo $formVars["model"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Address:</font></td>
<td><input type="text" name="addr"
value="<? echo $formVars["addr"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Zip:</font></td>
<td><input type="text" name="zip"
value="<? echo $formVars["zip"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Phone:</font></td>
<td><input type="text" name="phone"
value="<? echo $formVars["phone"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Deployment Date:</font></td>
<td><input type="text" name="deploy_date"
value="<? echo $formVars["deploy_date"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Serial Number:</font></td>
<td><input type="text" name="sernum"
value="<? echo $formVars["sernum"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Asset Number:</font></td>
<td><input type="text" name="assetnum"
value="<? echo $formVars["assetnum"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">Machine Name:</font></td>
<td><input type="text" name="machname"
value="<? echo $formVars["machname"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">System Version:</font></td>
<td><input type="text" name="sysversion"
value="<? echo $formVars["sysversion"]; ?>" size=100></td>
</tr>
<tr>
<td><font color="blue">UID:</font></td>
<td><input type="text" name="UID"
value="<? echo $formVars["UID"]; ?>" size=100></td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
</tr>
</body>
</html>

This one does the update:
<html>
<head>
<title>SystemsDoc Update</title>
</head>
<body bgcolor="white">
<?php
foreach($HTTP_POST_VARS as $varname => $value)
$formVars[$varname]=$value;
require_once("config.php");
$db1=mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db("sysops");
echo "Record updated<br><a href=\"sysdocupdate.html\">click here</a>
to update another record<br>";
$query="UPDATE systemsdoc set ".
"manu= \"".$formVars["manu"]."\",".
"model= \"".$formVars["model"]."\",".
"addr= \"".$formVars["addr"]."\",".
"zip= \"".$formVars["zip"]."\",".
"phone= \"".$formVars["phone"]."\",".
"deploy_date= \"".$formVars["deploy_date"]."\",".
"sernum= \"".$formVars["sernum"]."\",".
"assetnum= \"".$formVars["assetnum"]."\",".
"machname= \"".$formVars["machname"]."\",".
"sysversion= \"".$formVars["sysversion"].
"\" WHERE UID = \"".$formVars["UID"]."\"";
mysql_query($query);
mysql_close($db1);
?>
</body>
</html>
Jan 15 '06 #1
  • viewed: 1257
Share:
1 Reply
cover said the following on 15/01/2006 04:34:
I'm trying to put together a system that upgrades records in a
database and apparently have run into a bit of a glitch. I think the
problem is with the $HTTP_POST_VARS portion of the code. Is there
some variable that has to be set for this to work properly or what?
Ideas anyone? TIA


<...SNIP CODE...>

$HTTP_POST_VARS has been superceded by $_POST since PHP 4.1.0.

Also worth mentioning that you should use mysql_real_escape_string() on
all user-entered string values used in a MySQL query, and explicitly
cast numeric types before using in the SQL query.

--
Oli
Jan 15 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Chris Jackson | last post: by
reply views Thread by | last post: by
4 posts views Thread by Darrel | last post: by
1 post views Thread by davidgordon@scene-double.co.uk | last post: by
2 posts views Thread by Alexey.Murin@gmail.com | last post: by
10 posts views Thread by chimambo@googlemail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.