Jump to content

form not submiting


runnerjp

Recommended Posts

here is my code

 

<?php
session_start();
require_once '../settings.php';
checkLogin ('1 2');


      
?>
<? if (isset($_POST['basic'])){
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$first_name = addslashes($_POST['first_name']);
@$last_name = addslashes($_POST['last_name']);
@$gender = addslashes($_POST['gender']);
@$birthday = addslashes($_POST['birthday']);
@$birthmonth = addslashes($_POST['birthmonth']);
@$birthyear = addslashes($_POST['birthyear']);
@$dob = $birthday.'-'.$birthmonth.'-'.$birthyear;
@$id = $_SESSION['user_id'];

// Validation
if (strlen($first_name) <2)
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid first name</font></i></p>");
}
if (strlen($first_name) >15)
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid first name</font></i></p>");
}

if (strlen($first_name) == 0 )
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid first name</font></i></p>");
}

if (strlen($last_name) <2)
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid last name</font></i></p>");
}
if (strlen($last_name) >15)
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid last name</font></i></p>");
}

if (strlen($last_name) == 0 )
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid last name</font></i></p>");
}

if (strlen($gender) == 0 )
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid gender</font></i></p>");
}

if (strlen($birthday) == 0 )
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid birthday</font></i></p>");
}

if (strlen($birthmonth) == 0 )
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid birthmonth</font></i></p>");
}

if (strlen($birthyear) == 0 )
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid birthyear</font></i></p>");
}

//Sending auto respond Email to visitor
$pfw_header = "From: Admin@web.com\n"
  . "Reply-To: Admin@web.com\n";
$pfw_subject = "Profile @ site.com";
$pfw_email_to = "going to sort out";
$pfw_message = "We are just sending you an email to thankyou for adding your profile information.\n"
. "Now you have done this you will be able to have full access to our site.\n"
. "\n"
. "if you have any questions please contact us.\n"
. "------------------------------------------------------------------------------------------------\n"
. "\n"
. "admin";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//saving record to MySQL database
//changing date formats


@$pfw_strQuery = "INSERT INTO `users`(`first_name`,`last_name`,`gender`,`dob`)VALUES (\"$first_name\",\"$last_name\",\"$gender\","$dob")" ;
@$pfw_host = "";
@$pfw_user = "";
@$pfw_pw = "";
@$pfw_db = "";
$pfw_link = mysql_connect($pfw_host, $pfw_user, $pfw_pw);
if (!$pfw_link) {
die('Could not connect: ' . mysql_error());
}
$pfw_db_selected = mysql_select_db($pfw_db, $pfw_link);
if (!$pfw_db_selected) {
die ('Can not use $pfw_db : ' . mysql_error());
}

//insert new record
$pfw_result = mysql_query($pfw_strQuery);
if (!$pfw_result) {
die('Invalid query: ' . mysql_error());
}
mysql_close($pfw_link);

echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>Thankyou for creating your profile. </font></p>");
}else{
?>
<table width="50%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center" valign="middle"><form id="FormName" action='<?php "$_SERVER[php_SELF]" ?>' method="post" name="basic">
<table width="523" border="0" align="center" cellpadding="0" cellspacing="2">
<tr><td colspan="3"> </td>
</tr>
<tr>
  <td><div align="right">
    <label for="dob">First name</label>
  </div></td>
  <td colspan="2"><input class="inputedit" id="first_name" name="first_name" type="text" size="25" value="" maxlength="255" /></td>
</tr>
<tr>
  <td width="150"><div align="right">
<label for="dob">Last name</label>
</div></td>
  <td colspan="2"><input class="inputedit" id="last_name" name="last_name" type="text" size="25" value="" maxlength="255" /></td>
</tr>
<tr><td width="150"><div align="right">
<label for="first_name">Gender</label>
</div>
</td>
<td colspan="2"><select class="inputedit" id="gender" name="gender">
  <option value="Male" <?php if($gender == 'Male') echo 'selected'; ?>>Male</option>
  <option value="Female"  <?php if($gender == 'Female') echo 'selected'; ?>>Female</option>
</select></td>
</tr>
<tr><td width="150"><div align="right">
<label for="last_name">Date of birth</label>
</div>
</td>
<td colspan="2"><label for="birthday"></label>
  <select  name="birthday" id="birthday">
    <option value="1" <?php if($birthday == '1') echo ' selected="selected"'; ?>>1</option>
    <option value="2"  <?php if($birthday == '2') echo ' selected="selected"'; ?>>2</option>
    <option value="3" <?php if($birthday == '3') echo ' selected="selected"'; ?>>3</option>
    <option value="4"  <?php if($birthday == '4') echo ' selected="selected"'; ?>>4</option>
    <option value="5" <?php if($birthday == '5') echo ' selected="selected"'; ?>>5</option>
    <option value="6"  <?php if($birthday == '6') echo ' selected="selected"'; ?>>6</option>
    <option value="7" <?php if($birthday == '7') echo ' selected="selected"'; ?>>7</option>
    <option value="8"  <?php if($birthday == '8') echo ' selected="selected"'; ?>>8</option>
    <option value="9" <?php if($birthday == '9') echo ' selected="selected"'; ?>>9</option>
    <option value="10"  <?php if($birthday == '10') echo ' selected="selected"'; ?>>12</option>
    <option value="11" <?php if($birthday == '11') echo ' selected="selected"'; ?>>11</option>
    <option value="12"  <?php if($birthday == '12') echo ' selected="selected"'; ?>>12</option>
    <option value="13" <?php if($birthday == '13') echo ' selected="selected"'; ?>>13</option>
    <option value="14"  <?php if($birthday == '14') echo ' selected="selected"'; ?>>14</option>
    <option value="15" <?php if($birthday == '15') echo ' selected="selected"'; ?>>15</option>
    <option value="16"  <?php if($birthday == '16') echo ' selected="selected"'; ?>>16</option>
    <option value="17" <?php if($birthday == '17') echo ' selected="selected"'; ?>>17</option>
    <option value="18"  <?php if($birthday == '18') echo ' selected="selected"'; ?>>18</option>
    <option value="19" <?php if($birthday == '19') echo ' selected="selected"'; ?>>19</option>
    <option value="20"  <?php if($birthday == '20') echo ' selected="selected"'; ?>>20</option>
    <option value="21" <?php if($birthday == '21') echo ' selected="selected"'; ?>>21</option>
    <option value="22"  <?php if($birthday == '22') echo ' selected="selected"'; ?>>22</option>
    <option value="23" <?php if($birthday == '23') echo ' selected="selected"'; ?>>23</option>
    <option value="24"  <?php if($birthday == '24') echo ' selected="selected"'; ?>>24</option>
    <option value="25" <?php if($birthday == '25') echo ' selected="selected"'; ?>>25</option>
    <option value="26"  <?php if($birthday == '26') echo ' selected="selected"'; ?>>26</option>
    <option value="27" <?php if($birthday == '27') echo ' selected="selected"'; ?>>27</option>
    <option value="28"  <?php if($birthday == '28') echo ' selected="selected"'; ?>>28</option>
    <option value="29" <?php if($birthday == '29') echo ' selected="selected"'; ?>>29</option>
    <option value="30" <?php if($birthday == '30') echo ' selected="selected"'; ?>>30</option>
    <option value="31"  <?php if($birthday == '31') echo ' selected="selected"'; ?>>31</option>
  </select>
  <label for="birthmonth"></label>
  <select name="birthmonth" id="birthmonth">
    <option value="January" <?php if($birthmonth == 'January') echo 'selected'; ?>>January</option>
    <option value="Febuary"  <?php if($birthmonth == 'Febuary') echo 'selected'; ?>>Febuary</option>
    <option value="March" <?php if($birthmonth == 'March') echo 'selected'; ?>>March</option>
    <option value="April"  <?php if($birthmonth == 'April') echo 'selected'; ?>>April</option>
    <option value="May" <?php if($birthmonth == 'May') echo 'selected'; ?>>May</option>
    <option value="June"  <?php if($birthmonth == 'June') echo 'selected'; ?>>June</option>
    <option value="July" <?php if($birthmonth == 'July') echo 'selected'; ?>>July</option>
    <option value="August"  <?php if($birthmonth == 'August') echo 'selected'; ?>>August</option>
    <option value="September" <?php if($birthmonth == 'September') echo 'selected'; ?>>September</option>
    <option value="October"  <?php if($birthmonth == 'October') echo 'selected'; ?>>October</option>
    <option value="November" <?php if($birthmonth == 'November') echo 'selected'; ?>>November</option>
    <option value="December"  <?php if($birthmonth == 'December') echo 'selected'; ?>>December</option>
  </select>
  <label for="birthyear"></label>
  <select  name="birthyear" id="birthyear">
    <option value="2004"<?php if($birthyear == '2003') echo 'selected'; ?>>2004</option>
    <option value="2003"<?php if($birthyear == '2003') echo 'selected'; ?>>2003</option>
    <option value="2002"<?php if($birthyear == '2002') echo 'selected'; ?>>2002</option>
    <option value="2001"<?php if($birthyear == '2001') echo 'selected'; ?>>2001</option>
    <option value="2000"<?php if($birthyear == '2000') echo 'selected'; ?>>2000</option>
    <option value="1999"<?php if($birthyear == '1999') echo 'selected'; ?>>1999</option>
    <option value="1998"<?php if($birthyear == '1998') echo 'selected'; ?>>1998</option>
    <option value="1997"<?php if($birthyear == '1997') echo 'selected'; ?>>1997</option>
    <option value="1996"<?php if($birthyear == '1996') echo 'selected'; ?>>1996</option>
    <option value="1995"<?php if($birthyear == '1995') echo 'selected'; ?>>1995</option>
    <option value="1994"<?php if($birthyear == '1994') echo 'selected'; ?>>1994</option>
    <option value="1993"<?php if($birthyear == '1993') echo 'selected'; ?>>1993</option>
    <option value="1992"<?php if($birthyear == '1992') echo 'selected'; ?>>1992</option>
    <option value="1991"<?php if($birthyear == '1991') echo 'selected'; ?>>1991</option>
    <option value="1990"<?php if($birthyear == '1990') echo 'selected'; ?>>1990</option>
    <option value="1989"<?php if($birthyear == '1989') echo 'selected'; ?>>1989</option>
    <option value="1988"<?php if($birthyear == '1988') echo 'selected'; ?>>1988</option>
    <option value="1987"<?php if($birthyear == '1987') echo 'selected'; ?>>1987</option>
    <option value="1986"<?php if($birthyear == '1986') echo 'selected'; ?>>1986</option>
    <option value="1985"<?php if($birthyear == '1985') echo 'selected'; ?>>1985</option>
    <option value="1984"<?php if($birthyear == '1984') echo 'selected'; ?>>1984</option>
    <option value="1983"<?php if($birthyear == '1983') echo 'selected'; ?>>1983</option>
    <option value="1982"<?php if($birthyear == '1982') echo 'selected'; ?>>1982</option>
    <option value="1981"<?php if($birthyear == '1981') echo 'selected'; ?>>1981</option>
    <option value="1980"<?php if($birthyear == '1980') echo 'selected'; ?>>1980</option>
    <option value="1979"<?php if($birthyear == '1979') echo 'selected'; ?>>1979</option>
    <option value="1978"<?php if($birthyear == '1978') echo 'selected'; ?>>1978</option>
    <option value="1977"<?php if($birthyear == '1977') echo 'selected'; ?>>1977</option>
    <option value="1976"<?php if($birthyear == '1976') echo 'selected'; ?>>1976</option>
    <option value="1975"<?php if($birthyear == '1975') echo 'selected'; ?>>1975</option>
    <option value="1974"<?php if($birthyear == '1974') echo 'selected'; ?>>1974</option>
    <option value="1973"<?php if($birthyear == '1973') echo 'selected'; ?>>1973</option>
    <option value="1972"<?php if($birthyear == '1972') echo 'selected'; ?>>1972</option>
    <option value="1971"<?php if($birthyear == '1971') echo 'selected'; ?>>1971</option>
    <option value="1970"<?php if($birthyear == '1970') echo 'selected'; ?>>1970</option>
    <option value="1969"<?php if($birthyear == '1969') echo 'selected'; ?>>1969</option>
    <option value="1968"<?php if($birthyear == '1968') echo 'selected'; ?>>1968</option>
    <option value="1967"<?php if($birthyear == '1967') echo 'selected'; ?>>1967</option>
    <option value="1966"<?php if($birthyear == '1966') echo 'selected'; ?>>1966</option>
    <option value="1965"<?php if($birthyear == '1965') echo 'selected'; ?>>1965</option>
    <option value="1964"<?php if($birthyear == '1964') echo 'selected'; ?>>1964</option>
    <option value="1963"<?php if($birthyear == '1983') echo 'selected'; ?>>1963</option>
    <option value="1962"<?php if($birthyear == '1962') echo 'selected'; ?>>1962</option>
    <option value="1961"<?php if($birthyear == '1961') echo 'selected'; ?>>1961</option>
    <option value="1960"<?php if($birthyear == '1960') echo 'selected'; ?>>1960</option>
    <option value="1959"<?php if($birthyear == '1959') echo 'selected'; ?>>1959</option>
    <option value="1958"<?php if($birthyear == '1958') echo 'selected'; ?>>1958</option>
    <option value="1957"<?php if($birthyear == '1957') echo 'selected'; ?>>1957</option>
    <option value="1956"<?php if($birthyear == '1956') echo 'selected'; ?>>1956</option>
    <option value="1955"<?php if($birthyear == '1955') echo 'selected'; ?>>1955</option>
    <option value="1954"<?php if($birthyear == '1954') echo 'selected'; ?>>1954</option>
    <option value="1953"<?php if($birthyear == '1953') echo 'selected'; ?>>1953</option>
    <option value="1952"<?php if($birthyear == '1952') echo 'selected'; ?>>1952</option>
    <option value="1951"<?php if($birthyear == '1951') echo 'selected'; ?>>1951</option>
    <option value="1950"<?php if($birthyear == '1950') echo 'selected'; ?>>1950</option>
    <option value="1949"<?php if($birthyear == '1949') echo 'selected'; ?>>1949</option>
    <option value="1948"<?php if($birthyear == '1948') echo 'selected'; ?>>1948</option>
    <option value="1947"<?php if($birthyear == '1947') echo 'selected'; ?>>1947</option>
    <option value="1946"<?php if($birthyear == '1946') echo 'selected'; ?>>1946</option>
    <option value="1945"<?php if($birthyear == '1945') echo 'selected'; ?>>1945</option>
    <option value="1944"<?php if($birthyear == '1944') echo 'selected'; ?>>1944</option>
    <option value="1943"<?php if($birthyear == '1943') echo 'selected'; ?>>1943</option>
    <option value="1942"<?php if($birthyear == '1942') echo 'selected'; ?>>1942</option>
    <option value="1941"<?php if($birthyear == '1941') echo 'selected'; ?>>1941</option>
    <option value="1940"<?php if($birthyear == '1940') echo 'selected'; ?>>1940</option>
    <option value="1939"<?php if($birthyear == '1939') echo 'selected'; ?>>1939</option>
    <option value="1938"<?php if($birthyear == '1938') echo 'selected'; ?>>1938</option>
    <option value="1937"<?php if($birthyear == '1937') echo 'selected'; ?>>1937</option>
    <option value="1936"<?php if($birthyear == '1936') echo 'selected'; ?>>1936</option>
    <option value="1935"<?php if($birthyear == '1935') echo 'selected'; ?>>1935</option>
    <option value="1934"<?php if($birthyear == '1934') echo 'selected'; ?>>1934</option>
    <option value="1933"<?php if($birthyear == '1933') echo 'selected'; ?>>1933</option>
    <option value="1932"<?php if($birthyear == '1932') echo 'selected'; ?>>1932</option>
    <option value="1931"<?php if($birthyear == '1931') echo 'selected'; ?>>1931</option>
    <option value="1930"<?php if($birthyear == '1930') echo 'selected'; ?>>1930</option>
    <option value="1929"<?php if($birthyear == '1929') echo 'selected'; ?>>1929</option>
    <option value="1928"<?php if($birthyear == '1928') echo 'selected'; ?>>1928</option>
    <option value="1927"<?php if($birthyear == '1927') echo 'selected'; ?>>1927</option>
    <option value="1926"<?php if($birthyear == '1926') echo 'selected'; ?>>1926</option>
    <option value="1925"<?php if($birthyear == '1925') echo 'selected'; ?>>1925</option>
    <option value="1924"<?php if($birthyear == '1924') echo 'selected'; ?>>1924</option>
    <option value="1923"<?php if($birthyear == '1923') echo 'selected'; ?>>1923</option>
    <option value="1922"<?php if($birthyear == '1922') echo 'selected'; ?>>1922</option>
    <option value="1921"<?php if($birthyear == '1921') echo 'selected'; ?>>1921</option>
    <option value="1920"<?php if($birthyear == '1920') echo 'selected'; ?>>1920</option>
    <option value="1919"<?php if($birthyear == '1919') echo 'selected'; ?>>1919</option>
    <option value="1918"<?php if($birthyear == '1918') echo 'selected'; ?>>1918</option>
    <option value="1917"<?php if($birthyear == '1917') echo 'selected'; ?>>1917</option>
    <option value="1916"<?php if($birthyear == '1916') echo 'selected'; ?>>1916</option>
    <option value="1915"<?php if($birthyear == '1915') echo 'selected'; ?>>1915</option>
    <option value="1914"<?php if($birthyear == '1914') echo 'selected'; ?>>1914</option>
    <option value="1913"<?php if($birthyear == '1913') echo 'selected'; ?>>1913</option>
    <option value="1912"<?php if($birthyear == '1912') echo 'selected'; ?>>1912</option>
    <option value="1911"<?php if($birthyear == '1911') echo 'selected'; ?>>1911</option>
    <option value="1910"<?php if($birthyear == '1910') echo 'selected'; ?>>1910</option>
    <option value="1909"<?php if($birthyear == '1909') echo 'selected'; ?>>1909</option>
    <option value="1908"<?php if($birthyear == '1908') echo 'selected'; ?>>1908</option>
    <option value="1907"<?php if($birthyear == '1907') echo 'selected'; ?>>1907</option>
    <option value="1906"<?php if($birthyear == '1906') echo 'selected'; ?>>1906</option>
    <option value="1905"<?php if($birthyear == '1905') echo 'selected'; ?>>1905</option>
    <option value="1904"<?php if($birthyear == '1904') echo 'selected'; ?>>1904</option>
    <option value="1903"<?php if($birthyear == '1903') echo 'selected'; ?>>1903</option>
    <option value="1902"<?php if($birthyear == '1902') echo 'selected'; ?>>1902</option>
    <option value="1901"<?php if($birthyear == '1901') echo 'selected'; ?>>1901</option>
    <option value="1900"<?php if($birthyear == '1900') echo 'selected'; ?>>1900</option>
  </select></td>
</tr>
<tr>
  <td width="150"><div align="right">
<label for="last_name">Club</label>
  </div></td>
  <td colspan="2"><p>
        <label for="birthday"></label>
        <?php $lines = file('runningclubs.txt');
echo '<select class="inputedit" id="club" name="club">';
foreach($lines as $line) {
    echo '<option>'.$line.'</option>';
}
echo '</select>';?>
     
        
    </p></td>
</tr>
<tr>
<td width="150"></td>
<td width="112"><input name="submitButtonName" type="submit" class="submit-btn" value="">
<input type="hidden" name="id" value="<?php echo $id ?>"></td>
<td width="253"> </td>
</tr>
</table>
</form></td>
    </tr>
</table>
</td>
          <td width="17%" valign="middle" bgcolor="#FFFFFF"> </td>
        </tr>
        <tr>
          <td colspan="3" valign="middle"></td>
        </tr>

        <tr>
            <td colspan="3"></td>
        </tr>

        <tr>
            <td colspan="3"></td>
        </tr>

        <tr>
            <td height="143" colspan="3"></td>
  </tr>
    </table>


    <? } ?>

 

but when submit is clicked it just refreshes the page... also is there away to display the success and errors page under the table somehow?

Link to comment
Share on other sites

350 lines of code - sorry, I'm not going to go through that looking for your solution.

 

Add error trapping, remove error suppression, use some echo statements to track progress of the script, test smaller sections ... etc.

Link to comment
Share on other sites

ok solved it to work... but can i ask how would i do this... instead of displaying say ..if (strlen($first_name) <2)

{

die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid first name</font></i></p>");

or

echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>Thankyou for creating your profile. </font></p>");

on a new page... how would i add it under the sign up form

Link to comment
Share on other sites

here is a cut down version of the code

<?php
session_start();
require_once '../settings.php';
checkLogin ('1 2');
$id = $_SESSION['user_id'];

      
?>
<? if (isset($_POST['basic'])){
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$first_name = addslashes($_POST['first_name']);
@$last_name = addslashes($_POST['last_name']);
@$gender = addslashes($_POST['gender']);
@$birthday = addslashes($_POST['birthday']);
@$birthmonth = addslashes($_POST['birthmonth']);
@$birthyear = addslashes($_POST['birthyear']);
@$id = addslashes($_POST['id']);

// Validation
if (strlen($first_name) <2)
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid first name</font></i></p>");
}
if (strlen($first_name) >15)
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid first name</font></i></p>");
}

if (strlen($first_name) == 0 )
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid first name</font></i></p>");
}

if (strlen($last_name) <2)
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid last name</font></i></p>");
}
if (strlen($last_name) >15)
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid last name</font></i></p>");
}

if (strlen($last_name) == 0 )
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid last name</font></i></p>");
}

if (strlen($gender) == 0 )
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid gender</font></i></p>");
}

if (strlen($birthday) == 0 )
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid birthday</font></i></p>");
}

if (strlen($birthmonth) == 0 )
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid birthmonth</font></i></p>");
}

if (strlen($birthyear) == 0 )
{
die("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid birthyear</font></i></p>");
}

//Sending auto respond Email to visitor
$pfw_header = "From: Admin@.com\n"
  . "Reply-To: Admin@.com\n";
$pfw_subject = "Profile @ runningprofiles.com";
$pfw_email_to = "$id";
$pfw_message = "We are just sending you an email to thankyou for adding your profile information.\n"
. "Now you have done this you will be able to have full access to our site.\n"
. "\n"
. "if you have any questions please contact us.\n"
. "------------------------------------------------------------------------------------------------\n"
. "\n"
. "admin";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//saving record to MySQL database
//changing date formats


@$pfw_strQuery = "INSERT INTO `users`(`first_name`,`last_name`,`gender`)VALUES (\"$first_name\",\"$last_name\",\"$gender\")" ;
$pfw_db_selected = mysql_select_db($pfw_db, $pfw_link);
if (!$pfw_db_selected) {
die ('Can not use $pfw_db : ' . mysql_error());
}

//insert new record
$pfw_result = mysql_query($pfw_strQuery);
if (!$pfw_result) {
die('Invalid query: ' . mysql_error());
}
mysql_close($pfw_link);

echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>Thankyou for creating your profile. </font></p>");
}else{
?>
<body bgcolor="#FFFFFF">
<table width="50%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center" valign="middle"><form id="FormName" action='<?php "$_SERVER[php_SELF]" ?>' method="post" name="basic">
        <table width="523" border="0" align="center" cellpadding="0" cellspacing="2">
          <tr>
            <td colspan="3"> </td>
          </tr>
          <tr>
            <td><div align="right">
                <label for="dob">First name</label>
              </div></td>
            <td colspan="2"><input class="inputedit" id="first_name" name="first_name" type="text" size="25" value="" maxlength="255" /></td>
          </tr>
          <tr>
            <td width="150"><div align="right">
                <label for="dob">Last name</label>
              </div></td>
            <td colspan="2"><input class="inputedit" id="last_name" name="last_name" type="text" size="25" value="" maxlength="255" /></td>
          </tr>
          <tr>
            <td width="150"><div align="right">
                <label for="first_name">Gender</label>
              </div></td>
            <td colspan="2"><select class="inputedit" id="gender" name="gender">
                <option value="Male" <?php if($gender == 'Male') echo 'selected'; ?>>Male</option>
                <option value="Female"  <?php if($gender == 'Female') echo 'selected'; ?>>Female</option>
              </select></td>
          </tr>
          <tr>
            <td width="150"><div align="right">
                <label for="last_name">Date of birth</label>
              </div></td>
            <td colspan="2"><label for="birthday"></label>
              <select  name="birthday" id="birthday">
                <option value="1" <?php if($birthday == '1') echo ' selected="selected"'; ?>>1</option>
              </select>
              <label for="birthmonth"></label>
              <select name="birthmonth" id="birthmonth">
                <option value="January" <?php if($birthmonth == 'January') echo 'selected'; ?>>January</option>
              </select>
              <label for="birthyear"></label>
              <select  name="birthyear" id="birthyear">
                <option value="2004"<?php if($birthyear == '2004') echo 'selected'; ?>>2004</option>
              </select></td>
          </tr>
          <tr>
            <td width="150"><div align="right">
                <label for="last_name">Club</label>
              </div></td>
            <td colspan="2"><p>
                <label for="birthday"></label>
                <?php $lines = file('runningclubs.txt');
echo '<select class="inputedit" id="club" name="club">';
foreach($lines as $line) {
    echo '<option>'.$line.'</option>';
}
echo '</select>';?>
              </p></td>
          </tr>
          <tr>
            <td width="150"></td>
            <td width="112"><input name="basic" type="submit" class="submit-btn" value="" />
              <input type="hidden" name="id" value="<?php echo $id ?>" /></td>
            <td width="253"> </td>
          </tr>
          <tr>
            <td></td>
            <td width="112">ADD ERRORS HERE</td>
            <td width="253"> </td>
          </tr>
        </table>
      </form></td>
  </tr>
</table>
<? } ?>

Link to comment
Share on other sites

ok i tried this but does not work

 

<?php if (isset($_POST['basic'])){
if (strlen($first_name) <2)
{
$error=("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid first name</font></i></p>");
}
elseif (strlen($first_name) >15)
{
$error=("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid first name</font></i></p>");
}

elseif (strlen($first_name) == 0 )
{
$error=("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid first name</font></i></p>");
}

elseif (strlen($last_name) <2)
{
$error=("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid last name</font></i></p>");
}
ect ect

else{
submit form ?>

 

 

then i display the errors by this <?php if ( isset( $error ) ) { echo '$error';}?>

Link to comment
Share on other sites

basicly i hit submit when i have a not entred anything and all i get is a blank page... all i have chnaged is the errors

<?php if (isset($_POST['basic'])){
if (strlen($first_name) <2)
{
$error=("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid first name</font></i></p>");
}
elseif (strlen($first_name) >15)
{
$error=("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid first name</font></i></p>");
}

elseif (strlen($first_name) == 0 )
{
$error=("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid first name</font></i></p>");
}

elseif (strlen($last_name) <2)
{
$error=("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid last name</font></i></p>");
}
ect ect

else{
submit form }}

else{ show form}?>... am i doing i right?

Link to comment
Share on other sites

ahh ok i think i see whats im doing wrong

 

<?php if (isset($_POST['basic'])){
if (strlen($first_name) <2)
{
$error=("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid first name</font></i></p>");
}
elseif (strlen($first_name) >15)
{
$error=("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid first name</font></i></p>");
}

elseif (strlen($first_name) == 0 )
{
$error=("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid first name</font></i></p>");
}

elseif (strlen($last_name) <2)
{
$error=("<p align='center'><i><font face='@Arial Unicode MS' size='2' color='#FF0000'>Please enter a valid last name</font></i></p>");
}

else{
?> submit form <?}

else{ ?> show form<?}?>

 

im using else 2wise... how can i make it so if errors show errors.. else submit form.. else show the form

Link to comment
Share on other sites

ok im going to chnage my question abit lol

 

ok so for the sake if this i have chopped the code down to miniamal just to see how i can do this

 

ok so i have my form

 

<form id="FormName" action='basicpost.php' method="post" name="basic">
<table width="523" border="0" align="center" cellpadding="0" cellspacing="2">
<tr><td colspan="3"> </td>
</tr>
<tr>
  <td width="150"><div align="right">
    <label for="dob">First name</label>
  </div></td>
  <td colspan="2"><input class="inputedit" id="first_name" name="first_name" type="text" size="25" value="" maxlength="255" /></td>
</tr>
<tr>
  <td colspan="3">the errors are here</td>
  </tr>
<tr>
<td colspan="3"><input name="basic" type="submit" class="submit-btn" value="">
  <input type="hidden" name="id" value="<?php echo $id ?>"></td>
</tr>
</table>
</form>

 

as usuall it redirects to the action which is basicpost.php

 

shown here:

 

<?php



// Receiving variables
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$first_name = addslashes($_POST['first_name']);
@$last_name = addslashes($_POST['last_name']);
@$gender = addslashes($_POST['gender']);
@$birthday = addslashes($_POST['birthday']);
@$birthmonth = addslashes($_POST['birthmonth']);
@$birthyear = addslashes($_POST['birthyear']);
@$id = addslashes($_POST['id']);

// Validation
if (strlen($first_name) <3)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid first_name</font></p>");
}
if (strlen($first_name) >15)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid first_name</font></p>");
}

if (strlen($first_name) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid first_name</font></p>");
}

if (strlen($last_name) <3)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid last_name</font></p>");
}
if (strlen($last_name) >15)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid last_name</font></p>");
}

if (strlen($last_name) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid last_name</font></p>");
}

if (strlen($gender) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid gender</font></p>");
}

if (strlen($birthday) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid birthday</font></p>");
}

if (strlen($birthmonth) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid birthmonth</font></p>");
}

if (strlen($birthyear) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid birthyear</font></p>");
}

if (strlen($id) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid id</font></p>");
}

//Sending auto respond Email to visitor
$pfw_header = "From: admin@site.com\n"
  . "Reply-To: admin@site.com\n";
$pfw_subject = "thankyou for editing your profile";
$pfw_email_to = "$first_name";
$pfw_message = "We are sending this email to thankyou for creating your profile with us.";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//saving record to MySQL database
//changing date formats


@$pfw_strQuery = "INSERT INTO `users`(`first_name`,`last_name`,`gender`)VALUES (\"$first_name\",\"$last_name\",\"$gender\")" ;
@$pfw_host = "";
@$pfw_user = "";
@$pfw_pw = "";
@$pfw_db = "";
$pfw_link = mysql_connect($pfw_host, $pfw_user, $pfw_pw);
if (!$pfw_link) {
die('Could not connect: ' . mysql_error());
}
$pfw_db_selected = mysql_select_db($pfw_db, $pfw_link);
if (!$pfw_db_selected) {
die ('Can not use $pfw_db : ' . mysql_error());
}

//insert new record
$pfw_result = mysql_query($pfw_strQuery);
if (!$pfw_result) {
die('Invalid query: ' . mysql_error());
}
mysql_close($pfw_link);

echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>Thankyou for editing your profile</font></p>");
?>

 

how can i get it so that itsall done on the same page and the erros or the thankyou message are displayed in the form where it says  <td colspan="3">the errors are here</td>

 

 

Link to comment
Share on other sites

ok i now have

 

<?
function error_bool($error, $field) {
         if($error[$field]) {
             print("<td style=color:red>");
         }
        else {
            print("<td>");
        }
    }

function show_form() {
global $HTTP_POST_VARS, $print_again, $error;
?>
<form id="FormName" action='<?php "$_SERVER[php_SELF]" ?>' method="post" name="basic">

<div align="right">
  <label for="dob">First name</label>
</div>    <input class="inputedit" id="first_name" name="first_name" type="text" size="25" value="" maxlength="255" />
<div align="right">
  <label for="dob">Last name</label>
</div><input class="inputedit" id="last_name" name="last_name" type="text" size="25" value="" maxlength="255" />
<div align="right">
  <label for="first_name">Gender</label>
</div><select class="inputedit" id="gender" name="gender">
  <option value="Male" >Male</option>
  <option value="Female"  >Female</option>
</select>
<div align="right">
  <label for="last_name">Date of birth</label>
</div>
<label for="birthday"></label>
  <select  name="birthday" id="birthday">
    <option> - Day - </option>
    <option value="1">1</option> 
  </select>
  <label for="birthmonth"></label>
  <select name="birthmonth" id="birthmonth">
    <option> - Month - </option>
    <option value="January">January</option>
  </select>
  <label for="birthyear"></label>
  <select  name="birthyear" id="birthyear">
    <option> - Year - </option>
    <option value="2007">2007</option>

  </select>
  <div align="right">
  <label for="last_name">Club</label>
  </div>  <p>
    <label for="birthday"></label>
    <?php $lines = file('runningclubs.txt');
echo '<select class="inputedit" id="club" name="club">';
foreach($lines as $line) {
    echo '<option>'.$line.'</option>';
}
echo '</select>';?>
    
    
  </p>  <?
}
if(isset($_POST["basic"])) {
    check_form();
} else {
    show_form();
}

function check_form()
{
global $HTTP_POST_VARS, $error, $print_again;
$error['error'] = false;
    if($_POST["first_name"]=="") {
        $error['first_name'] = true;
         $print_again = true;
        $message="The first name field is empty<br>";
    }
   if($_POST["last_name"]=="") {
        $error['last_name'] = true;
         $print_again = true;
        $message="The last name field is empty<br>";
    }
     if($print_again) {
         show_form();
       
       } else {
        show_form();
           $message="All Fields are valid <br>";
	   $id =  mysql_real_escape_string( $_POST['id']);

$club = mysql_real_escape_string( $_POST['club']);
$first_name = mysql_real_escape_string( $_POST['first_name']);
$last_name =  mysql_real_escape_string( $_POST['last_name']);
$gender =  mysql_real_escape_string( $_POST['gender']);
$birthyear =  mysql_real_escape_string( $_POST['birthyear']);
$birthmonth =  mysql_real_escape_string( $_POST['birthmonth']);
$birthday =  mysql_real_escape_string( $_POST['birthday']);
$dob = $birthday.'-'.$birthmonth.'-'.$birthyear;


if($birthmonth == 'December'){
    echo 'they chose december';
}
$update = "UPDATE users SET new_user='1',dob='$dob', club= '$club', first_name = '$first_name', gender = '$gender', last_name = '$last_name' WHERE id='$id' ";
       }
  echo '			<p class="error">' . $message . '</p>' . "\n";
}

?>
  <input name="basic" type="submit" class="submit-btn" value="">
  <input type="hidden" name="id" value="<?php echo $id ?>">

</form>

 

but its displaying all fields are valid but not submiting the form into my db ?

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.