lost
Oct 25th 2005, 9:53 am
I have something a little complex here, i hope that i can explain it correctly.
I have a form with 4 textfields to start with. However, it gets dynamically created larger if the user hits the tab key in the last field, it will create a new row of textfields.
See code:
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD>Item 1</TD>
</TR>
<TR>
<TD ID="textfields">Description <INPUT TYPE="text" NAME="description" VALUE="" Part Number <INPUT TYPE="text" NAME="partno" VALUE"" ONKEYDOWN="if (event.keyCode==9) { addNewItem(); }"></TD>
</TR>
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD>Wiring Harness 1</TD>
</TR>
<TR>
<TD ID="whtextfields">Description <INPUT TYPE="text" NAME="description" VALUE="" Part Number <INPUT TYPE="text" NAME="partno" VALUE="" ONKEYDOWN="if (event.keyCode==9) { addNewWiringHarness(); }"></TD>
</TR>
</TABLE>
Now, at the end of the form there is a cancel and save button. If the save button is pressed, all the data entered in the fields gets inserted into a mysql database.
Currently, i only know how to insert 2 fields, not a indefinite number.
This is how i'm doing it:
<?php
//if 'Submit' button was pressed
if(isset($_POST['savebutton']))
{
$message = NULL;
if(ereg("[([0-9a-zA-Z_]|\-|\[|\])", $_POST['description']))
{
//valid description
$desc = $_POST['description'];
}
else
{
//invalid description
$desc = FALSE;
$message .= '<p>Description not valid.<p>';
}
if((ereg("[0-9]{6}", $_POST['partno'])) && (strlen($_POST['partno']) >= 5))
{
//valid part number
$pno = $_POST['partno'];
}
else
{
//invalid part no
$pno = FALSE;
$message .= '<P>Part No must be in the format: 999999<P>';
}
if ($desc && $pno)
{
require_once('./mysql_connect.php');
$query = "INSERT INTO systemconfig_generic(description, partno) VALUES ('$desc', '$pno')";
$result = @mysql_query($query);
if($result)
{
echo '<FONT SIZE=2>The following was added to the AWACS lab database:<br>';
echo 'Description: ' .$desc .'<br>';
echo 'Part No: ' .$pno;
}
else
{
$message = '<P><FONT SIZE=2>The following sql error occured:</P><P>' .mysql_error() .'</P><FONT>';
echo $message;
}
mysql_close();
}
Any ideas would be great please.
I have a form with 4 textfields to start with. However, it gets dynamically created larger if the user hits the tab key in the last field, it will create a new row of textfields.
See code:
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD>Item 1</TD>
</TR>
<TR>
<TD ID="textfields">Description <INPUT TYPE="text" NAME="description" VALUE="" Part Number <INPUT TYPE="text" NAME="partno" VALUE"" ONKEYDOWN="if (event.keyCode==9) { addNewItem(); }"></TD>
</TR>
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD>Wiring Harness 1</TD>
</TR>
<TR>
<TD ID="whtextfields">Description <INPUT TYPE="text" NAME="description" VALUE="" Part Number <INPUT TYPE="text" NAME="partno" VALUE="" ONKEYDOWN="if (event.keyCode==9) { addNewWiringHarness(); }"></TD>
</TR>
</TABLE>
Now, at the end of the form there is a cancel and save button. If the save button is pressed, all the data entered in the fields gets inserted into a mysql database.
Currently, i only know how to insert 2 fields, not a indefinite number.
This is how i'm doing it:
<?php
//if 'Submit' button was pressed
if(isset($_POST['savebutton']))
{
$message = NULL;
if(ereg("[([0-9a-zA-Z_]|\-|\[|\])", $_POST['description']))
{
//valid description
$desc = $_POST['description'];
}
else
{
//invalid description
$desc = FALSE;
$message .= '<p>Description not valid.<p>';
}
if((ereg("[0-9]{6}", $_POST['partno'])) && (strlen($_POST['partno']) >= 5))
{
//valid part number
$pno = $_POST['partno'];
}
else
{
//invalid part no
$pno = FALSE;
$message .= '<P>Part No must be in the format: 999999<P>';
}
if ($desc && $pno)
{
require_once('./mysql_connect.php');
$query = "INSERT INTO systemconfig_generic(description, partno) VALUES ('$desc', '$pno')";
$result = @mysql_query($query);
if($result)
{
echo '<FONT SIZE=2>The following was added to the AWACS lab database:<br>';
echo 'Description: ' .$desc .'<br>';
echo 'Part No: ' .$pno;
}
else
{
$message = '<P><FONT SIZE=2>The following sql error occured:</P><P>' .mysql_error() .'</P><FONT>';
echo $message;
}
mysql_close();
}
Any ideas would be great please.