bCourtney07 Posted October 25, 2007 Share Posted October 25, 2007 Okay I have a stupid question here.. I have a form where users enter in information. One of the fields is an employee ID field. I need to verify that they enter in a valid Employee ID. The form is in an external html file so here is my php submit form. <?php require("config.php"); if($_GET['action'] == 'post') { if(empty($_POST['Employee_ID'])|| empty($_POST['Date']) || empty($_POST['Activity']) || empty($_POST['Miles'])) { //if everything is not filled in than prints out error message echo error("blank"); exit; } else $db_conn->Execute("INSERT INTO Activity_Log (`Employee_ID`, `Date`, `Activity`, `Miles`) VALUES ('{$_POST['Employee_ID']}', '{$_POST['Date']}', '{$_POST['Activity']}', '{$_POST['Miles']}')") or die("Error in connecting to the database"); header("Location: success.php?action=success"); } function error($error) { //if error is equal to blank if($error == 'blank') { echo "Please fill in all the required fields before submitting"; } } ?> All of the employee ID's are located in a table called analyzer_query. I think i have the code right to do this but here it is $db_conn->Execute("SELECT * FROM analyzer_query WHERE Employee_ID = ($_POST['Employee_ID'])") or die("Please enter correct EmployeeID"); My question is, is this correct? and where should i put it? ??? Thank you! Quote Link to comment Share on other sites More sharing options...
MadTechie Posted October 25, 2007 Share Posted October 25, 2007 something like this depends on the connection type <?php require("config.php"); if($_GET['action'] == 'post') { if(!empty($_POST['Employee_ID'])) { $db_conn->Execute("SELECT * FROM analyzer_query WHERE Employee_ID = {$_POST['Employee_ID']}") or die("Please enter correct EmployeeID"); //unsure if your using ODBC if ($db_conn->odbc_num_rows < 1){ error("blank"); exit; } } if( empty($_POST['Date']) || empty($_POST['Activity']) || empty($_POST['Miles'])) { //if everything is not filled in than prints out error message error("blank"); exit; } else $db_conn->Execute("INSERT INTO Activity_Log (`Employee_ID`, `Date`, `Activity`, `Miles`) VALUES ('{$_POST['Employee_ID']}', '{$_POST['Date']}', '{$_POST['Activity']}', '{$_POST['Miles']}')") or die("Error in connecting to the database"); header("Location: success.php?action=success"); } function error($error) { //if error is equal to blank if($error == 'blank') { echo "Please fill in all the required fields before submitting"; } } ?> also echo error("blank"); should be error("blank"); Quote Link to comment Share on other sites More sharing options...
bCourtney07 Posted October 25, 2007 Author Share Posted October 25, 2007 yeah guess it would've helped if i had posted this with it... <?php $db_conn = new COM("ADODB.Connection"); $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("./Copy of HR Employee Wellness Program.mdb").";"; $db_conn->open($connstr); ?> Quote Link to comment Share on other sites More sharing options...
MadTechie Posted October 25, 2007 Share Posted October 25, 2007 Okay.. i haven't used ADODB, for a while but i think this should do it.. <?php require("config.php"); if($_GET['action'] == 'post') { if(!empty($_POST['Employee_ID'])) { $ret = $db_conn->Execute("SELECT * FROM analyzer_query WHERE Employee_ID = {$_POST['Employee_ID']}") or die("Please enter correct EmployeeID"); if ($ret->FieldCount() < 1) { error("blank"); exit; } } if( empty($_POST['Date']) || empty($_POST['Activity']) || empty($_POST['Miles'])) { //if everything is not filled in than prints out error message error("blank"); exit; } else $db_conn->Execute("INSERT INTO Activity_Log (`Employee_ID`, `Date`, `Activity`, `Miles`) VALUES ('{$_POST['Employee_ID']}', '{$_POST['Date']}', '{$_POST['Activity']}', '{$_POST['Miles']}')") or die("Error in connecting to the database"); header("Location: success.php?action=success"); } function error($error) { //if error is equal to blank if($error == 'blank') { echo "Please fill in all the required fields before submitting"; } } ?> Quote Link to comment Share on other sites More sharing options...
bCourtney07 Posted October 25, 2007 Author Share Posted October 25, 2007 ok i used that..and got this Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft OLE DB Provider for ODBC Drivers Description: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2. in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 10 Please enter correct EmployeeID edit - guess i should have added thats what i got when i tested it with an invalid id Quote Link to comment Share on other sites More sharing options...
MadTechie Posted October 25, 2007 Share Posted October 25, 2007 change $ret = $db_conn->Execute("SELECT * FROM analyzer_query WHERE Employee_ID = {$_POST['Employee_ID']}") or die("Please enter correct EmployeeID"); to var_dump($_POST['Employee_ID']); $Query = "SELECT * FROM analyzer_query WHERE Employee_ID = {$_POST['Employee_ID']}"; $ret = $db_conn->Execute($Query) or die("Please enter correct EmployeeID:$Query"); Quote Link to comment Share on other sites More sharing options...
bCourtney07 Posted October 25, 2007 Author Share Posted October 25, 2007 string(3) "das" Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft OLE DB Provider for ODBC Drivers Description: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2. in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 9 Please enter correct Employee ID ??? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted October 25, 2007 Share Posted October 25, 2007 erm.. your missing part of that error! inany case change to $Query = "SELECT * FROM analyzer_query WHERE Employee_ID = '{$_POST['Employee_ID']}'"; it should stop the error Quote Link to comment Share on other sites More sharing options...
bCourtney07 Posted October 25, 2007 Author Share Posted October 25, 2007 thats all of the error it gives me <?php require("config.php"); if($_GET['action'] == 'post') { if(!empty($_POST['Employee_ID'])) { var_dump($_POST['Employee_ID']); $Query = "SELECT * FROM analyzer_query WHERE Employee_ID = {$_POST['Employee_ID']}"; $ret = $db_conn->Execute($Query) or die("Please enter correct EmployeeID:$Query"); if ($ret->FieldCount() < 1) { error("blank"); exit; } } if(empty($_POST['Employee_ID']) || empty($_POST['Date']) || empty($_POST['Activity']) || empty($_POST['Miles'])) { //if everything is not filled in than prints out error message error("blank"); exit; } else $db_conn->Execute("INSERT INTO Activity_Log (`Employee_ID`, `Date`, `Activity`, `Miles`) VALUES ('{$_POST['Employee_ID']}', '{$_POST['Date']}', '{$_POST['Activity']}', '{$_POST['Miles']}')") or die("Error in connecting to the database"); header("Location: success.php?action=success"); } function error($error) { //if error is equal to blank if($error == 'blank') { echo "Please fill in all the required fields before submitting"; } } ?> and this is the error i get string(9) "bcourtney" Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft OLE DB Provider for ODBC Drivers Description: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2. in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 11 Please enter correct EmployeeID:SELECT * FROM analyzer_query WHERE Employee_ID = bcourtney Quote Link to comment Share on other sites More sharing options...
MadTechie Posted October 25, 2007 Share Posted October 25, 2007 $Query = "SELECT * FROM analyzer_query WHERE Employee_ID = {$_POST['Employee_ID']}"; should be $Query = "SELECT * FROM analyzer_query WHERE Employee_ID = '{$_POST['Employee_ID']}'"; Note the single quotes SELECT * FROM analyzer_query WHERE Employee_ID = '{$_POST['Employee_ID']}'"; Quote Link to comment Share on other sites More sharing options...
bCourtney07 Posted October 25, 2007 Author Share Posted October 25, 2007 <?php require("config.php"); if($_GET['action'] == 'post') { if(!empty($_POST['Employee_ID'])) { var_dump($_POST['Employee_ID']); $Query = "SELECT * FROM analyzer_query WHERE Employee_ID = '{$_POST['Employee_ID']}'"; $ret = $db_conn->Execute($Query) or die("Please enter correct EmployeeID:$Query"); if ($ret->FieldCount() < 1) { error("blank"); exit; } } if(empty($_POST['Employee_ID']) || empty($_POST['Date']) || empty($_POST['Activity']) || empty($_POST['Miles'])) { //if everything is not filled in than prints out error message error("blank"); exit; } else $db_conn->Execute("INSERT INTO Activity_Log (`Employee_ID`, `Date`, `Activity`, `Miles`) VALUES ('{$_POST['Employee_ID']}', '{$_POST['Date']}', '{$_POST['Activity']}', '{$_POST['Miles']}')") or die("Error in connecting to the database"); header("Location: success.php?action=success"); } function error($error) { //if error is equal to blank if($error == 'blank') { echo "Please fill in all the required fields before submitting"; } } ?> still get the same error with this code. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted October 25, 2007 Share Posted October 25, 2007 okay try this instead.. $Query = "SELECT * FROM analyzer_query"; its not what we want but i would like to see if the error still occurs also try $Query = "SELECT * FROM Activity_Log"; Quote Link to comment Share on other sites More sharing options...
bCourtney07 Posted October 25, 2007 Author Share Posted October 25, 2007 Ok I tried that and got this Warning: (null)(): Unable to lookup fieldcount: Unknown name. in F:\InetPub\wwwroot\EmployeeWellnessProgram\WellnessSubmit.php on line 12 Well i know how to do it with mysql $result = mysql_query("SELECT * FROM users_table WHERE username='{$_POST['username']}'") or die(mysql_error()); $row = mysql_fetch_array( $result ); or maybe i'm not doing something right...or i'm not on the right track.. Quote Link to comment Share on other sites More sharing options...
bCourtney07 Posted October 25, 2007 Author Share Posted October 25, 2007 ??? ??? Anybody know what this could possibly be? or what could be wrong? I'm at a loss. Quote Link to comment Share on other sites More sharing options...
bCourtney07 Posted November 2, 2007 Author Share Posted November 2, 2007 Okay so i really cannot figure this out and i need help if someone can help me. I need to have the employee id be validated (make sure it's in the login database) before the data from the form is put into the database if this makes any sense. here is the code for the form <?php require("config.php"); if($_GET['action'] == 'post') { if(empty($_POST['Employee_ID']) || empty($_POST['Date']) || empty($_POST['Activity']) || empty($_POST['Miles'])) { //if everything is not filled in than prints out error message error("blank"); exit; } else $db_conn->Execute("INSERT INTO Activity_Log (`Employee_ID`, `Date`, `Activity`, `Miles`) VALUES ('{$_POST['Employee_ID']}', '{$_POST['Date']}', '{$_POST['Activity']}', '{$_POST['Miles']}')") or die("Error in connecting to the database"); header("Location: success.php?action=success"); } function error($error) { //if error is equal to blank if($error == 'blank') { echo "Please fill in all the required fields before submitting"; } //if error is equal to blank if($error == 'user') { echo "Please fill in the correct Employee ID"; } } ?> here is the config.php file <?php $db_conn = new COM("ADODB.Connection"); $connstr = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=F:\Wellness Program\Copy of HR Employee Wellness Program.mdb;"; $db_conn->open($connstr); ?> Can someone help me? Point me in the direction of a tutorial or how to go about doing this. i've tried all of the above code's and haven't had any luck. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.