vigiw Posted August 20, 2006 Share Posted August 20, 2006 Hello, I currently have a great and working setup for a form sending data to a MySQL database and displaying it in another file (Big thanks to Corbin on these Forums!), but I recently decided that I just want to add one more text box field to the form and database. We will call this field4. field4 is going to be placed between field1 and field2 -- the order being: field1 field4 field2 field3 Only because field4 was just thought of and it best fits in that position. Here's my current file called submit.php:submit.php[code]<?include("db.php");$field1 = $_POST['field1'];$field2 = $_POST['field2'];$field3 = $_POST['field3'];if($_POST['sub'] == "yes") {if($field1 == "") { $error .= "You did not put any information for field1<BR>"; } //checks to see if the user filled in field1, or if they put in too much information, and defines the variable error if they didif(strlen($field1) > 30) { $error .= "Field1 is too long.<BR>"; }if($field2 == "") { $error .= "You did not put any information for field2<BR>"; } //checks to see if the user filled in field1, or if they put in too much information, and defines the variable error if they didif(strlen($field2) > 999) { $error .= "Field2 is too long.<BR>"; }if($field3 == "") { $error .= "You did not put any information for field3<BR>"; } //checks to see if the user filled in field1, or if they put in too much information, and defines the variable error if they didif(strlen($field3) > 256) { $error .= "Field3 is too long<BR>."; }}if($_GET['success'] != "yes") { ?><form action="submit.php" method=POST><font size="2" face="Arial">Alert Type: </font><font face="Arial"> <input type="text" maxlength="30" name="field1" <? if(isset($field1)) { echo "value=\"" . $field1 . "\""; } ?>><font size="2"> Choices: Severe Weather Watch -or- Severe Weather Watch Update -or- Severe Weather Watch Correction (Use choice 1 if it is just a normal Severe Weather Watch issuance; use choice 2 if it is an update from an earlier Severe Weather Watch; </font></font><font size="2" face="Arial">use choice 3 if you are correcting a </font><font size="2" face="Arial"> Severe Weather Watch that you issued earlier)<BR>Alert Text: </font><font face="Arial"> <textarea name="field2" rows="9" cols="78">Type in the alert, detailed, here. Text box can fit up to 999 characters.</textarea></font><font size="2" face="Arial"><BR>Forecaster: </font><font face="Arial"> <input type="text" maxlength="256" name="field3" <? if(isset($field3)) { echo "value=\"" . $field3 . "\""; } ?>><font size="2"> (Your first and last name)</font></font><font size="2" face="Arial"><BR></font><font face="Arial"><input type="hidden" name="sub" value="yes"><input type="submit" value="Send"></font><p><font face="Arial"> **KEEP IN MIND: Severe Weather Watches are not official alerts issued by NOAA! Also, we issue these only as needed. Be conservative, as with all other alerts issued via VWFN.</font><font size="2" face="Arial"> </font></p></form><?}/* note: .= defines a variable or adds onto it if it already exists... for example$var1 = "hello";$var1 .= " my name is corbin";echo $var1;would out put hello my name is corbin*/if(isset($error)) {echo "There was one or more error!<BR>";echo $error;}else {if(($_GET['success'] != "yes") && ($_POST['sub'] == "yes")) { // checks to see if $error is set of if the GET variable of success does not equal yes$field1 = htmlspecialchars($field1);// if $field does not return an error it replaces any thing that could be interpetted as a browser as html$field2 = htmlspecialchars($field2);$field3 = htmlspecialchars($field3);$q = mysql_query("INSERT INTO `" . $table_name . "` (`field1` , `field2` , `field3`) VALUES ('" . $field1 . "', '" . $field2 . "', '" . $field3 ."')");if($q) { //what to do if the mysql query is successful $error = NULL;?><meta http-equiv="refresh" content="0;url=<? echo $_SERVER['HTTP_SELF'] . "?success=yes"; ?>" ?>" ?>" ?>" ?>"><?//by forwarding to its self the page will clear its post values so if a user hits refresh its not inserted into the database again...} //the meta tag has it forward it to this page cept with the $_GET['success'] tag set}elseif($_GET['success'] == "yes") { //what to do if $_GET['success'] does equal yesecho "Severe Weather Watch successfully issued.<BR> View it <a href=\"http://www.vigilantweather.com/forecast/viewseverewatch/bos_view.php\">Here</a>.";}}mysql_close(); //closes the link to mysql}?>[/code]It seems easy since all that has to be done is add one field to wherever in this file it needs to be shown.field4 is already added to the database and it is a TEXT field.Could anyone please help me out. I don't want to ruin this file, and I just one that one more text field added as described in this message. And I am quite new to PHP.Once again this file IS working, I just want to add that one field! :)Thanks in advance! ;D Link to comment https://forums.phpfreaks.com/topic/18135-need-to-add-a-field-to-phphtml-form/ Share on other sites More sharing options...
vigiw Posted August 21, 2006 Author Share Posted August 21, 2006 *bump* Link to comment https://forums.phpfreaks.com/topic/18135-need-to-add-a-field-to-phphtml-form/#findComment-77797 Share on other sites More sharing options...
vigiw Posted August 21, 2006 Author Share Posted August 21, 2006 *bump*I'd really appreciate some help on this!! Please help out, as I want to release this great new weather service on my website ASAP!Thanks. Link to comment https://forums.phpfreaks.com/topic/18135-need-to-add-a-field-to-phphtml-form/#findComment-77830 Share on other sites More sharing options...
vigiw Posted August 21, 2006 Author Share Posted August 21, 2006 Hello? Anyone out there? :'(This is a greatly anticipated addition.. I need some help!Thanks! Link to comment https://forums.phpfreaks.com/topic/18135-need-to-add-a-field-to-phphtml-form/#findComment-77858 Share on other sites More sharing options...
Jervous Posted August 21, 2006 Share Posted August 21, 2006 I am doing this right now, but I need to know a few things. What is the maximum length for the field and what type of field is it, (textarea, text, password, etc.)? Link to comment https://forums.phpfreaks.com/topic/18135-need-to-add-a-field-to-phphtml-form/#findComment-77899 Share on other sites More sharing options...
vigiw Posted August 21, 2006 Author Share Posted August 21, 2006 Text is the field type, and there is no maximum length defined in the field.Need anymore info?Thanks! :) Link to comment https://forums.phpfreaks.com/topic/18135-need-to-add-a-field-to-phphtml-form/#findComment-77902 Share on other sites More sharing options...
desithugg Posted August 21, 2006 Share Posted August 21, 2006 [code]$feild4 = $_POST['feild4'];$feild4_mx_length = "100";//feild4 max lengthif($field4 == "") { $error .= "You did not put any information for field2<BR>"; } //checks to see if the user filled in field1, or if they put in too much information, and defines the variable error if they didif(strlen($field4) > $feild4_mx_length) { $error .= "Field4 is too long.<BR>"; }and just enter it in ur databaseinsert into (feild1,feild2,field3,field4) values ('$field1','$field2','$field3','$field4')[/code]sorry i didnt read your whole code im not sure which rows you want to fill in but hopefully you get my point Link to comment https://forums.phpfreaks.com/topic/18135-need-to-add-a-field-to-phphtml-form/#findComment-77904 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.