By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 769 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

using UPDATE in MySQL

P: n/a
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>Equipment Input</h3></center>
<form method="post" action="updatingin2.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"><input type="text" name="date2" size="8"
maxlength="10" value="<? print strftime("%m/%d/%Y"); ?>"></td>
</tr>
<tr>
<td>Equipment Number:</td><td align="left"><input type="text"
name="equipno" size="25" maxlength="15" value=""></td>
</tr>
<tr>
<td>Equipment Name:</td><td align="left"><input type="text"
name="equipname" size="25" maxlength="25" value=""></td>
</tr>
<tr>
<td>Equipment Model No:</td><td align="left"><input type="text"
name="model" size="25" maxlength="6" value=""></td>
</tr>
<tr>
<td>Equipment Serial No:</td><td align="left"><input 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>Equipment 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><TD 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($sqlquery) or die("Query failed: $sqlquery<br>"
..
mysql_error());
echo mysql_error();
mysql_close();
print "<center><table border=\"0\"
width=\"500\"><tr><td>";
print "<p><font face=\"verdana\" size=\"+0\"> <center>You
Just Entered This Information into the Database<p><blockquote>";
print "Date: $date2<p>Equipment Number: $equipno<p>Equipment Name:
$equipname<p>Model: $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>Equipment Input</h3></center>
<form method="post" action="updatingin2.php">
<input type="hidden" name="date2" value="<? print
strftime("%m/%d/%Y"); ?>">
<center>
<table border="8">
<tr>
<td>id:</td><td align="left"><input type="text" name="id" size="25"
maxlength="15" value=""></td>
</tr>
<tr>
<td>Equipment Number:</td><td align="left"><input type="text"
name="equipno" size="25" maxlength="15" value=""></td>
</tr>
<tr>
<td>Equipment Name:</td><td align="left"><input type="text"
name="equipname" size="25" maxlength="25" value=""></td>
</tr>
<tr>
<td>Equipment Model No:</td><td align="left"><input type="text"
name="model" size="25" maxlength="6" value=""></td>
</tr>
<tr>
<td>Equipment Serial No:</td><td align="left"><input 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>
Apr 22 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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>Equipment Update Search</h3></center>
<form method="post" action="updatingin4.php">
<center>
<table border="8">
<tr>
<td>Equipment Number:</td><td align="left"><input 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>Equipment Update</h3></center>
<form method="post" action="updatingin2.php">
<input type="hidden" name="date2" value="<? print
strftime("%m/%d/%Y"); ?>">
<center>
<table border="8">
<tr>
<td>id:</td><td align="left"><input type="text" name="id" size="25"
maxlength="15" value=""></td>
</tr>
<tr>
<td>Equipment Number:</td><td align="left"><input type="text"
name="equipno" size="25" maxlength="15" value=""></td>
</tr>
<tr>
<td>Equipment Name:</td><td align="left"><input type="text"
name="equipname" size="25" maxlength="25" value=""></td>
</tr>
<tr>
<td>Equipment Model No:</td><td align="left"><input type="text"
name="model" size="25" maxlength="6" value=""></td>
</tr>
<tr>
<td>Equipment Serial No:</td><td align="left"><input 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>
Apr 22 '06 #2

P: n/a
In message <3a********************************@4ax.com>, cover
<co****************@yahoo.com> writes
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:


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

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

$item = mysql_query("SELECT * 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
Apr 24 '06 #3

P: n/a
In message <AB**************@spam-free.org.uk>, Martin Jay
<ma****@spam-free.org.uk> writes
In message <3a********************************@4ax.com>, cover
<co****************@yahoo.com> writes
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:


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

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

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

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

etc.


Ooops, I forgot about mysql_fetch_array, it should be something like:

$item = mysql_query("SELECT * FROM $table WHERE equipno = '$find'");
$row = mysql_fetch_array($list);

Then:

$row['id'] is your id;
$row['date1'] is your first date;
$row['date2'] is your second date;
--
Martin Jay
Apr 24 '06 #4

P: n/a
Martin Jay wrote:
In message <3a********************************@4ax.com>, cover
<co****************@yahoo.com> writes
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:

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

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

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

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

etc.


Not quite.

$result = mysql_query("SELECT * FROM $table WHERE equipno = '$find'");
$item = mysql_fetch_array($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.
js*******@attglobal.net
==================
Apr 24 '06 #5

P: n/a
Thanks very much guys - appreciate the help. :-)
Apr 26 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.