Jump to content

[SOLVED] Some problems. Need Help.


Amy1980

Recommended Posts

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 wishes
Amy
Link to comment
https://forums.phpfreaks.com/topic/33122-solved-some-problems-need-help/
Share on other sites

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 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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.