472,352 Members | 1,488 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,352 software developers and data experts.

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>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
5 2103
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
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
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
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
Thanks very much guys - appreciate the help. :-)
Apr 26 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Gary | last post by:
I haver a table of students - Say 100 students that I need to be able to update/delete and amend. I know I can do this one student at a time which...
0
by: Fraser Hanson | last post by:
Hello, I have a table which has a foreign key relationship with itself. I want and expect my updates to cascade (deletes definitely cascade as...
0
by: Jim S. | last post by:
I'm having a horrible time simply inserting the date in a MySQL database through a Visual Basic program. I have a table, called "ORDERS"; "ID" is...
17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd =...
7
by: sime | last post by:
Hi, I have a blob field in a mysql database table. I want to copy a blob from one record to another. I am having trouble transferring the data...
4
by: Japhy | last post by:
Hello, I'm am pulling data from a mysql db and want to use the data to populate a <ul. Here are relavent parts of my code : $wohdate =...
4
by: The Bear | last post by:
Has anyone successfully used MySQL with C#? I'm having problems using the Update command Here is the code snippet. I am able to connect to...
9
by: =?iso-8859-1?B?Sm/jbyBNb3JhaXM=?= | last post by:
Hi there guys, My doubt is related with MySQL and Transactions (InnoDB) so here it goes: I have a query like this: $query = 'START...
3
by: RAG2007 | last post by:
I'm using the QueryDef and Execute method to update a record in my MySQL backend. Problem: When the Passthrough update query is defined using...
0
by: silversubey | last post by:
I am trying to convert mssql triggers to mysql. I am very new to Mysql and would like some help with my code. My queries work but there has to be a...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.