stutego
-
Posts
23 -
Joined
-
Last visited
Posts posted by stutego
-
-
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
-
-
i need help on how to write a code or a clue on what i need to know when writting it
-
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
-
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
-
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)
-
so please friends how am i going to clear this errors or notices like i've said before am new to php and i dont really understand this error messages that was my reason for posting it here
-
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
-
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
-
You can write regular expressions but you can't understand those errors?
i've tried my best to clear the error and on like i said before am new to php, and i've been trying my best to learn php on my own
please help out
-
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
-
tanx to you all for helping out
-
ok kelvin tanx 4 that...
-
k m sorry @Jessica but dat ws'nt inclusive in the ebook am using, am using oreilly's php ebook
-
but please @jessy what are diff btw .= & = and what are their functions to the code
-
You didn't post using the code tags. You apparently didn't read the entire second sentence, because it explains what's wrong with your code. I'm guessing you don't understand what .= and = do.
haha i forgot adding the tag
tanx a lot Jessy wil love u helping out next time on any prob
-
@
You did like maybe 1/5th of what this post says.
what did u mean by saying i did just 1/5th and can u explain the remaining 1ce i did'nt do
-
much tanx to Jessica, Aykay47 & Barand 4 helping me out with my prob i used Aykay47's anwser and it worked out well....
much tanx 2 Jessica for ur's 2...... like i've said before am new to php and programming environment wish to be creative using php
-
@
Your function needs to
return $select;
return $select; is there
-
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
-
@Jessica please i've tried it out, but only got just the (contine) button please help me out my still a newbie to php
-
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>
form not posting to database
in Applications
Posted
form not posting to database
instead its redirecting me to another page with heading "object not found!"