FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


HomeWatched TopicsRegisterSearchDirectory
FAQMemberlistUsergroupsLog inStoresItemsBank
Google

Reply to topic Page 1 of 1
PHP and html form error
Message  

Reply with quote
Post PHP and html form error 
I had put php coding and html form together. Basically, the person will fill in the form and submit the info and it will be send to the same page back to be checked and write into the database.  But when even i open it on the browser, it will not show the form but instead it straight away show mi the error msg.  Coding as shown below.

Code:

//registration.php

<?
$host='localhost';
$username='root';
$password='asd';
$connection = mysql_connect($host,$username,$password);
mysql_select_db("data");
$yearList = mysql_query ("SELECT yrValue FROM admin_dateFormat order by year");
?>

<html>
<title>Registration</title>
<form action="registration.php" method="post" name="register_form" target="_self" id="register_form">
 
Year
              <select name="list_year" id="list_year">
                <?
                      $counter = 0;
            while ($row = mysql_fetch_array($yearList)) {
             ?>
                <option value="<? echo $row["yrValue"]; ?>"> <? echo $row["yrValue"];
        } ?>
              </select>
<input type="submit" name="Submit" value="Submit" >
</form>
</html>

<?
$Year=$_POST['list_year'];
if($Year==null)
{
        echo"Please make sure all the required field are being entered or chosen. //year \n";
    echo "Please back click to continue.";

}
else
{

mysql_query ("INSERT INTO user values ('$Year')");
mysql_close();}
?>

When even i open it on the browser, the error msg will straight away shown out without even the user clicking on the submit button.


View user's profile Send private message

Reply with quote
Post  
instead of using if($year==null) use if(empty($year))


_________________
http://www.scaria.info/
View user's profile Send private message AIM Address

Reply with quote
Post  
Ya i have put that in but when ever i load the page, the error telling the person that they had not fill up the form msg will be shown at the bottom of the page. By right the error shown be shown only if the person click on the submit button if they nv fill in the form. But not the person nv click on the submit button but still receive the error msg.

What is wrong with it?

View user's profile Send private message

Reply with quote
Post  
your sytnax should be like this:

if(isset($_POST['Submit']))
{
// PROCESS FORM

}else{
// DISPLAY FORM
}

Make sure your Submit button is called "Submit"


_________________
http://www.scaria.info/
View user's profile Send private message AIM Address

Reply with quote
Post  
Code:
if( empty( $_POST[ 'email' ] ) || !eregi( "^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes( trim( $_POST[ 'email' ] ) ) ) ) {
                   $message = 'Email address is not a valid email address.';



Just change email to w/e you need.

View user's profile Send private message
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
  



Google

FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


Web Design by PlatinumShore.com & Web Hosting by TradeWebHosting.com