You are here: using UPDATE in MySQL « PHP Programming Language « IT news, forums, messages
using UPDATE in MySQL

Posted by cover on 04/22/06 20:59

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>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация