Amy1980 Posted January 6, 2007 Share Posted January 6, 2007 Hello. I got some problems with my website.1. I got captcha. It works fine but I want to add javascript alert. Ehan I add it I get it always, when I use [code]echo[/code] I always get it.Source:Captcha and inserting values to the db[code]session_start(); if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) { $query = "INSERT INTO guestbook (name, email, url, message, browser, gender, age, kraj, ip_add, hostname,entry_date) " . "VALUES ('$name', '$email', '$url', '$message', '$nav', '$gender', '$age', '$country', '$user_ip', '$user_host', current_date)"; mysql_query($query) or die('Error, query failed. ' . mysql_error()); header('Location: ' . $_SERVER['REQUEST_URI']); exit; } else { echo 'BAD'; }[/code]I'm I doing it right way?The second problem. I would like to apply this function:[code]function check_input($input, $maxlenght= 5){$temp_array = explode(" ", $input);foreach ($temp_array as $word) {if (strlen($word) > $maxlenght) {return false;}}return true;}[/code]Function is checking length of each word. If is longer I apply javascript alert.[code]if (!check_input($_POST['message'])) {print 'One of your words in your message in longer than 40 chars. Please edit your message.';}[/code]In expample "echo" is used. But the main problem is that alert isin't appearing after pushing submit button.Can someone help me?Best wishesAmy Quote Link to comment Share on other sites More sharing options...
Hypnos Posted January 6, 2007 Share Posted January 6, 2007 Personally, I would do the length check in Javascript before the submission. It's easier to implement, and you aren't risking losing what the user just typed, and the user doesn't have to go through another captcha. Quote Link to comment Share on other sites More sharing options...
Amy1980 Posted January 6, 2007 Author Share Posted January 6, 2007 Could You show me any example? Don't know JavaScript. Quote Link to comment Share on other sites More sharing options...
Amy1980 Posted January 6, 2007 Author Share Posted January 6, 2007 Anyone? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted January 6, 2007 Share Posted January 6, 2007 it is best to ensure that your php scripts validate any input - just in case someone switches off javascript!To make the alert come up all you need do is echo out the js for an alert box in the output of teh next page. If you echo it in the head section I believe the page will not open until you have clicked it. BUT agin it goes to the isue of js being on or not - why not simply echo a warning statement in teh html? that way you are sure everyone will get the same experience from your site. Quote Link to comment Share on other sites More sharing options...
Amy1980 Posted January 6, 2007 Author Share Posted January 6, 2007 [quote author=ToonMariner link=topic=121279.msg498331#msg498331 date=1168115930]it is best to ensure that your php scripts validate any input - just in case someone switches off javascript!To make the alert come up all you need do is echo out the js for an alert box in the output of teh next page. If you echo it in the head section I believe the page will not open until you have clicked it. BUT agin it goes to the isue of js being on or not - why not simply echo a warning statement in teh html? that way you are sure everyone will get the same experience from your site.[/quote]I think I made something bad. When I use [code]echo 'bad code'; [/code] for tests I get it always. Strange. Could You check my code, please? 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.