Updating Records

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cover

    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>SystemsD oc Update</title>
    </head>
    <body bgcolor="white" >
    <form method="POST" action="sysdocu pdate.php">
    <table>
    <col span="1" align="right">
    <tr>
    <td><font color="blue">UI D 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_P OST_VARS as $varname => $value)
    $formVars[$varname]=$value;
    require_once("c onfig.php");
    $db1=mysql_conn ect($dbhost, $dbuname, $dbpass);
    mysql_select_db ("sysops");
    $query="SELECT * FROM systemsdoc WHERE UID =
    \"".$formVar s["UID"]."\"";
    $result=mysql_q uery($query);
    $row=mysql_fetc h_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_dat e"]=$row["deploy_dat e"];
    $formVars["sernum"]=$row["sernum"];
    $formVars["assetnum"]=$row["assetnum"];
    $formVars["machname"]=$row["machname"];
    $formVars["sysversion "]=$row["sysversion "];
    $formVars["UID"]=$row["UID"];
    mysql_close($db 1);
    ?>
    <html>
    <head>
    <title>SystemsD oc Update</title>
    </head>
    <body bgcolor="white" >
    <form method="post" action="postupd ate.php">
    <table>
    <col span="1" align="right">
    <tr>
    <td><font color="blue">Ma nufacturer:</font></td>
    <td><input type="text" name="manu"
    value="<? echo $formVars["manu"]; ?>" size=100></td>
    </tr>
    <tr>
    <td><font color="blue">Mo del:</font></td>
    <td><input type="text" name="model"
    value="<? echo $formVars["model"]; ?>" size=100></td>
    </tr>
    <tr>
    <td><font color="blue">Ad dress:</font></td>
    <td><input type="text" name="addr"
    value="<? echo $formVars["addr"]; ?>" size=100></td>
    </tr>
    <tr>
    <td><font color="blue">Zi p:</font></td>
    <td><input type="text" name="zip"
    value="<? echo $formVars["zip"]; ?>" size=100></td>
    </tr>
    <tr>
    <td><font color="blue">Ph one:</font></td>
    <td><input type="text" name="phone"
    value="<? echo $formVars["phone"]; ?>" size=100></td>
    </tr>
    <tr>
    <td><font color="blue">De ployment Date:</font></td>
    <td><input type="text" name="deploy_da te"
    value="<? echo $formVars["deploy_dat e"]; ?>" size=100></td>
    </tr>
    <tr>
    <td><font color="blue">Se rial Number:</font></td>
    <td><input type="text" name="sernum"
    value="<? echo $formVars["sernum"]; ?>" size=100></td>
    </tr>
    <tr>
    <td><font color="blue">As set Number:</font></td>
    <td><input type="text" name="assetnum"
    value="<? echo $formVars["assetnum"]; ?>" size=100></td>
    </tr>
    <tr>
    <td><font color="blue">Ma chine Name:</font></td>
    <td><input type="text" name="machname"
    value="<? echo $formVars["machname"]; ?>" size=100></td>
    </tr>
    <tr>
    <td><font color="blue">Sy stem Version:</font></td>
    <td><input type="text" name="sysversio n"
    value="<? echo $formVars["sysversion "]; ?>" size=100></td>
    </tr>
    <tr>
    <td><font color="blue">UI D:</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>SystemsD oc Update</title>
    </head>
    <body bgcolor="white" >
    <?php
    foreach($HTTP_P OST_VARS as $varname => $value)
    $formVars[$varname]=$value;
    require_once("c onfig.php");
    $db1=mysql_conn ect($dbhost, $dbuname, $dbpass);
    mysql_select_db ("sysops");
    echo "Record updated<br><a href=\"sysdocup date.html\">cli ck here</a>
    to update another record<br>";
    $query="UPDATE systemsdoc set ".
    "manu= \"".$formVar s["manu"]."\",".
    "model= \"".$formVar s["model"]."\",".
    "addr= \"".$formVar s["addr"]."\",".
    "zip= \"".$formVar s["zip"]."\",".
    "phone= \"".$formVar s["phone"]."\",".
    "deploy_dat e= \"".$formVar s["deploy_dat e"]."\",".
    "sernum= \"".$formVar s["sernum"]."\",".
    "assetnum= \"".$formVar s["assetnum"]."\",".
    "machname= \"".$formVar s["machname"]."\",".
    "sysversion = \"".$formVar s["sysversion "].
    "\" WHERE UID = \"".$formVar s["UID"]."\"";
    mysql_query($qu ery);
    mysql_close($db 1);
    ?>
    </body>
    </html>
  • Oli Filth

    #2
    Re: Updating Records

    cover said the following on 15/01/2006 04:34:[color=blue]
    > 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
    >[/color]

    <...SNIP CODE...>

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

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

    --
    Oli

    Comment

    Working...