Page 1 of 1

Help

Posted: Mon Feb 15, 2010 6:40 am
by rica4th07
can you help me??? about this code nid imediately!!!!

<?php
function isIntegerVip($n) {
$n2 = (int) $n;
$s = (string) $n;
$s2 = (string) $n2;
if ($s == $s2) {
return true;
} else {
return false;
}
}

function isValidDateVip($dateToCheck) {
$date_elements = exploe("/", $dateToCheck);
if (checkdate($date_elements[0], $date_elements[1], $date_elements[2])) {
return true;
} else {
return false;
}
}

if ($action == "add" OR $action == "edit") { <----------- Notice: Undefined variable: action in /opt/lampp/htdocs/sample2/sample.php on line 22
$numOfError = 0;
$msg = "";

// validate integer
$intEntry = $_POST['intEntry'];
if (!isIntegerVip($intEntry)) {
$numOfError = $numOfError + 1;
$msg = $msg . "intEntry field must be an integer. ";
}

// validate and double
$anyNum = $_POST['anyNum']
if (is_numeric($anyNum)) {
$numOfError = $numOfError + 1;
$msg = $msg . "anyNum field must be a number. ";
}

// validate blank field
$txtField = $_POST['txtfield'];
if (trim($txtField) == "") {
$numOfError = $numOfError + 1;
$msg = $msg . "txtField must not be blank. ";
}

// validate date field
$dateField = $_POST['dateField'];
if (!isValidDateVip($dateField)) {
$numOfError = $numOfError + 1;
$msg = $msg . "dateField field must be a valid date. ";
}

if($numOfError > 0) {
/* if validation catches error, let user
enter corrected fields
*/
include_once("formentry.php")
} else {
/* if no more validation errors, move on
to processing. In case you need to go back
to formentry.php with no more validation
errors, make sure to unset $numOfErrors so it doesn't
assume there are errors:
*/
unset($numOfError):
if ($action == "add") {
mysql_querry("INSERT...");
} elseif ($action == "edit") {
mysql_query("UPDATE...");
}
include_once("listentry.php);
} // endelse

} elseif ($action == "delete") { <--------------- Notice: Undefined variable: action in /opt/lampp/htdocs/sample2/sample.php on line 75
/* ... */
}
?>

<?php
if (!isset($numOfError)) {
$action = $_GET['action']; <--------Notice: Undefined index: action in /opt/lampp/htdocs/sample2/sample.php on line 82
$id = $_GET['id']; <--------------------Notice: Undefined index: id in /opt/lampp/htdocs/sample2/sample.php on line 83
...over at formentry.php ...
if ($action == "edit") {
$result = mysql_querry("SELECT...");
$row = @mysql_fetch_object($result);
$dateField = date("n/j/y", strtotime($row->dateField));
...
} elseif ($action == "add") {
$dateField = "";
...
}
}
?>

pls help me im just starting to learn php.....

Re: Help

Posted: Mon Feb 15, 2010 6:42 am
by papa
Use the code tags please.

Code: Select all

 
// validate and double
$anyNum = $_POST['anyNum']; <-- 
...
 
if($numOfError > 0) {
/* if validation catches error, let user
enter corrected fields
*/
include_once("formentry.php"); <---
 
Just took a quick look.

Re: Help

Posted: Mon Feb 15, 2010 6:47 am
by rica4th07
oh thx a lot im little bit of a tired thx...

Re: Help

Posted: Mon Feb 15, 2010 6:51 am
by rica4th07
Parse error: syntax error, unexpected ':', expecting ';' in /opt/lampp/htdocs/sample2/sample.php on line 66

<?php
function isIntegerVip($n) {
$n2 = (int) $n;
$s = (string) $n;
$s2 = (string) $n2;
if ($s == $s2) {
return true;
} else {
return false;
}
}

function isValidDateVip($dateToCheck) {
$date_elements = exploe("/", $dateToCheck);
if (checkdate($date_elements[0], $date_elements[1], $date_elements[2])) {
return true;
} else {
return false;
}
}

if ($action == "add" OR $action == "edit") {
$numOfError = 0;
$msg = "";

// validate integer
$intEntry = $_POST['intEntry'];
if (!isIntegerVip($intEntry)) {
$numOfError = $numOfError + 1;
$msg = $msg . "intEntry field must be an integer. ";
}

// validate and double
$anyNum = $_POST['anyNum'];
if (is_numeric($anyNum)) {
$numOfError = $numOfError + 1;
$msg = $msg . "anyNum field must be a number. ";
}

// validate blank field
$txtField = $_POST['txtfield'];
if (trim($txtField) == "") {
$numOfError = $numOfError + 1;
$msg = $msg . "txtField must not be blank. ";
}

// validate date field
$dateField = $_POST['dateField'];
if (!isValidDateVip($dateField)) {
$numOfError = $numOfError + 1;
$msg = $msg . "dateField field must be a valid date. ";
}

if($numOfError > 0) {
/* if validation catches error, let user
enter corrected fields
*/
include_once("formentry.php");
} else {
/* if no more validation errors, move on
to processing. In case you need to go back
to formentry.php with no more validation
errors, make sure to unset $numOfErrors so it doesn't
assume there are errors:
*/
unset($numOfError):
if ($action == "add") {
mysql_querry("INSERT...");
} elseif ($action == "edit") {
mysql_query("UPDATE...");
}
include_once("listentry.php);
} // endelse

} elseif ($action == "delete") {
/* ... */
}
?>

another prob pls help.... thx

Re: Help

Posted: Mon Feb 15, 2010 6:56 am
by papa

Code: Select all

unset($numOfError):
Should be:

Code: Select all

unset($numOfError);
Also a good way of coding is to use intendation:

Code: Select all

 
} else {
    /* if no more validation errors, move on
    to processing. In case you need to go back
    to formentry.php with no more validation
    errors, make sure to unset $numOfErrors so it doesn't
    assume there are errors:
    */
    unset($numOfError);
    if ($action == "add") {
        mysql_querry("INSERT...");
    } elseif ($action == "edit") {
        mysql_query("UPDATE...");
    }
include_once("listentry.php"); <-- also parse error before
} // endelse
 
 

Re: Help

Posted: Tue Feb 16, 2010 1:35 am
by rica4th07
<?php
if (!isset($numOfError)) {
$action = $_GET['action'];
$id = $_GET['id'];
if ($action == "edit") {
$result = mysql_querry("SELECT...");
$row = @mysql_fetch_object($result);
$dateField = date("n/j/y", strtotime($row->dateField));
... <-------------------------- the error is in here....
} elseif ($action == "add") {
$dateField = "";
...
}
}
?>


Parse error: syntax error, unexpected '.' in /opt/lampp/htdocs/sample2/sample.php on line 88

help me pls coz im a newbie in php nid some help

Re: Help

Posted: Tue Feb 16, 2010 2:14 am
by rica4th07
rica4th07 wrote:can you help me??? about this code nid imediately!!!!

<?php
function isIntegerVip($n) {
$n2 = (int) $n;
$s = (string) $n;
$s2 = (string) $n2;
if ($s == $s2) {
return true;
} else {
return false;
}
}

function isValidDateVip($dateToCheck) {
$date_elements = exploe("/", $dateToCheck);
if (checkdate($date_elements[0], $date_elements[1], $date_elements[2])) {
return true;
} else {
return false;
}
}

if ($action == "add" OR $action == "edit") { <----------- Notice: Undefined variable: action in /opt/lampp/htdocs/sample2/sample.php on line 22
$numOfError = 0;
$msg = "";

// validate integer
$intEntry = $_POST['intEntry'];
if (!isIntegerVip($intEntry)) {
$numOfError = $numOfError + 1;
$msg = $msg . "intEntry field must be an integer. ";
}

// validate and double
$anyNum = $_POST['anyNum']
if (is_numeric($anyNum)) {
$numOfError = $numOfError + 1;
$msg = $msg . "anyNum field must be a number. ";
}

// validate blank field
$txtField = $_POST['txtfield'];
if (trim($txtField) == "") {
$numOfError = $numOfError + 1;
$msg = $msg . "txtField must not be blank. ";
}

// validate date field
$dateField = $_POST['dateField'];
if (!isValidDateVip($dateField)) {
$numOfError = $numOfError + 1;
$msg = $msg . "dateField field must be a valid date. ";
}

if($numOfError > 0) {
/* if validation catches error, let user
enter corrected fields
*/
include_once("formentry.php")
} else {
/* if no more validation errors, move on
to processing. In case you need to go back
to formentry.php with no more validation
errors, make sure to unset $numOfErrors so it doesn't
assume there are errors:
*/
unset($numOfError):
if ($action == "add") {
mysql_querry("INSERT...");
} elseif ($action == "edit") {
mysql_query("UPDATE...");
}
include_once("listentry.php);
} // endelse

} elseif ($action == "delete") { <--------------- Notice: Undefined variable: action in /opt/lampp/htdocs/sample2/sample.php on line 75
/* ... */
}
?>

<?php
if (!isset($numOfError)) {
$action = $_GET['action']; <--------Notice: Undefined index: action in /opt/lampp/htdocs/sample2/sample.php on line 82
$id = $_GET['id']; <--------------------Notice: Undefined index: id in /opt/lampp/htdocs/sample2/sample.php on line 83
...over at formentry.php ...
if ($action == "edit") {
$result = mysql_querry("SELECT...");
$row = @mysql_fetch_object($result);
$dateField = date("n/j/y", strtotime($row->dateField));
...
} elseif ($action == "add") {
$dateField = "";
...
}
}
?>

pls help me im just starting to learn php.....

Re: Help

Posted: Tue Feb 16, 2010 2:41 am
by papa
Define action in the beginning of your script

<?php
$action = "";

Re: Help

Posted: Tue Feb 16, 2010 2:53 am
by rica4th07
sir the error is in there nothing happend

<?php
if ($action == "add" OR $action == "edit") {
$numOfError = 0;
$msg = "";


Notice: Undefined variable: action in /opt/lampp/htdocs/sample2/sample.php on line 22

same error.... sir

i stock in here and dont know what to do....

thx 4 d help...

Re: Help

Posted: Tue Feb 16, 2010 3:36 am
by rica4th07
can u help me?? pls identify the errors thx....
sorry im a newbie in here nid some tutorials.....

<?php
function isIntegerVip($n) {
$n2 = (int) $n;
$s = (string) $n;
$s2 = (string) $n2;
if ($s == $s2) {
return true;
} else {
return false;
}
}

function isValidDateVip($dateToCheck) {
$date_elements = exploe("/", $dateToCheck);
if (checkdate($date_elements[0], $date_elements[1], $date_elements[2])) {
return true;
} else {
return false;
}
}

if ($action == "add" OR $action == "edit") {
$numOfError = 0;
$msg = "";

// validate integer
$intEntry = $_POST['intEntry'];
if (!isIntegerVip($intEntry)) {
$numOfError = $numOfError + 1;
$msg = $msg . "intEntry field must be an integer. ";
}

// validate and double
$anyNum = $_POST['anyNum'];
if (is_numeric($anyNum)) {
$numOfError = $numOfError + 1;
$msg = $msg . "anyNum field must be a number. ";
}

// validate blank field
$txtField = $_POST['txtfield'];
if (trim($txtField) == "") {
$numOfError = $numOfError + 1;
$msg = $msg . "txtField must not be blank. ";
}

// validate date field
$dateField = $_POST['dateField'];
if (!isValidDateVip($dateField)) {
$numOfError = $numOfError + 1;
$msg = $msg . "dateField field must be a valid date. ";
}

if($numOfError > 0) {
/* if validation catches error, let user
enter corrected fields
*/
include_once("formentry.php");
} else {
/* if no more validation errors, move on
to processing. In case you need to go back
to formentry.php with no more validation
errors, make sure to unset $numOfErrors so it doesn't
assume there are errors:
*/
unset($numOfError);
if ($action == "add") {
mysql_querry("INSERT...");
} elseif ($action == "edit") {
mysql_query("UPDATE...");
}
include_once("listentry.php");
} // endelse

} elseif ($action == "delete") {
/* ... */
}
?>

<?php
if (!isset($numOfError)) {
$action = $_GET['action'];
$id = $_GET['id'];
if ($action == "edit") {
$result = mysql_querry("SELECT...");
$row = @mysql_fetch_object($result);
$dateField = date("n/j/y", strtotime($row->dateField));

} elseif ($action == "add") {
$dateField = "";

}
}
?>


...over at formentry.php

<?php


if (isset($msg)) {
echo $msg;
}

?>


<script language="JavaScript">
<!--

function validForm(thisForm) {
if (thisForm.s.value =="") {
alert("you must a string");
thisForm.s.focus():
return false:
}

if ( thisForm.n.value <= 0) {
alert("Number must be greater than 0");
thisForm.n.focus();
return false;
}

if ( (thisform.projectCost.value =="") || isNaN(thisForm.projectCost.value) ) {
alert("Project Cost field must have a number or 0");
thisForm.projectCost.focus();
return false;
}

/* is you want to allow user to enter a number or nothing at all, then remove
the check for "": */

if ( isNaN(thisForm.projectCost.value) ) {
alert("Project Cost field must be a number");
return false;
}

/* using isNan() -- "is Not a Number" -- is more effective than this next version
becuse this 2nd version will not aler when user enters something like
453,344 --'cuz as long as user enters a number in the first few entiries, it
*/

if ( !((thisForm.n2.value > 0) || (thisForm.n2.value <= 0)) ) {
alert("You must enter a number" );
return false;
}

return true;
}

//-->
</script>

...

<FORM onSubmit="return validForm(this)" ACTION="praction.php" METHOD="POST" ENCTYPE="application/x-www-form-urlencoded">

Re: Help

Posted: Wed Feb 17, 2010 9:02 am
by emmbec
Mods, shouldn't this be moved to some other forum? And shouldn't CODE TAGS be used instead?

rica4th07, read the rules please so it can be easier for us to help you. :D