GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Jan-2005, 07:45
rams rams is offline
New Member
 
Join Date: Jan 2005
Posts: 10
rams is on a distinguished road

Data Entry


Using the following two files, I'm able to click the submit button and have the date, room and pot for each of the 21 records entered into the MySql database. I still need some help getting the temperature entered.

insertform.php:
PHP Code:

<html>
<head>
<title>Insert Form</title>
</head>
<body>
<table width="300" cellpadding="5" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="left" colspan="1" rowspan="1" bgcolor="64b1ff">
<h3>Insert Record</h3>
<form method="POST" action="insert_record.php">
<!--The hidden fields are provided to maintain state. They are used to pass the username and password from script to script.-->
<input type="hidden" name="username" value="<? print $_POST['root']?>">
<input type="hidden" name="password" value="<?print $_POST['triadpass']?>">



<?
$Date = date("Y-m-d");
print "Enter pot: <input type=number name=pot size=10><br>\n";
print "Enter temp: <input type=number name=temp size=10><br>\n";
print "<br>\n";

print("<table align=center border=1>");
print("<tr>");
print("<td><font style='FONT-WEIGHT:BOLD'>Date:</font></td>");
print("<td><font style='FONT-WEIGHT:BOLD'>Room:</font></td>");
print("<td><font style='FONT-WEIGHT:BOLD'>Pot:</font></td>");
print("<td><font style='FONT-WEIGHT:BOLD'>Temp:</font></td>");
print("</tr>");
for ($Loop = 1; $Loop <= 21; $Loop++)
{
print("<tr>");
print("<td>" .$Date. "</td>");

if ($Loop <= 56)
print("<td>A</td>");
else
print("<td>B</td>");

print("<td>" .$Loop. "</td>");
print("<td><input type=text name='Temp" .$Loop."' size=3 maxlength=4></td>");
print("</tr>");
}
print("</table><br><br>");

print "<input type=submit value=Submit><input type=reset>\n";
?>
</form>
</td>
</tr>
</table>
</body>
</html> 


insertrecord.php:
PHP Code:

<html>
<head>
<title>Insert Record</title>
</head>
<body>
<?
$Date = date("Y-m-d");
$room= "A";

define(db_host, "localhost"); 
define(db_user, "root"); 
define(db_pass, "triadpass"); 
define(db, "processdata");
$link = mysql_connect(db_host,db_user,db_pass);
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db(db , $link) or die("Select Error: ".mysql_error());

for ($Loop = 1; $Loop <= 21; $Loop++)



$result=mysql_query("INSERT INTO tbltemperaturesl1 (Date, Room, Pot, Temperature) VALUES ('$Date','$room','$Loop','$Temp')")or die("Insert Error: ".mysql_error());
mysql_close($link);
print "Record added\n";
?>
<form method="POST" action="insert_form.php">
<input type="submit" value="Insert Another Record">
</form>
</body>
</html> 

Last edited by LuciWiz : 11-Jan-2005 at 07:52. Reason: Please insert your php code betweeen [php] & [/php] tags
  #2  
Old 11-Jan-2005, 09:51
Allowee's Avatar
Allowee Allowee is offline
Regular Member
 
Join Date: May 2003
Location: The Netherlands
Posts: 339
Allowee has a spectacular aura about
I think the problem is the query

you give the box a 'name' Temp##' where ## is the number $Loop has.
The insert query doesn't seem to know the ##, it enters $Temp and not $Temp.$Loop which might make it work

try this query:
PHP Code:

$result=mysql_query("INSERT INTO tbltemperaturesl1 (Date, Room, Pot, Temperature) VALUES ('$Date','$room','$Loop','".$Temp.$Loop."')")or die("Insert Error: ".mysql_error()); 


it might work
__________________
Pastebin
PHP Documentation Site
Allowee's Blog http://allowee.net
Last edited by Allowee : 11-Jan-2005 at 10:02. Reason: uhh.. wrong answer
  #3  
Old 11-Jan-2005, 10:04
rams rams is offline
New Member
 
Join Date: Jan 2005
Posts: 10
rams is on a distinguished road
In insert_form.php I changed

PHP Code:

print("<td><input type=text name='Temp" .$Loop."' size=3 maxlength=4></td>"); 



to

PHP Code:

print("<td><input type=text name='Temp[]' size=3 maxlength=4></td>"); 



and in insert_record.php I changed

PHP Code:

$result=mysql_query("INSERT INTO tbltemperaturesl1 (Date, Room, Pot, Temperature) VALUES ('$Date','$room','$Loop','$Temp')")or die("Insert Error: ".mysql_error()); 



to

PHP Code:

$result=mysql_query("INSERT INTO tbltemperaturesl1 (Date, Room, Pot, Temperature) VALUES ('$Date','$room','$Loop','$Temp[$Loop]')")or die("Insert Error: ".mysql_error()); 



That seems to have fixed the problem, thanks for your help.
 
 

Recent GIDBlogMeeting the populace by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12
Using getline to read in data krisbot C Programming Language 4 24-Oct-2004 15:57
[CONTEST?]Data Structure Test dsmith C Programming Language 2 06-Jun-2004 15:13
Automate a data change php form mjfmn MySQL / PHP Forum 4 20-Oct-2003 09:37

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 17:29.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.