Jump to content


Photo

Need to add a field to PHP/HTML Form


  • Please log in to reply
6 replies to this topic

#1 vigiw

vigiw
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts

Posted 20 August 2006 - 09:39 PM

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
<?
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 did
if(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 did
if(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 did
if(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:&nbsp; </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!&nbsp; Also, we 
issue these only as needed.&nbsp; 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 yes
echo "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}
?>

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

#2 vigiw

vigiw
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts

Posted 21 August 2006 - 12:02 AM

*bump*

#3 vigiw

vigiw
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts

Posted 21 August 2006 - 01:52 AM

*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.

#4 vigiw

vigiw
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts

Posted 21 August 2006 - 03:09 AM

Hello? Anyone out there? :'(

This is a greatly anticipated addition.. I need some help!

Thanks!

#5 Jervous

Jervous
  • Members
  • Pip
  • Newbie
  • 9 posts

Posted 21 August 2006 - 04:43 AM

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.)?

#6 vigiw

vigiw
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts

Posted 21 August 2006 - 04:48 AM

Text is the field type, and there is no maximum length defined in the field.

Need anymore info?

Thanks! :)

#7 desithugg

desithugg
  • Members
  • PipPipPip
  • Advanced Member
  • 281 posts
  • LocationScarborough

Posted 21 August 2006 - 04:54 AM

$feild4 = $_POST['feild4'];
$feild4_mx_length = "100";//feild4 max length
if($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 did
if(strlen($field4) > $feild4_mx_length) { $error .= "Field4 is too long.<BR>"; }
and just enter it in ur database
insert into (feild1,feild2,field3,field4) values ('$field1','$field2','$field3','$field4')
sorry i didnt read your whole code im not sure which rows you want to fill in but hopefully you get my point




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users