Jump to content

PC Nerd

Members
  • Posts

    1,122
  • Joined

  • Last visited

    Never

Everything posted by PC Nerd

  1. Hi, im using a foreach($_POST as $field => $value) {} to loop through my form input and validate it. I have a line that checks to see if the field is empty, and if it is it sets the error and then passes that iteration: if(empty($value)) {pass;} however it seems not to be doing this. HEre is my code: foreach($_POST as $field => $value) { if($field == 1) {pass;} if($_POST['Save'] == 1 && $field == "User_Name" || $field == "Password" || $field == "Conf_Password" || $field == "Emg_Relation") { ### Validate the Username, password and email if(empty($value)) { $ERROR[$idx]['err'] = "empty"; $ERROR[$idx]['empty'] = $field; $idx ++; } else if(!preg_match("[A-za-z]", $value)) { $ERROR[$idx]['err'] = "invalid"; $ERROR[$idx]['empty'] = $field; $idx ++; } else if(strlen($value) > 20 || strlen($value) < 5) { $ERROR[$idx]['len'] = "invalid"; $ERROR[$idx]['empty'] = $field; $idx ++; } else if($field == "Password" && $value != $_POST['Conf_Password']) { $ERROR[$idx]['err'] = "passmtch"; $idx ++; } } if($_POST['Save'] == 0 && empty($value)) { $ERROR[$idx]['err'] = "empty"; $ERROR[$idx]['empty'] = $field; $idx ++; } if($field == "F_Name" || $field == "L_Name" || $field == "User_Name" || $field == "Emg_Name") { ### Validate the names if(!ereg("[A-za-z' -]", $value)) { $ERROR[$idx]['err'] = "invalid"; $ERROR[$idx]['empty'] = $field; $idx ++; } else if(strlen($value) > 20) { $ERROR[$idx]['err'] = "len"; $ERROR[$idx]['empty'] = $field; $idx ++; } ..... i know that my ERROR array is containing one entry for an invalid F_Name, and then an empty error for the F_Name: Here is my error array output below using print_r($ERROR); Array ( [0] => Array ( [err] => empty [empty] => F_Name ) [1] => Array ( [err] => invalid [empty] => F_Name ) [2] => Array ( [err] => invalid [empty] => 1 ) [3] => Array ( [err] => empty [empty] => L_Name ) [4] => Array ( [err] => invalid [empty] => L_Name ) ..... note that the: [empty] => 1 is simply an error which im in the middle of fixing - however it shouldnt effect this outcome Am i using teh correct method to skip th eloop iteration - or is there another way to do it? Thanks for your help in advance
  2. firstly can i make a suggestion about your code If there is an error - ie the fields are empty - then doint make the connection to the database eg: - im not using direct PH code here however its easy to make changes to your script - just rearrange the location of your brackets if(user or password is empty) { set error message } else { make your connections } if isset($error message) { echo $error; } that shoudl help you make it work a little better
  3. Hi, Im working on a validation script for creating user accounts - and Im not at all familiar with ereg(), preg_match() etc. Ive been mashing together expressions from forums etc - and Ive come accrose the error with the following line: if(!ereg("[A-za-z' -]{1, 50}", $trim($value))) { Here is the surounding code: ... ... foreach($_POST as $field => $value) { if($_POST['Save'] == 1 && $field == "User_Name" || $field == "Password" || $field == "Conf_Password" || $field == "Email" || $field == "Emg_Relation") { ### Validate the Username, password and email if(!ereg("[A-za-z' -]{1, 50}", $trim($value))) { $ERROR[$idx]['err'] = "invalid"; $ERROR[$idx]['empty'] = $field; $idx ++; } if(strlen($value) > 20) { ... ... The error is this: Fatal error: Function name must be a string in ###\new_user.php on line 60 Im confused by the meaning of this error - meaning ihave no clue as how to fix it. Any suggestions or answers woudl be much appreciated. Thanks in advance
  4. if your trying to link to just the database - then youll most likely have to open a rule that allows the IP address of your external server. if using cPanel - its in the MySQL page i think/.... gdlk
  5. Thanks - thats got it Thansk for all your help - Happy New Year :>
  6. Thanks I understand the basics - but i dont understand how to construct the 3{z} stuff . is ther elike a list or table that says what to do? Thanks for oyu help
  7. Hi, Im writing scripts that validate user input - and Ive been told that regular expressions are by far the best way to go. the problem is that I dont understand how to format the string to validate with. ie ereg("validation string", $var); Im wondeirng if anyone here has a good tutorial that will explain how to construict one of these strings so that I can validate different data sets. Im particularly interested in text/date formats and emails etc. Thanks for any and all help in advance
  8. ok assuming that someone only enters the numbers withought the spaces or dashes etc ( which is how ill tell them to enter it) - how would i tell how many digits in the value. eg: $_POST['cell_no'] = "1111111111"; how can i tell teh length/dighits in that value? Thanks.
  9. Hi, Im looking for a way to validate a phone number. I'm lost as to how to check if its an integer, and to remove any punctuation it is - and the length of the number. The othe rproblem ive got is that i dont know how many digits ina US mobile phone number. ( Im from Australia.....). If anyone can point me in teh right direction with some functionsetc, id be most greatful. Thanks in advance, PC Nerd
  10. the main reason is that you need double quotes to evaluate the caharacters. if you user "hello world \n" that will work because it will pringt a new line isntead of a "\" and a "n" gdlk
  11. <?php $lastname = "ME"; $firstname = "NAME"; $email = "email@domain.com"; if(is_writable('TEST.csv')) { $fp = fopen('TEST.csv','a'); $content = "$lastname,$firstname,$email\n"; fwrite($fp,$content); fclose($fp); } ?> thats what ive got - and its working. Thanks Thanks
  12. *** UPDATE: echoing: "\n"; at the end of the record foesnt work - it actually echos out as the characters "\" and "n". is this because o fht encoding or somethign eg ASCI etc??? thanks
  13. hmm might work: set a cookie when you first submit the page. as a boolean value or something.. then simply check if the page has been submitted recently - maybe log hte timein the cookie? gdlk
  14. Hi, Im looking for a way to write to a CSV file. I can get the writing working, but i cant seem to find out how to get the records seperated. at the moment the firlds are placed correctly "value, value, value" - however the next record only continues on the same line when veiwed in MS Office Excel. How can I create the newline? thanks
  15. port check: Apache <http> 80 C:\xampp\apache\bin\apache.exe Apache <webDAV> 81 Free Apache <HTTPS> 443 C:\xampp\apache\bin\apache.exe MySQL 3306 C:\xampp\mysql\bin\mysqld-nt.exe Firefilla <ftp> 21 Free FireZilla <admin> 14147 free Mercury <smtp> 25 free Mercury <pop3> 110 free mercury <imap> 143 free im only using the MYSQL and apach and iot looks like the only ports being used are by a) those programs and b) not anothe rprogram an other suggestions about it? *** im running on localhost - not a purchased host etc ( howerver my purchased host does work with all my scripts (of corse )) thnakx
  16. hmm ok - yes it is XAMPP sry for the typo im only getting mysql_connect errors some of the time others im simply not being able to connect, or the entire APACHE server wont work. Ill look into Apache2Triad.. thanks for the suggestion
  17. depends on the differences in control. if there is a massive difference, may be easier building different pages. either way si possilbe gdlk.
  18. print_r($ARRAY_NAME, "<br>"); that shoudl to what you want - hwever im not to familiar with the print_r function so please check it out on the php.net site. gdlk
  19. hi, Im creating a script where administration can update database entries. the form directs to itself... eg edit_tour.php?id=33 directs to edit_tour.php?id=33&action=update here is the code that runs on action==update if ($_GET['action'] == 'update' && isset($_GET['id']) && !empty($_GET['id'])) { $Day = date("j", $_POST['Start_date_day']); $Month = date("n", $_POST['Start_date_day']); $Year = date("Y", $_POST['Start_date_day']); $Hour = date("G", $_POST['Start_Date_hour']); $Minute = date("i", $_POST['Start_date_minute']); $Start_Date = mktime($Hour, $Minute, 0, $Month, $Day, $Year); $Day = date("j", $_POST['Finish_date_day']); $Month = date("n", $_POST['Finish_date_day']); $Year = date("Y", $_POST['Finish_date_day']); $Hour = date("G", $_POST['Finish_Date_hour']); $Minute = date("i", $_POST['Finish_date_minute']); $Finish_Date = mktime($Hour, $Minute, 0, $Month, $Day, $Year); $SQL = "UPDATE tours SET `Tour_Name` = '".$_POST['Tour_Name']."', `Destination` = '".$_POST['Destination']."', `Departs` = '".$_POST['Departs']."', `Description` = '".$_POST['Description']."', `Seats_Total` = '".$_POST['Seats_Total']."', `Seats_Avail` = '".$_POST['Seats_Avail']."', `Start_Date` = '".$Start_Date."', `Finish_Date` = '".$Finish_Date."' WHERE `User_ID` = ".$_GET['id'].""; echo "<br>".$SQL."<br>\n"; $Create_Query = MYSQL_DATABASE_QUERY($SQL, $DB_Server); } now this is the output of my query: UPDATE tours SET `Tour_Name` = 'Sydney - Sport', `Destination` = 'Sydney Stadium', `Departs` = 'Katoomba Train Station', `Description` = 'NEW', `Seats_Total` = '12', `Seats_Avail` = '8', `Start_Date` = '1201912200', `Finish_Date` = '1197936000' WHERE `User_ID` = 33 Im also using a different MYSQL connection method. ive had to comment out most of it becausae i had troube with it, but this is the file: <?php function CONNECT_MYSQL_DATABASE() { $host = "***"; #usually localhost $account = "***"; # username for access. eg. root $password = "***"; $db_name = "***"; #name of database on the server that you want to connect. global $db_type; $db_type = 4.1; # MySQL version #if ($db_type <= 4.0) { # $DB_Server = mysql_connect($host, $account, $password) or die("Cannot conenct to the selected MySQL ".$db_Type." on the selected server. Invalid Parameters"); # $DB_Select = mysql_select_db($db_name, $DB_Server) or die("Connection established to server, however unable to find selected database."); #} #else if($db_Type >= 4.1) { #echo "connecting to a 4.1 or higher"; $DB_Server = mysqli_connect($host, $account, $password);# or die("Cannot conenct to the selected MySQL ".$db_Type." on the selected server. Invalid Parameters"); $DB_Select = mysqli_select_db($DB_Server, $db_name);# or die("Connection established to server, however unable to find selected database."); #} return $DB_Server; } function MYSQL_DATABASE_QUERY($SQL, $DB_Server) { #if($db_type <= 4.0) { # $QUERY = mysql_query($SQL, $DB_Server) or die(mysql_error()); #} #else #if($db_type >= 4.1) { $QUERY = mysqli_query($DB_Server, $SQL);# or die(mysqli_error($DB_Server)); #echo $SQL; #if(isset($QUERY)) {echo "$QUERY is set";} #if(empty($QUERY)) {echo "$QUERY is empty";} #echo "<br><br>"; #echo "QUERY: ".$QUERY; #echo "<br> and query"; #} return $QUERY; } function MYSQL_GET_ARRAY($QUERY) { $ROW = mysqli_fetch_array($QUERY); return $ROW; } $DB_Server = CONNECT_MYSQL_DATABASE(); ?> Now i know that these functions work because they are workign for all my INSERT and SELECT queries, which makes me think that its the actual SQL that ismy problem, and nto the connection etc. Does anyone have any suggestions on how i can fix this problem. *** there are no errors echoed out. *** when checking the database with phpmyadmin - the database hasnt been updated with the new values..... which means the UPDATE query didnt work. Thanks for any suggestions in advance.
  20. hi. Create a field in Mysql within your users account and name it Last_Login, and have its value as a timestamp. than when your user logs in update that field to =: date(), or strtotime("now YOUR_TIMEZONE"); etc etc. look into your date functions. gdlk
  21. Hi, Ive recently come up with this problem - where any PHP script will connect to MySQL only about half the time. the other half it will either tel me the server is not reqponding ( in phpmyadmin) - or not conenct and return errors with my own code - or the entire server wont respond. Im working off localhost, using XMAPP 1.6.4 version. It seems weird because the mysql administrator program says that everythign is working... green light. Has anyone else come across this problem. the only thing that I thought migh tbe causeing the problem is MySQL having a "max_query" per minute limit or something... Has anyone got any suggestions on what may be causeing this and how to fix it? Thanks for your time.
  22. ok - got it working at last. here it is for reference ### CREATE TEH TIME ARRAYS $Days = array(); $Hours = array(); $Minutes = array(); #$follow = 1; #for($i=time();$follow == 1;$i += strtotime("+ 1 day", $i)) { $i = time(); while($i <= strtotime("+ 2 months")) { $day = date("d/m/y - l", $i); echo "".$i."<br>"; $Days[$i] = $day; $i = $i + 60*60*24; #if($i >= strtotime("now + 2 months AEST")) {$follow = 0;} } ###CREATE THE MENU $Start_Date = $ROW['Start_Date']; echo date("d/m/y", $Start_Date)."<br>"; echo "<form action = '***' method = 'POST'>\n"; echo "Start Date: <select name = 'Start_date_day'>\n"; foreach($Days as $field => $value) { if(date("d/y", $Start_Date) == date("d/y", $field)) {$s = " selected";} else {$s = "";} #echo date("d/m/y", $field)." => ".date("d/m/y", $Start_Date)."<br>"; echo "<option value = '".$field."' ".$s.">".$value."</option>\n"; } ?> </select> Thanks for all your help. ;D :D ;) ;D
  23. hmmm ok - can i just check - can someone tell me how that shorthand if statement works? thnks
  24. i your looking for only one result: SELECT * FROM gname ORDER BY rand() LIMIT 1
×
×
  • 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.