using UPDATE in MySQL

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

    #1

    using UPDATE in MySQL

    I have an input form that passes data when submitted to a second form
    to let the user know what they have just entered into the db.

    My question comes with using 'update'. I'd like to query the database
    by equipment number (equipno is unique) and query all fields from that
    row, populating an original form 'look alike' whereby the user can add
    detail to the original records as the db builds. I'm using 'date'
    twice because I'd like to have the original date the record was added
    plus the most recent update date.

    Form 1 below, is original user input:
    <html>
    <head>
    <title>Equip Input</title>
    </head>
    <body>
    <center><h3>Equ ipment Input</h3></center>
    <form method="post" action="updatin gin2.php">
    <input type="hidden" name="id" value="NULL">
    <input type="hidden" name="date1" value="<? print
    strftime("%m/%d/%Y"); ?>">
    <center>
    <table border="8">
    <tr>
    <td>Date:</td>
    <td align="left"><i nput type="text" name="date2" size="8"
    maxlength="10" value="<? print strftime("%m/%d/%Y"); ?>"></td>
    </tr>
    <tr>
    <td>Equipment Number:</td><td align="left"><i nput type="text"
    name="equipno" size="25" maxlength="15" value=""></td>
    </tr>
    <tr>
    <td>Equipment Name:</td><td align="left"><i nput type="text"
    name="equipname " size="25" maxlength="25" value=""></td>
    </tr>
    <tr>
    <td>Equipment Model No:</td><td align="left"><i nput type="text"
    name="model" size="25" maxlength="6" value=""></td>
    </tr>
    <tr>
    <td>Equipment Serial No:</td><td align="left"><i nput type="text"
    name="serial" size="25" maxlength="6" value=""></td>
    </tr>
    <tr>
    <td colspan="4" align="center"> <input type="submit"
    value="Enter"></td>
    </tr>
    </table>
    </form>
    </center><p>
    </body>
    </html>

    Form 2 below shows data that has been input to the db:
    <html>
    <head>
    <title>Equipmen t Input Form Results</title>
    </head>
    <body>
    <font color="#990099" size="+1"><span style="font-size:18"><p>
    <TABLE cellSpacing=0 cellPadding=10 width="85%" align=center
    border=8">
    <TBODY><TR><T D vAlign=top align=left><P>< FONT face=arial color=bright
    white><b>
    <?php
    $DBhost = "localhost" ; // connection information
    $DBuser = "john";
    $DBpass = "jco234";
    $DBName = "updatingin ";
    $table = "updatingin_tbl ";

    $id = $_POST['id'];
    $date1 = $_POST['date1'];
    $date2 = $_POST['date2'];
    $equipno = $_POST['equipno'];
    $equipname = $_POST['equipname'];
    $model = $_POST['model'];
    $serial = $_POST['serial'];

    mysql_connect($ DBhost,$DBuser, $DBpass) or die("Unable to connect to
    database"); // make connection to database
    mysql_select_db ($DBName) or die("Unable to select database $DBName");
    // select database
    // if (mysqli_connect _errno()) removed for go live 7/21/05
    // {
    // echo 'Error: Could not connect to database. Please report this
    problem to Chris Overland.';
    // exit;
    // }
    $sqlquery = "INSERT INTO $table (id, date1, date2, equipno, equipname,
    model, serial) VALUES('$id', '$date1', '$date2', '$equipno',
    '$equipname', '$model', '$serial')";
    $results = mysql_query($sq lquery) or die("Query failed: $sqlquery<br>"
    ..
    mysql_error());
    echo mysql_error();
    mysql_close();
    print "<center><t able border=\"0\"
    width=\"500\">< tr><td>";
    print "<p><font face=\"verdana\ " size=\"+0\"> <center>You
    Just Entered This Information into the Database<p><blo ckquote>";
    print "Date: $date2<p>Equipm ent Number: $equipno<p>Equi pment Name:
    $equipname<p>Mo del: $model<p>Serial :
    $serial</blockquote></td></tr></table>
    </CENTER>
    </body>
    </html>";
    ?>
    </FONT></CENTER></b>
    </H3></TD></TR></TBODY></TABLE>
    </body>
    </html><p>

    Form 3 below shows where I hope to query results from the db
    (updatingin) and place them into my form 1 'look alike' which would be
    for updating records. Hope that makes sense. Finally, I would VERY
    much appreciate any pointers on getting the form data to show in my
    update form. TIA and gratefully yours, :-) Chris

    <html>
    <head>
    <title>Equip Update</title>
    </head>
    <body>
    <center><h3>Equ ipment Input</h3></center>
    <form method="post" action="updatin gin2.php">
    <input type="hidden" name="date2" value="<? print
    strftime("%m/%d/%Y"); ?>">
    <center>
    <table border="8">
    <tr>
    <td>id:</td><td align="left"><i nput type="text" name="id" size="25"
    maxlength="15" value=""></td>
    </tr>
    <tr>
    <td>Equipment Number:</td><td align="left"><i nput type="text"
    name="equipno" size="25" maxlength="15" value=""></td>
    </tr>
    <tr>
    <td>Equipment Name:</td><td align="left"><i nput type="text"
    name="equipname " size="25" maxlength="25" value=""></td>
    </tr>
    <tr>
    <td>Equipment Model No:</td><td align="left"><i nput type="text"
    name="model" size="25" maxlength="6" value=""></td>
    </tr>
    <tr>
    <td>Equipment Serial No:</td><td align="left"><i nput type="text"
    name="serial" size="25" maxlength="6" value=""></td>
    </tr>
    <tr>
    <td colspan="4" align="center"> <input type="submit" value="Update
    Record"></td>
    </tr>
    </table>
    </form>
    </center><p>
    </body>
    </html>
  • cover

    #2
    Re: using UPDATE in MySQL

    On Sat, 22 Apr 2006 10:59:05 -0700, cover wrote:

    So I guess in short, what I'm looking for is a single field text
    search to populate table 3 where the successful query result of this
    form:

    <html>
    <head>
    <title>Equip Update Search</title>
    </head>
    <body>
    <center><h3>Equ ipment Update Search</h3></center>
    <form method="post" action="updatin gin4.php">
    <center>
    <table border="8">
    <tr>
    <td>Equipment Number:</td><td align="left"><i nput type="text"
    name="equipno" size="25" maxlength="15" value=""></td>
    </tr>
    <tr>
    <td colspan="4" align="center"> <input type="submit"
    value="Search"> </td>
    </tr>
    </table>
    </form>
    </center><p>
    </body>
    </html>

    Populates the form below where an 'equipno' is found in the db:

    <html>
    <head>
    <title>Equip Update</title>
    </head>
    <body>
    <center><h3>Equ ipment Update</h3></center>
    <form method="post" action="updatin gin2.php">
    <input type="hidden" name="date2" value="<? print
    strftime("%m/%d/%Y"); ?>">
    <center>
    <table border="8">
    <tr>
    <td>id:</td><td align="left"><i nput type="text" name="id" size="25"
    maxlength="15" value=""></td>
    </tr>
    <tr>
    <td>Equipment Number:</td><td align="left"><i nput type="text"
    name="equipno" size="25" maxlength="15" value=""></td>
    </tr>
    <tr>
    <td>Equipment Name:</td><td align="left"><i nput type="text"
    name="equipname " size="25" maxlength="25" value=""></td>
    </tr>
    <tr>
    <td>Equipment Model No:</td><td align="left"><i nput type="text"
    name="model" size="25" maxlength="6" value=""></td>
    </tr>
    <tr>
    <td>Equipment Serial No:</td><td align="left"><i nput type="text"
    name="serial" size="25" maxlength="6" value=""></td>
    </tr>
    <tr>
    <td colspan="4" align="center"> <input type="submit" value="Update
    Record"></td>
    </tr>
    </table>
    </form>
    </center><p>
    </body>
    </html>

    Comment

    • Martin Jay

      #3
      Re: using UPDATE in MySQL

      In message <3avk42ha27snej lt1f7q5uvvc35vn i2glq@4ax.com>, cover
      <coverlandNOSPA M914@yahoo.com> writes[color=blue]
      >On Sat, 22 Apr 2006 10:59:05 -0700, cover wrote:
      >
      >So I guess in short, what I'm looking for is a single field text
      >search to populate table 3 where the successful query result of this
      >form:[/color]

      $find=$_POST['equipno'];
      $table = /* name of your MySQL table */

      /* Connect and select your database as in input file */

      $item = mysql_query("SE LECT * FROM $table WHERE equipno = '$find'");

      Then:
      $item['id'] is your id;
      $item['date1'] is your first date;
      $item['date2'] is your second date;

      etc.

      --
      Martin Jay

      Comment

      • Martin Jay

        #4
        Re: using UPDATE in MySQL

        In message <ABM8kTGoDNTEFw CI@spam-free.org.uk>, Martin Jay
        <martin@spam-free.org.uk> writes[color=blue]
        >In message <3avk42ha27snej lt1f7q5uvvc35vn i2glq@4ax.com>, cover
        ><coverlandNOSP AM914@yahoo.com > writes[color=green]
        >>On Sat, 22 Apr 2006 10:59:05 -0700, cover wrote:
        >>
        >>So I guess in short, what I'm looking for is a single field text
        >>search to populate table 3 where the successful query result of this
        >>form:[/color]
        >
        >$find=$_POST['equipno'];
        >$table = /* name of your MySQL table */
        >
        >/* Connect and select your database as in input file */
        >
        >$item = mysql_query("SE LECT * FROM $table WHERE equipno = '$find'");
        >
        >Then:
        >$item['id'] is your id;
        >$item['date1'] is your first date;
        >$item['date2'] is your second date;
        >
        >etc.[/color]

        Ooops, I forgot about mysql_fetch_arr ay, it should be something like:

        $item = mysql_query("SE LECT * FROM $table WHERE equipno = '$find'");
        $row = mysql_fetch_arr ay($list);

        Then:

        $row['id'] is your id;
        $row['date1'] is your first date;
        $row['date2'] is your second date;
        --
        Martin Jay

        Comment

        • Jerry Stuckle

          #5
          Re: using UPDATE in MySQL

          Martin Jay wrote:[color=blue]
          > In message <3avk42ha27snej lt1f7q5uvvc35vn i2glq@4ax.com>, cover
          > <coverlandNOSPA M914@yahoo.com> writes
          >[color=green]
          >> On Sat, 22 Apr 2006 10:59:05 -0700, cover wrote:
          >>
          >> So I guess in short, what I'm looking for is a single field text
          >> search to populate table 3 where the successful query result of this
          >> form:[/color]
          >
          >
          > $find=$_POST['equipno'];
          > $table = /* name of your MySQL table */
          >
          > /* Connect and select your database as in input file */
          >
          > $item = mysql_query("SE LECT * FROM $table WHERE equipno = '$find'");
          >
          > Then:
          > $item['id'] is your id;
          > $item['date1'] is your first date;
          > $item['date2'] is your second date;
          >
          > etc.
          >[/color]

          Not quite.

          $result = mysql_query("SE LECT * FROM $table WHERE equipno = '$find'");
          $item = mysql_fetch_arr ay($result);

          NOW:
          $item['id'] is your id;
          $item['date1'] is your first date;
          $item['date2'] is your second date;

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • cover

            #6
            Re: using UPDATE in MySQL

            Thanks very much guys - appreciate the help. :-)

            Comment

            Working...