Jump to content

PHP Form not Sending


vigiw

Recommended Posts

Hi there,

I am very excited about releasing a new addition to my website, and one of the crucial components is not functioning properly.

I have a PHP form, called submit.php -- it will work with db.php -- in the same folder, to get access to the database.

Here is an example of one of my already-working forms that sends this form data to my MySQL database to make it retrievable in a view file:

submit.php
[code]<?
include("db.php");

$field1 = $_POST['field1'];
$field2 = $_POST['field2'];
$field3 = $_POST['field3'];
$field4 = $_POST['field4'];
$field5 = $_POST['field5'];
if($_POST['sub'] == "yes") {
if($field1 == "") { $error .= "You did not put identify the alert type.<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) > 200) { $error .= "Alert type is too long.<BR>"; }

if($field2 == "") { $error .= "You did not add type any alert text.<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 .= "Alert text is too long.<BR>"; }

if($field3 == "") { $error .= "You did not identify yourself.<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 .= "Forecaster name is too long.<BR>."; }

if($field4 == "") { $error .= "You did not identify the counties effected.<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) > 700) { $error .= "Counties effected list is too long.<BR>"; }

if($field5 == "") { $error .= "You did not identify the expiration of the alert.<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($field5) > 500) { $error .= "The expiration for the alert 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="200" name="field1" <? if(isset($field1)) { echo "value=\"" . $field1 . "\""; } ?>><font size="2">
Choices: Flood Watch -or- Flood Watch Update -or- Flood Watch Correction (Use choice 1 if it is just a normal
Flood Watch
issuance; use choice 2 if it is an update from an earlier Flood Watch; </font></font><font size="2" face="Arial">
use choice 3 if you are correcting a Flood Watch that you issued earlier)</font><p>
<font face="Arial" size="2">Counties:&nbsp;&nbsp;&nbsp; </font><font face="Arial">
<input type="text" maxlength="700" name="field4" <? if(isset($field1)) { echo "value=\"" . $field4 . "\""; } ?>>
<font size="2">List the counties here and separate by state and comma.&nbsp;
Example: In Massachusetts: Bristol, Plymouth, and Barnstable counties.&nbsp; In
Rhode Island: Providence county.</font></font></p>
<p>
<font face="Arial" size="2">Expires:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" maxlength="500" name="field5" <? if(isset($field1)) { echo "value=\"" . $field5 . "\""; } ?>>
Format: <b>Until 8:00pm EDT, Monday, July 23, 2005. </b>Please make this correspond with a relevant expiration time
and date and list it like so and please include the correct time zone.</font></p>
<p>
<font face="Arial" size="2">Alert Text:&nbsp; </font><font face="Arial">
<font size="2">

&nbsp;<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>&nbsp;<input type="text" maxlength="256" name="field3" <? if(isset($field3)) { echo "value=\"" . $field3 . "\""; } ?>><font size="2">
(Your first and last name)</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>
<p>**KEEP IN MIND:
Flood Watches are not official alerts issued by NOAA!&nbsp; Also, we
only issue Flood Watches if <font color="#000000">high flow or overflow
of water from a river is possible in the given time period. It can also apply to
heavy runoff or drainage of water into low-lying areas. These watches are
generally issued for flooding that is expected to occur at least 6 hours after
heavy rains have ended.</font>
Be conservative, as with all other alerts
issued via VWFN.<font size="2" face="Arial"> </font>
</p>
<p>
<span style="font-style: italic; text-decoration: underline; background-color: #FF0000">
<a href="http://www.vigilantweather.com/forecast/alerts.html">
<font color="#FFFFFF">VERY IMPORTANT -- BOOKMARK:</font></a></span></p>
<p><font color="#000080">
<span style="font-weight: 700; background-color: #00FFFF">
<a href="http://www.vigilantweather.com/forecast/alerts.html">REFERENCE: Go to the
VWFN Weather Alerts page to view the official VWFN weather alert definitions.&nbsp;
This will greatly help forecasters!&nbsp; Do not skip, this is an important step
and will improve upon your forecasting for VWFN.&nbsp; Technical definitions;
take notes, bookmark!</a></span></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);
$field4 = htmlspecialchars($field4);
$field5 = htmlspecialchars($field5);
$q = mysql_query("INSERT INTO `" . $table_name . "` (`field1` , `field2` , `field3`, `field4`, `field5`) VALUES ('" . $field1 . "', '" . $field2 . "', '" . $field3 ."', '" . $field4 . "', '" . $field5 . "')");
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 "Flood Watch successfully issued.<BR> View it <a href=\"http://www.vigilantweather.com/forecast/viewfloodwatch/bos_view.php\">Here</a>.";
}
}
mysql_close(); //closes the link to mysql}
?>[/code]

Please note how it is submitted.

Now, I have a more fields and different types of fields--such as radio buttons and drop-downs, etc.

Here is what I have so far, please compare to submit.php above... this one is also submit.php, but I will call it submit2.php in this post to minimize confusion:

[code]<?
include("db.php");

$precip1 = $_POST['precip1'];
$heaviness1 = $_POST['heaviness1'];
$conditions_1 = $_POST['conditions_1'];
$conditions2_1 = $_POST['conditions2_1'];
$winddir1 = $_POST['winddir1'];
$high1 = $_POST['high1'];
$low1 = $_POST['low1'];
$pop1 = $_POST['pop1'];
$wind1 = $_POST['wind1'];
if($_POST['sub'] == "yes") {
if($precip1 == "") { $error .= "You did not put identify the alert type.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($precip1) > 999) { $error .= "Alert type is too long.<BR>"; }

if($heaviness1 == "") { $error .= "You did not add type any alert text.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($heaviness1) > 999) { $error .= "Alert text is too long.<BR>"; }

if($conditions_1 == "") { $error .= "You did not identify yourself.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($conditions_1) > 999) { $error .= "Forecaster name is too long.<BR>."; }

if($conditions2_1 == "") { $error .= "You did not identify the counties effected.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($conditions2_1) > 999) { $error .= "Counties effected list is too long.<BR>"; }

if($winddir1 == "") { $error .= "You did not identify the expiration of the alert.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($winddir1) > 999) { $error .= "The expiration for the alert is too long.<BR>"; }

if($high1 == "") { $error .= "You did not identify the expiration of the alert.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($high1) > 999) { $error .= "The expiration for the alert is too long.<BR>"; }

if($low1 == "") { $error .= "You did not identify the expiration of the alert.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($low1) > 999) { $error .= "The expiration for the alert is too long.<BR>"; }

if($pop1 == "") { $error .= "You did not identify the expiration of the alert.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($pop1) > 999) { $error .= "The expiration for the alert is too long.<BR>"; }

if($wind1 == "") { $error .= "You did not identify the expiration of the alert.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($wind1) > 999) { $error .= "The expiration for the alert is too long.<BR>"; }
}
if($_GET['success'] != "yes") { ?>
<form action="submit.php" method=POST>
<font face="Arial" size="2">Precipitation: </font><font face="Arial"> <select name="precip1">
  <option value="No Precipitation">None</option>
  <option>Rain</option>
  <option>Snow</option>
  <option>Wintry Mix</option>
  <option>Freezing Rain</option>
  <option>Sleet</option>
  </select></font><p>
<font face="Arial" size="2">Precipitation Heaviness:&nbsp;&nbsp;&nbsp; </font>
<font face="Arial">
<input type="radio" value="Very Heavy" name="heaviness1" checked><font size="2">Very
  Heavy </font> <input type="radio" value="Heavy" name="heaviness1"><font size="2"> Heavy
  </font>
  <input type="radio" value="Moderate" name="heaviness1"><font size="2"> Moderate
  </font>
  <input type="radio" value="Light" name="heaviness1"><font size="2"> Light
  </font>
  <input type="radio" value="Very Light" name="heaviness1"><font size="2"> Very Light&nbsp;
  </font>
  <input type="radio" value=" " name="heaviness1"><font size="2"> No Precipitation</font></font></p>
<p>
<font face="Arial" size="2">Conditions: </font><font face="Arial">
      <select name="conditions_1">

  <option value="Sunny Conditions">Sunny</option>
  <option value="Increasing Cloudiness">Increasing Clouds</option>
  <option value="Decreasing Cloudiness">Decreasing Clouds</option>
  <option value="Mostly Sunny Conditions">Mostly Sunny</option>
  <option value="Partly Cloudy Conditions">Partly Cloudy</option>
  <option value="Mostly Cloudy Conditions">Mostly Cloudy</option>
  <option value="Cloudy Conditions">Overcast</option>

      </select></font><p>
<font face="Arial" size="2">Additional Conditions:&nbsp;</font><font face="Arial"><select name="conditions2_1">

  <option value=" ">N/A</option>
  <option value='and windy'>Windy</option>

  <option value='and humid'>Humid</option>

      <option value="and foggy">Foggy</option>

      </select><font size="2" face="Arial"> </font><font size="2">(Select N/A if this does not apply)</font><font size="2" face="Arial"><BR>
Wind Direction: </font><font size="2">&nbsp;</font><select size="1" name="winddir1">
  <option>Light and Variable</option>
  <option>North</option>
  <option>Northeast</option>
  <option>East</option>
  <option>Southeast</option>
  <option>South</option>
  <option>Southwest</option>
  <option>West</option>
  <option>Northwest</option>
  </select></font></p>
  <p><font face="Arial"><font size="2">Wind Speed: </font> <input type="text" name="wind1" size="4"><font size="2"> mph</font></font></p>
  <p><font face="Arial"><font size="2">High Temperature: </font> <input type="text" name="high1" size="3"></font></p>
  <p><font face="Arial"><font size="2">Low Temperature: </font> <input type="text" name="low1" size="3"></font></p>
  <p><font face="Arial"><font size="2">Probability of Precipitation: </font> <select size="1" name="pop1">
  <option>0%</option>
  <option>10%</option>
  <option>20%</option>
  <option>30%</option>
  <option>40%</option>
  <option>50%</option>
  <option>60%</option>
  <option>70%</option>
  <option>80%</option>
  <option>90%</option>
  <option>100%</option>
  </select></font></p>
  <p>
<font face="Arial">
<font size="2" face="Arial"><BR>
</font>
<input type="hidden" name="sub" value="yes">
<input type="submit" value="Send"></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
$precip1 = htmlspecialchars($precip1);// if $field does not return an error it replaces any thing that could be interpetted as a browser as html
$heaviness1 = htmlspecialchars($heaviness1);
$conditions_1 = htmlspecialchars($conditions_1);
$conditions2_1 = htmlspecialchars($conditions2_1);
$winddir1 = htmlspecialchars($winddir1);
$wind1 = htmlspecialchars($wind1);
$high1 = htmlspecialchars($high1);
$low1 = htmlspecialchars($low1);
$pop1 = htmlspecialchars($pop1);
$q = mysql_query("INSERT INTO `" . $table_name . "` (`precip1` , `heaviness1` , `conditions_1`, `conditions2_1`, `winddir`, `wind1`, `high`, `low`, `pop`) VALUES ('" . $precip1 . "', '" . $heaviness1 . "', '" . $conditions_1 ."', '" . $conditions2_1 . "', '" . $winddir1 . "', '" . $high1 . "', '" . $low1 . "', '" . $wind1 . "', '" . $pop1 . "')");
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 "Dense Fog Advisory successfully issued.<BR> View it <a href=\"http://www.vigilantweather.com/forecast/viewfog/bos_view.php\">Here</a>.";
}
}
mysql_close(); //closes the link to mysql}
?>[/code]

Any ideas?  I would really appreciate any help I can get to get this to work.  I am not a great coder, so I will not be able to see what is wrong with it, unfortunately.  I would very much like to get this addition up and running soon, many of my viewers are excited as well.  This is going to be my last or "almost last" part of the new addition! :)

Thank you, in advance! ;D
Link to comment
Share on other sites

Hi Ken,

Thanks for replying... take a look at this example:

http://www.vigilantweather.com/forecast/forecast/submit.php

The form will not sucessfully send to the MySQL database.

Meanwhile, http://www.vigilantweather.com/forecast/floodwatch/submit.php will.

Any ideas to fix this?

Thanks :)
Link to comment
Share on other sites

No, the paths ARE set up... it is all correct with the db.php file.

I am confident in saying that I am at or very close to 100% sure that it is in the code of the file.

I do not know what is wrong and need to fix it but do not know how to.

Thanks for your responses, but any ideas now?

Thanks again.
Link to comment
Share on other sites

add error check to the query

[code]$q = mysql_query("INSERT INTO `" . $table_name . "` (`precip1` , `heaviness1` , `conditions_1`, `conditions2_1`, `winddir`, `wind1`, `high`, `low`, `pop`) VALUES ('" . $precip1 . "', '" . $heaviness1 . "', '" . $conditions_1 ."', '" . $conditions2_1 . "', '" . $winddir1 . "', '" . $high1 . "', '" . $low1 . "', '" . $wind1 . "', '" . $pop1 . "')") or die (mysql_error());[/code]

Let us know

Ray
Link to comment
Share on other sites

That error means what it says.

[code]<?php
$q ="INSERT INTO `" . $table_name . "` (`precip1` , `heaviness1` , `conditions_1`, `conditions2_1`,
                                                      `winddir`, `wind1`, `high`, `low`, `pop`)
                                          VALUES ('" . $precip1 . "', '" . $heaviness1 . "', '" . $conditions_1 ."', '" .
                                                            $conditions2_1 . "', '" . $winddir1 . "', '" . $high1 . "', '" .
                                                            $low1 . "', '" . $wind1 . "', '" . $pop1 . "')";
$rs = mysql_query($q) or die ("Error with the query: $q<br>" . mysql_error());
?>[/code]
Use the above code, which will show you the query being used to generate the error.

Ken
Link to comment
Share on other sites

well it is exaxtly what it say. You are calling to update 9 rows but only giving 8 values. Or vice versa. It looks like you are giving 9 of both so I would double check your field names. Also right after the sql statement echo it out to see what it is asking for

echo "$q<br>";

Ray

beat me to it :)
Link to comment
Share on other sites

Well-- to Ken:

I replaced that code with the code that was mentioned before your post by Ray.

I took off the <? php tags because from what I understood, I should have replaced your version of that line with mine.

And now I get the following error:

Parse error: parse error, unexpected T_ELSEIF in /public_html/forecast/forecast/submit.php on line 157

Here's line 157:

elseif($_GET['success'] == "yes") { //what to do if $_GET['success'] does equal yes

But it has to be due to the code you supplied... ahh what a day!

Thanks for your help so far! ;D

I'll check my field names, any help still appreciated!
Link to comment
Share on other sites

this is you roriginal code with ken's code in it. Copy and paste then let us know error

[code]<?php
include("db.php");

$precip1 = $_POST['precip1'];
$heaviness1 = $_POST['heaviness1'];
$conditions_1 = $_POST['conditions_1'];
$conditions2_1 = $_POST['conditions2_1'];
$winddir1 = $_POST['winddir1'];
$high1 = $_POST['high1'];
$low1 = $_POST['low1'];
$pop1 = $_POST['pop1'];
$wind1 = $_POST['wind1'];
if($_POST['sub'] == "yes") {
if($precip1 == "") { $error .= "You did not put identify the alert type.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($precip1) > 999) { $error .= "Alert type is too long.<BR>"; }

if($heaviness1 == "") { $error .= "You did not add type any alert text.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($heaviness1) > 999) { $error .= "Alert text is too long.<BR>"; }

if($conditions_1 == "") { $error .= "You did not identify yourself.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($conditions_1) > 999) { $error .= "Forecaster name is too long.<BR>."; }

if($conditions2_1 == "") { $error .= "You did not identify the counties effected.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($conditions2_1) > 999) { $error .= "Counties effected list is too long.<BR>"; }

if($winddir1 == "") { $error .= "You did not identify the expiration of the alert.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($winddir1) > 999) { $error .= "The expiration for the alert is too long.<BR>"; }

if($high1 == "") { $error .= "You did not identify the expiration of the alert.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($high1) > 999) { $error .= "The expiration for the alert is too long.<BR>"; }

if($low1 == "") { $error .= "You did not identify the expiration of the alert.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($low1) > 999) { $error .= "The expiration for the alert is too long.<BR>"; }

if($pop1 == "") { $error .= "You did not identify the expiration of the alert.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($pop1) > 999) { $error .= "The expiration for the alert is too long.<BR>"; }

if($wind1 == "") { $error .= "You did not identify the expiration of the alert.<BR>"; } //checks to see if the user filled in precip1, or if they put in too much information, and defines the variable error if they did
if(strlen($wind1) > 999) { $error .= "The expiration for the alert is too long.<BR>"; }
}
if($_GET['success'] != "yes") { ?>
<form action="submit.php" method=POST>
<font face="Arial" size="2">Precipitation: </font><font face="Arial"> <select name="precip1">
  <option value="No Precipitation">None</option>
  <option>Rain</option>
  <option>Snow</option>
  <option>Wintry Mix</option>
  <option>Freezing Rain</option>
  <option>Sleet</option>
  </select></font><p>
<font face="Arial" size="2">Precipitation Heaviness:&nbsp;&nbsp;&nbsp; </font>
<font face="Arial">
<input type="radio" value="Very Heavy" name="heaviness1" checked><font size="2">Very
  Heavy </font> <input type="radio" value="Heavy" name="heaviness1"><font size="2"> Heavy
  </font>
  <input type="radio" value="Moderate" name="heaviness1"><font size="2"> Moderate
  </font>
  <input type="radio" value="Light" name="heaviness1"><font size="2"> Light
  </font>
  <input type="radio" value="Very Light" name="heaviness1"><font size="2"> Very Light&nbsp;
  </font>
  <input type="radio" value=" " name="heaviness1"><font size="2"> No Precipitation</font></font></p>
<p>
<font face="Arial" size="2">Conditions: </font><font face="Arial">
      <select name="conditions_1">

  <option value="Sunny Conditions">Sunny</option>
  <option value="Increasing Cloudiness">Increasing Clouds</option>
  <option value="Decreasing Cloudiness">Decreasing Clouds</option>
  <option value="Mostly Sunny Conditions">Mostly Sunny</option>
  <option value="Partly Cloudy Conditions">Partly Cloudy</option>
  <option value="Mostly Cloudy Conditions">Mostly Cloudy</option>
  <option value="Cloudy Conditions">Overcast</option>

      </select></font><p>
<font face="Arial" size="2">Additional Conditions:&nbsp;</font><font face="Arial"><select name="conditions2_1">

  <option value=" ">N/A</option>
  <option value='and windy'>Windy</option>

  <option value='and humid'>Humid</option>

      <option value="and foggy">Foggy</option>

      </select><font size="2" face="Arial"> </font><font size="2">(Select N/A if this does not apply)</font><font size="2" face="Arial"><BR>
Wind Direction: </font><font size="2">&nbsp;</font><select size="1" name="winddir1">
  <option>Light and Variable</option>
  <option>North</option>
  <option>Northeast</option>
  <option>East</option>
  <option>Southeast</option>
  <option>South</option>
  <option>Southwest</option>
  <option>West</option>
  <option>Northwest</option>
  </select></font></p>
  <p><font face="Arial"><font size="2">Wind Speed: </font> <input type="text" name="wind1" size="4"><font size="2"> mph</font></font></p>
  <p><font face="Arial"><font size="2">High Temperature: </font> <input type="text" name="high1" size="3"></font></p>
  <p><font face="Arial"><font size="2">Low Temperature: </font> <input type="text" name="low1" size="3"></font></p>
  <p><font face="Arial"><font size="2">Probability of Precipitation: </font> <select size="1" name="pop1">
  <option>0%</option>
  <option>10%</option>
  <option>20%</option>
  <option>30%</option>
  <option>40%</option>
  <option>50%</option>
  <option>60%</option>
  <option>70%</option>
  <option>80%</option>
  <option>90%</option>
  <option>100%</option>
  </select></font></p>
  <p>
<font face="Arial">
<font size="2" face="Arial"><BR>
</font>
<input type="hidden" name="sub" value="yes">
<input type="submit" value="Send"></p>
</form>
<?php
}
/*
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
$precip1 = htmlspecialchars($precip1);// if $field does not return an error it replaces any thing that could be interpetted as a browser as html
$heaviness1 = htmlspecialchars($heaviness1);
$conditions_1 = htmlspecialchars($conditions_1);
$conditions2_1 = htmlspecialchars($conditions2_1);
$winddir1 = htmlspecialchars($winddir1);
$wind1 = htmlspecialchars($wind1);
$high1 = htmlspecialchars($high1);
$low1 = htmlspecialchars($low1);
$pop1 = htmlspecialchars($pop1);
$sql = "INSERT INTO `" . $table_name . "`
        (`precip1` , `heaviness1` , `conditions_1`, `conditions2_1`, `winddir`, `wind1`, `high`, `low`, `pop`)
VALUES ('" . $precip1 . "', '" . $heaviness1 . "', '" . $conditions_1 ."', '" . $conditions2_1 . "', '" . $winddir1 . "', '" . $high1 . "', '" . $low1 . "', '" . $wind1 . "', '" . $pop1 . "')";

$rs = mysql_query($sql) or die ("Error with the query: $sql<br>" . mysql_error());

if($rs) { //what to do if the mysql query is successful
$error = NULL;

?>
<meta http-equiv="refresh" content="0;url=<? echo $_SERVER['HTTP_SELF'] . "?success=yes"; ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>" ?>">
<?php
//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 "Dense Fog Advisory successfully issued.<BR> View it <a href=\"http://www.vigilantweather.com/forecast/viewfog/bos_view.php\">Here</a>.";
}
}
mysql_close(); //closes the link to mysql}
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.