Jump to content

stutego

Members
  • Posts

    23
  • Joined

  • Last visited

Posts posted by stutego

  1. form not posting to database

    instead its redirecting me to another page with heading "object not found!"

     

     

    <?php
      $connect= mysql_connect("localhost", "username", "password");
      if (!$connect)
      {
      die("could'nt connect to db:".mysql_error());
      }
      mysql_select_db("myapp", $connect);
      $sql="INSERT INTO form(fname,lname,email,password,telephone,sex,dob)
      VALUES
      ('','$_POST[fname]', '$_POST[lname]', '$_POST[email]' '$_POST[password]', '$_POST[telephone]', '$_POST[sex]', '$_POST[dob]')";
      if (!mysql_query($sql, $connect))
       {
    die("Error:" .mysql_error());
       }
    mysql_close($connect);
    
    
    
    function spamcheck($field)
    {
    $field = filter_var($field, FILTER_SANITIZE_EMAIL);
    if(filter_var ($field, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
    else
    {
    return FALSE;
    }
    }
    if (isset($_POST['email']))
    {
    $mailcheck = spamcheck($_POST['email']);
    }
    if($mailcheck == FALSE)
    {
    //echo "invalid input";
    }
    else
    {
    $email=$_POST['email'];
    $fname=$_POST['fname'];
    $lname=$_POST['lname'];
    $password=$_POST['password'];
    $retype_password=$password;
    $telephone=$_POST['telephone'];
    $sex=$_POST['sex'];
    $DOB=$_POST['dob'];
    }
    
    
    
    function yearOptions()
       {
        for ($i = 1910; $i <= date('Y'); $i++)
           {
       $s = date('Y') == $i ? ' selected="selected"' : '';
       echo '<option '.$s.' value="'.$i.'">'.$i.'</option>'."\n";
       }
       }
    
       function monthOptions()
       {
        $months = array( 1 => "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" );
    
        foreach ( $months as $monthNo => $month )
        {
    	    ( $monthNo == date('n') ) ? $selected = ' selected="selected"' : $selected = '';
    	    echo '<option value="'.$monthNo.'"'.$selected.'>'.$month.'</option>'."\n";
        }
       }
    
       function dayOptions()
       {
        for ( $i = 1; $i <= 31; $i++ )
        {
    	    ( $i == date('j') ) ? $selected = ' selected="selected"' : $selected = '';
    	    echo '<option value="'.$i.'"'.$selected.'>'.$i.'</option>'."\n";
        }
       }
    
       $password=$_POST["password"];
       $salt=rand(100000,999999);
           $encrypted= (MD5(MD5($salt.$password)));
       if($retype_password!=$password)
       {
       echo "password mismatch";
       }
    
    
    
    
    
    ?>
    <form action = "register.php" method=post>
    <fieldset>
    Firstname:
    <input type="text" size=30 name="fname"><br>
    
    Lastname:
    <input type="text" size=30 name="lname"><br>
    
    Email address:
    <input type=text size=30 name="email"><br>
    
    Password:
    <input type=password size=30 name="password"><br>
    
    Retype Password:
    <input type=password size=30 name="retype_password"><br>
    
    Telephone:
    <input type=tel size=30 name="telephone"><br>
    
    sex:
    <input type="radio" name="sex" value="male" checked="checked">Male<br/><input type="radio" name="sex" value="female">Female<br>
    
    Date of birth:
    <select name="dob">
    <?php dayOptions();?>
    </select>
    <select name="dob">
    <?php monthOptions();?>
    </select>
    <select name="dob">
    <?php yearOptions();?>
    </select><br>
    
    <INPUT TYPE=SUBMIT VALUE="Register">
    </fieldset>
    </form>
    
    
    
    
    
    
    

  2. please i've been trying to create a registration form for my website and it seems like its taking forever..... i've got some error of which i have tried to rectify but to no avail, so decided post the code and the error to see if someone might be of help to me

     

     

     

    <?php
     $required=array("fname" => "Firstname",
    	"lname" => "Lastname",
    	"email" => "Email address",
    	"password" => "Password");
     foreach ($required as $field => $label)
     {
    	if (isset($_POST[$field]))
    	{
    	 $warnings[$field] = "Required";
    	}
     }
    
    	if (isset($_POST["email"])&&
    !ereg("^[^@]+@([a-z\-]+\.)+[a-z]{2,4}$", $_POST["email"]))
    $warnings["email"] = "Invalid email";
    if (isset($_POST["telephone"])&&
    !ereg("^\([[:digit:]]{3}\)[[:digit:]]{4}-[[:digit:]]{4}$",
    $_POST["telephone"]))
    $warnings["telephone"] = "Must be (555)0000-0000";
    
    $password=$_POST["password"];
    $salt=rand(100000,999999);
    	$encrypted= (md5($salt.$password));
    
    if (empty($warnings) > 0)
    {
    
    	?>
    <form action = "register.php" method=post>
    <table border=0>
    <tr>
    <td>Firstname:</td>
    <td><input type=text size=30 name="fname" value="<?php echo (isset($_POST["fname"])? $_POST ["fname"]:"");?>" > </td>
    <td><?php echo (isset($warnings["fname"])? $warnings["fname"]:"");?> </td>
    </tr><br/>
    <tr>
    <td>Lastname:</td>
    <td><input type=text size=30 name="lname" value="<?php echo (isset($_POST["lname"])? $_POST ["lname"]:"");?>"> </td>
    <td><?php echo (isset($warnings["lname"])? $warnings["lname"]:"");?> </td>
    </tr>
    <tr>
    <td>Email address:</td>
    <td><input type=text size=30 name="email" <?php if (isset($warnings["email"])) echo "STYLE=\"shaded\"";?> value="<?php echo (isset($_POST["email"])? $_POST["email"]:"");?>"> </td>
    <td><?php echo (isset($warnings["email"])? $warnings["email"]:"");?> </td>
    </tr>
    <tr>
    <td>Password:</td>
    <td><input type=password size=30 name="password" value="<?php echo (isset($_POST["password"])? $_POST["password"]:"");?>"> </td>
    <td><?php echo (isset($warnings["password"])? $warnings[password]:"");?> </td>
    </tr>
    <tr>
    <td>Telephone:</td>
    <td><input type=text size=30 name="telephone" value="<?php echo (isset($_POST["telephone"])? $_POST["telephone"]:"")?>"> </td>
    <td><?php echo (isset($warning["telephone"])? $warnings["telephone"]:"");?> </td>
    </tr>
    <tr>
    <td>sex:</td>
    <td><?php include("sex.php"); ?> </td>
    <td></td>
    </tr>
    <tr>
    <td>Date of birth:</td>
    <?php
    $menu = generate_menu("year", $endYear = '', $startYear = '1900');
    function generate_menu($name, $endYear = '', $startYear = '1900' )
    {
    $selected = "<SELECT NAME=\"$name\">";
    	for ( $i = $startYear; $i <= $endYear; $i++ )
    	{
    	$selected .= "<OPTION ";
    	  ( $i == date('Y') ) ?
    	$selected .= "selected='selected'" : $selected = '';
    	$selected .= "value=\'$i\'>$i</OPTION>";
    }
    $selected .= "</SELECT>";
    return($selected);
    }
      ?>
    <?  
    $month = array(1=> "Jan", 2=> "Feb", 3=> "Mar", 4=> "Apr", 5=> "May", 6=> "Jun", 7=> "Jul", 8=> "Aug", 9=> "Sep", 10=> "Oct", 11=> "Nov", 12=> "Dec");
    $default = "1";
    $option = generate_menu("month", $month, $default);
    function generate_menu($name, $month, $default="")
    {
    $select = "<SELECT NAME=\"$name\">";
    foreach($month as $value => $label)
    {
    	$select .= "<OPTION ";
    	if ($value == $default)
    	$select .= "selected='selected'";
    	$select .= "value=\'$value\'>$label</OPTION>";
    }
    $select .= "</SELECT>";
    return($select);
    }
      ?>
    <?
      $function = generate_menu("day");
    function generate_menu($name)
    {$sel = "<SELECT NAME=\"$name\">";
    	 for ( $i = 1; $i <= 31; $i++ )
    	 {
    	$sel .= "<OPTION ";
    	( $i == date('j') ) ?
    	$sel .= "selected='selected'" : $sel = '';
    	$sel .= "value=\'$i\'>$i</OPTION>";
    }
    $sel .= "</SELECT>";
    return($sel);
    }
    ?>
    <td>
    <?php print $menu;?>
    </td>
    <td>
    <?php print $option;?>
    </td>
    <td>
    <?php print $function;?>
    </td>
    </tr>
    </TABLE>
    <INPUT TYPE=SUBMIT VALUE="Register">
    </form>
    <?php
    }
    else {
    echo "Thank you for registering";
    }
    ?>
    
    

     

     

    error

     

     

     

    Fatal error: Call to undefined function generate_menu() in C:\xampp\htdocs\form.php on line 65

  3. somebody once told me in this forum that i can't create a good calculator with php, but i've been trying my best to prove the critics wrong, and in my effort to do so i have written a front view of how the calculator will look like but the problem is am new to php dont have an idea of how to extract the value from the clicking of a number and dont know how to go about with coding php this is the front view

    <table border ="5">
    <table border="2">
    <th><input type="text" name="num" size="23" ></th>
    </table>
    <table border="3">
    <tr>
    <td><button size="0">+</button></td>
    <td><button width="0"> - </button></td>
    <td><button>*</button></td>
    <td><button>/</button></td>
    </tr>
    <tr>
    <td><button>-></button></td>
    <td><button>1</button></td>
    <td><button>2</button></td>
    <td><button>3</button></td>
    </tr>
    <tr>
    <td><button>4</button></td>
    <td><button>5</button></td>
    <td><button>6</button></td>
    <td><button>7</button></td>
    </tr>
    <tr>
    <td><button>8</button></td>
    <td><button>9</button></td>
    <td><button>0</button></td>
    <td><button>=</button></td>
    </tr>
    <tr>
    <td><button>.</button></td>
    <td><button>%</button></td>
    <td><button>^</button></td>
    <td><button>!</button></td>
    </tr>
    </table>
    </table>
    

     

     

    please help out

  4. please friends i have been trying to fetch data from my database but my output is showing a blank page this are my codes

     

    ?php
    $host_name = "localhost";
    $user_name = "root";
    $password = "";
    $db_name = "addressbook";
    mysql_connect("$host_name", "$user_name", "$password");
    mysql_select_db("$db_name");
    $result = mysql_query("SELECT * FROM bestway");
    ?>
    

     

     

    its just showing a blank page i cant tell why

  5. Notices are logic errors. They may not be syntax errors; the script may continue to run; but the fact is that it is not able to do exactly what you told it to do. You can choose to ignore them but then, you can choose to not look both ways before crossing the street, too. At some point, there will likely be a problem.

     

    OP: Look at the error messages and look at your code. The message says all those errors are on line 8. My guess is this code at the beginning of your script:

     

    $required=array("fname" => "Firstname",
    "lname" => "Lastname",
    "email" => "Email address",
    "password" => "Password");
    foreach ($required as $field => $label)
    {
    if (!$_post[$field])
    {
    $warnings[$field] = "Required";
    }
    }
    

     

    that IF statement is checking each of those elements in the POST array. You need to check to see if they are set. They will not be set when the page is first requested (before it is submitted). Try if (isset($_POST[$field])).

     

    But, TEXT fields will always be set when submitted even if the user left them blank. So you can check for empty, except if the user just types spaces.

     

    I usually wrap all of the validation code in an IF that checks for the SUBMIT element, but you have not given your SUBMIT element a name. You could wrap it in a check of the request method:

     

    if ($_SERVER['REQUEST_METOD'] == 'POST') {
    $required=array("fname" => "Firstname",
    "lname" => "Lastname",
    "email" => "Email address",
    "password" => "Password");
    foreach ($required as $field => $label)
    {
    if (isset($_POST[$field])) {
    $check = trim($_POST[$field]);
    if (empty($check) $warnings[$field] = "Required";
    }
    }
    }
    

     

    i've tried this

    $required=array("fname" => "Firstname",
        "lname" => "Lastname",
        "email" => "Email address",
        "password" => "Password");
     foreach ($required as $field => $label)
     {
        if (isset($_POST[$field]))
           {
    	 $warnings[$field] = "Required";
        }
     }
    
    

     

    and got another error message as this

     

    Notice: Undefined variable: warnings in C:\xampp\htdocs\form.php on line 21

     

    and this is what that line 21 is saying

    if (count($warnings) > 0)
    

  6. OP, just look at the line numbers for the errors.

     

    Line 13:

     

    if ($_POST['email'] && ...

     

    You must check if index 'email' has been set within the $_POST array:

     

    if (isset($_POST['email']) && ...

     

    Follow that logic for line 16, and any other instances that might arise.

    yes tanx very much u've helped me figure some, remaining this ones

     

    Notice: Undefined index: fname in C:\xampp\htdocs\form.php on line 8

     

    Notice: Undefined index: lname in C:\xampp\htdocs\form.php on line 8

     

    Notice: Undefined index: email in C:\xampp\htdocs\form.php on line 8

     

    Notice: Undefined index: password in C:\xampp\htdocs\form.php on line 8

  7. if (!$_post['field'])

     

    $_post should be in CAPS across all instances where it's in lowercase (within your form, as well):

     

    if (!$_POST['field'])

     

    And email/telephone have not been set, yet you're echo'ing them out within the form. You need to first determine whether they're set variables before attempting to access their value.

     

    <td><input type=text size=30 name="email" value="<?php echo (isset($_POST['email']) ? $_POST['email'] : ''); ?>"> </td>

     

    i've done that and it clear part of the error but not all

  8. please friends i have a problem trying to create a form for my web site please this is the code

    <?php
    $required=array("fname" => "Firstname",
    "lname" => "Lastname",
    "email" => "Email address",
    "password" => "Password");
    foreach ($required as $field => $label)
    {
    if (!$_post[$field])
    {
    $warnings[$field] = "Required";
    }
    }
    if ($_POST["email"] &&
    !ereg("^[^@]+@([a-z\-]+\.)+[a-z]{2,4}$", $_POST["email"]))
    $warnings["email"] = "Invalid email";
    if ($_POST["telephone"] &&
    !ereg("^\([[:digit:]]{3}\)[[:digit:]]{3}-[[:digit:]]{4}$",
    $_POST["telephone"]))
    $warnings["telephone"] = "Must be (555)555-5555";
    if (count($warnings) > 0)
    {
    
    ?>
    <form action = "register.php" method=post>
    <table border=0>
    <tr>
    <td>Firstname:</td>
    <td><input type=text size=30 name="fname" value="<?php echo $_post ["fname"];?>" > </td>
    <td><?php echo $warnings["fname"];?> </td>
    </tr><br/>
    <tr>
    <td>Lastname:</td>
    <td><input type=text size=30 name="lname" value="<?php echo $_post ["lname"];?>"> </td>
    <td><?php echo $warnings["lname"];?> </td>
    </tr>
    <tr>
    <td>Email address:</td>
    <td><input type=text size=30 name="email" value="<?php echo $_post["email"];?>"> </td>
    <td><?php echo $warnings["email"];?> </td>
    </tr>
    <tr>
    <td>Password:</td>
    <td><input type=text size=30 name="password" value="<?php echo $_post["password"];?>"> </td>
    <td><?php echo $warnings["password"];?> </td>
    </tr>
    <tr>
    <td>Telephone:</td>
    <td><input type=text size=30 name="telephone" value="<?php echo $_post["telephone"]?>"> </td>
    <td><?php echo $warnings["telephone"];?> </td>
    </tr>
    <tr>
    <td>Sex</td>
    <td><script src="sex.php"> </script></td>
    </tr>
    <tr>
    </TABLE>
    <INPUT TYPE=SUBMIT VALUE="Register">
    </form>
    <?php
    }
    else {
    echo "Thank you for registering";
    }
    ?>
    
    

    and this are the error messages, am a newbie to php please help and this is the error message

     

     

    Notice: Undefined variable: _post in C:\xampp\htdocs\form.php on line 8

     

    Notice: Undefined variable: _post in C:\xampp\htdocs\form.php on line 8

     

    Notice: Undefined variable: _post in C:\xampp\htdocs\form.php on line 8

     

    Notice: Undefined variable: _post in C:\xampp\htdocs\form.php on line 8

     

    Notice: Undefined index: email in C:\xampp\htdocs\form.php on line 13

     

    Notice: Undefined index: telephone in C:\xampp\htdocs\form.php on line 16

     

    please help me out

  9. the updated code took off the error but wasnt giving me the dropdown list i coded

    this is the updated code

    <?php
    //lets select options from a dropdown list using php functions
    $month = array("jan" => "Jan", "feb" => "Feb", "mar" => "Mar", "apr" => "Apr", "may" => "May", "jun" => "Jun", "jul" => "Jul", "aug" => "Aug", "sep" => "Sep", "oct" => "Oct", "nov" => "Nov", "dec" => "Dec");
    		 $default = "jan";
    $select = generate_menu("month", $month, $default);
    function generate_menu($name, $month, $default="") {
    $select= "<SELECT NAME=\"$name\">";
    foreach($month as $value => $label) {
    $select= "<OPTION ";
    if ($value == $default)
    $select= "SELECTED ";
    $select= "VALUE=\"$value\">$label</OPTION>";
    }
    $select= "</SELECT>";
    return($select);
    }
    ?>
    <FORM ACTION="month.php" METHOD=POST>
    <?php print $select;?>
    <INPUT TYPE=SUBMIT VALUE="Continue">
    </FORM>

    and more over the editor am using is notepad+++

    please help me out i've been sick of this code for sum days now

  10. please i have an error message as viz(Notice: Undefined variable: select in C:\xampp\htdocs\interest.php) running this code

    <?php
    //lets select options from a dropdown list using php functions
    $month = array("jan" => "Jan", "feb" => "Feb", "mar" => "Mar", "apr" => "Apr", "may" => "May", "jun" => "Jun", "jul" => "Jul", "aug" => "Aug", "sep" => "Sep", "oct" => "Oct", "nov" => "Nov", "dec" => "Dec");
    		 $default = "jan";
    $select = generate_menu("month", $month, $default);
    function generate_menu($name, $month, $default="") {
    $select .= "<SELECT NAME=\"$name\">";						<<<<------- this is where the error is located
    foreach($month as $value => $label) {
    $select .= "<OPTION ";
    if ($value == $default)
    $select .= "SELECTED ";
    $select .= "VALUE=\"$value\">$label</OPTION>";
    }
    $select .= "</SELECT>";
    return($select);
    }
    ?>
    <FORM ACTION="month.php" METHOD=POST>
    <?php print $select;?>
    <INPUT TYPE=SUBMIT VALUE="Continue">
    </FORM>

×
×
  • 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.