Vegard Berg
Vegard Berg

Reputation: 79

MySQL returns always Error

I have a check for max letters. If the check is not true the first time, its working. But if i have a insert with 200 characters or more it always returns Message cant have more than 200 characters. Even with 10 characters after the test return error. Can't see what I'm doing wrong.

<?php
$stripped = mysql_real_escape_string($_GET['id']);
$id = mysql_real_escape_string($_GET['id']);
$message = mysql_real_escape_string($_POST['message']);
$aktiv = mysql_real_escape_string($_POST['aktiv']);

if (isset($_POST['sendmsg'])) {
  if ($_POST['message'] < 200) {        
    echo "Message can't be more than 200 characters";
  } else {
    $result = mysql_query("UPDATE cms_prosjekt SET message = '$message',  active_msg = '$aktiv' WHERE id = $stripped;");

    header('Location: Location: /index.php?url=projectedit&id='.$stripped.'&code='.$id.'');
    exit;
  }
}
?>

Upvotes: 0

Views: 64

Answers (2)

nospor
nospor

Reputation: 4220

This is not mysql error but your php validation error

1) More than 200 is >200 not <200

2) You need to check length of text not text

if (strlen($_POST['message']) > 200)
{       

     echo "Message can't be more than 200 characters";

}

Upvotes: 4

Zenel Rrushi
Zenel Rrushi

Reputation: 2366

The problem is in ($_POST['message'] < 200) you should do it (strlen($_POST['message']) > 200)

At least that is the message that you display when the message is longer than 200.

Upvotes: 2

Related Questions