Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Securing form from possible sql injection

//Using PDOStatement to protect db from sql injection
// text is the form field you are trying to protect
//We are using  $sql here as the object and joke_table is the
// name of the database table we will insert our jokes in.
//Text in here represents the database column that our users  
//input will be inserted in.

if (isset($_POST['text'])) {
   try {
        $pdo= new PDO('mysql:host=localhost;dbname=omo; chaerset=utf8','username','passwrd');
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $sql = 'INSERT INTO `joke_table` SET   
        `text` = :text, 
        `date` = CURDATE()'; 
        $stmt = $pdo->prepare($sql); 
        $stmt->bindValue(':text', $_POST['text']); 
        $stmt->execute(); 
        header('location: thank.php'); 
      } catch (PDOException $e) {
            echo 'error in connecting to the database'.$e->getMessage().'in'.$e->getFile().':'. $e->getLine(). $e->getCode();
         
    } 
    } else {
    // use any logic that you would like to happen here

    }
Comment

PREVIOUS NEXT
Code Example
Php :: laravel valet subdomain 
Php :: display php error 
Php :: laravel crud 
Php :: Laravel return empty relationship on model when condition is true 
Php :: cakephp login session 
Php :: touches in laravel 
Php :: unique validation laravel 
Php :: in date function + 1 month and - 1 day in php 
Php :: laravel creat new model 
Php :: show uploaded image in php 
Php :: laravel where and blade 
Php :: codeigniter 3 image upload 
Php :: copy file in php 
Php :: is legged in wodpress 
Php :: test php code online free 
Php :: Regex to remove span tags using php [duplicate] 
Php :: php increment variable 
Php :: woocommerce function traduccion label 
Php :: multiple ternary operator in php 
Php :: ./yii serve not working in advanced template 
Php :: hummingbird remove caching specific page php 
Php :: laravel migration drop foreign keys 
Php :: php get referrer ajax 
Php :: stampare array php foreach 
Php :: get product price by id woocommerce snippet 
Php :: laravel 7 upload file s3 
Php :: PHP sprintf — Return a formatted string 
Php :: laravel how to query belongsTo relationship 
Php :: PHP str_ends_with — Checks if a string ends with a given substring 
Php :: octobercms mail 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =