Jump to content

PHP Validation

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Alex_j

Alex_j

    Newbie

  • Members
  • PipPip
  • 29 posts
Hi, I need to validate this code, how can i do this? What sort of things should I include and how? Also what would be better client side first then server side?

<?php

        $con = mysql_connect("localhost","db","password");
        if (!$con)
          {
          die('Could not connect: ' . mysql_error());
          }

        mysql_select_db("db", $con);

        
        
        
        $sql="INSERT INTO Users (FirstName, Surname, Email)
        VALUES
        ('$_POST[firstname]','$_POST[surname]','$_POST[email]')";

        if (!mysql_query($sql,$con))
          {
          die('Error: ' . mysql_error());
          }
          
        
        
        //Email Stuff

    
$email = $_REQUEST['email'];
$firstName=$_REQUEST['firstName'];
$surname=$_REQUEST['surname'];
$headers="From: Someone";
$subject = "Registration";
$message = "Dear $firstName, your registration is now complete.";
    mail($email,$subject,$message,$headers);    
        
    if (mail($email,$subject,$message,$headers))
{
        header("Location: ../confirm.html");
    }
    else
    {
    echo 'Error';

}


}

?>


#2
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
You mean you want to validate the user input? In that case you need to use PHP patterns.

#3
Programnnd

Programnnd

    Newbie

  • Members
  • Pip
  • 4 posts
I did not understand what the problem here.
Rupert again I'd be happy if I can to help you effectively

#4
SoN9ne

SoN9ne

    Programmer

  • Members
  • PipPipPipPip
  • 129 posts
You will need to validate the users input and make sure it is valid. You will need to run your checks on the $_POST. You are open to SQL injection so use real_escape_string. You should not use $_REQUEST....

To validate the user input I would suggest you use PHP: filter_var - Manual as it is more efficient than creating your own.

Does this cover your question?
"Life would be so much easier if we only had the source code."