You are on page 1of 9

Web design and development

Mysql DB_insert+validation

T. Marwa Alhadi
2

2
Operations in PDO(Insertion using PDO)
<?php
session_start();
include_once('conn.php);
include_once(‘insert_desing.php’);
include_once(‘full_desing.php’);
// set the PDO error mode to exception
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(isset($_POST['submit']))
{try {$Co_name=$_POST['Co_name’];
$sql = $db->prepare("INSERT INTO collages (Co_name) VALUES
(:Co_name)");
$db->beginTransaction();
$sql->execute(array(':Co_name'=>$Co_name));
// use exec() because no results are returned
$db->exec($sql); //message for adding succesfully }
catch(PDOException $e)
{ echo $sql . "<br>" . $e->getMessage();}}
$conn = null;//}?> 3
Implementation

4
Types of Includes PHP file in a
currently running script:
◼ Include
◼ Include_once
◼ Require
◼ Require_once

5
When there is an error ….
◼ With include,
a warning is displayed and the script
continues to run.
◼ With require,
 an error is displayed and the script stops.

6
include_once and require_once
◼ include_once and require_once work
 just like include and require,
 file has already been included at least once
for the current page request
 This is handy for include files performing a
task that only needs to be done once, like
connecting to the database

7
Book check
◼ ………………..

8
Assignment
◼ Don’t forget to complete your website
◼ Next week we will have mid term exam

You might also like