PDO. Не работает INSERT
Не вставляет =(
В таблице:
id int(11)
user_id varchar(255)
email varchar(255)
salt varchar(255)
categiry varchar(255)
Да и с чтением кажется облом. А ошибок ноль, да. Первый раз с PDO столкнулся и решил - пора! =)
/** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .php.geshi_code {font-family:monospace;} .php.geshi_code .imp {font-weight: bold; color: red;} .php.geshi_code .kw1 {color: #b1b100;} .php.geshi_code .kw2 {color: #000000; font-weight: bold;} .php.geshi_code .kw3 {color: #990000;} .php.geshi_code .co1 {color: #666666; font-style: italic;} .php.geshi_code .co2 {color: #666666; font-style: italic;} .php.geshi_code .co3 {color: #0000cc; font-style: italic;} .php.geshi_code .co4 {color: #009933; font-style: italic;} .php.geshi_code .coMULTI {color: #666666; font-style: italic;} .php.geshi_code .es0 {color: #000099; font-weight: bold;} .php.geshi_code .es1 {color: #000099; font-weight: bold;} .php.geshi_code .es2 {color: #660099; font-weight: bold;} .php.geshi_code .es3 {color: #660099; font-weight: bold;} .php.geshi_code .es4 {color: #006699; font-weight: bold;} .php.geshi_code .es5 {color: #006699; font-weight: bold; font-style: italic;} .php.geshi_code .es6 {color: #009933; font-weight: bold;} .php.geshi_code .es_h {color: #000099; font-weight: bold;} .php.geshi_code .br0 {color: #009900;} .php.geshi_code .sy0 {color: #339933;} .php.geshi_code .sy1 {color: #000000; font-weight: bold;} .php.geshi_code .st0 {color: #0000ff;} .php.geshi_code .st_h {color: #0000ff;} .php.geshi_code .nu0 {color: #cc66cc;} .php.geshi_code .nu8 {color: #208080;} .php.geshi_code .nu12 {color: #208080;} .php.geshi_code .nu19 {color:#800080;} .php.geshi_code .me1 {color: #004000;} .php.geshi_code .me2 {color: #004000;} .php.geshi_code .re0 {color: #000088;} .php.geshi_code span.xtra { display:block; }
<?php
global $db_host, $db_login, $db_pass, $db_name;
$db_host = '1111';
$db_login = '111';
$db_pass = '1111';
$db_name = '11111';
if(isset($_GET['email']) && isset($_GET['uid']))
{
$db = new PDO('mysql:host='.$db_host.';dbname='.$db_name.'', $db_login, $db_pass );
$stream = $db->prepare("SELECT email FROM `subscribe` WHERE (email) values (':email')");
$stream->bindParam(':email', $_GET['email']);
$stream->execute();
global $mailtest;
$mailtest = $stream->fetchAll();
if(count($mailtest) == 0)
{
$STH = $db->prepare("INSERT INTO subscribe (user_id, email, salt, category) values (':user_id, :email, :salt, :category')");
$STH->bindParam(':user_id', $_GET['uid']);
$STH->bindParam(':email', $_GET['email']);
$STH->bindValue(':salt', "Shinkai");
$STH->bindValue(':category', '2,4,9');
$STH->execute();
$newmail = 'true';
}
else {$newmail = 'false '.count($mailtest);}
echo $newmail;
}
else
{
echo "Please, kiss my ass :3";
}
?>
В таблице:
id int(11)
user_id varchar(255)
email varchar(255)
salt varchar(255)
categiry varchar(255)
Да и с чтением кажется облом. А ошибок ноль, да. Первый раз с PDO столкнулся и решил - пора! =)
/** * GeSHi (C) 2004 - 2007 Nigel McNie, 2007 - 2008 Benny Baumann * (http://qbnz.com/highlighter/ and http://geshi.org/) */ .php.geshi_code {font-family:monospace;} .php.geshi_code .imp {font-weight: bold; color: red;} .php.geshi_code .kw1 {color: #b1b100;} .php.geshi_code .kw2 {color: #000000; font-weight: bold;} .php.geshi_code .kw3 {color: #990000;} .php.geshi_code .co1 {color: #666666; font-style: italic;} .php.geshi_code .co2 {color: #666666; font-style: italic;} .php.geshi_code .co3 {color: #0000cc; font-style: italic;} .php.geshi_code .co4 {color: #009933; font-style: italic;} .php.geshi_code .coMULTI {color: #666666; font-style: italic;} .php.geshi_code .es0 {color: #000099; font-weight: bold;} .php.geshi_code .es1 {color: #000099; font-weight: bold;} .php.geshi_code .es2 {color: #660099; font-weight: bold;} .php.geshi_code .es3 {color: #660099; font-weight: bold;} .php.geshi_code .es4 {color: #006699; font-weight: bold;} .php.geshi_code .es5 {color: #006699; font-weight: bold; font-style: italic;} .php.geshi_code .es6 {color: #009933; font-weight: bold;} .php.geshi_code .es_h {color: #000099; font-weight: bold;} .php.geshi_code .br0 {color: #009900;} .php.geshi_code .sy0 {color: #339933;} .php.geshi_code .sy1 {color: #000000; font-weight: bold;} .php.geshi_code .st0 {color: #0000ff;} .php.geshi_code .st_h {color: #0000ff;} .php.geshi_code .nu0 {color: #cc66cc;} .php.geshi_code .nu8 {color: #208080;} .php.geshi_code .nu12 {color: #208080;} .php.geshi_code .nu19 {color:#800080;} .php.geshi_code .me1 {color: #004000;} .php.geshi_code .me2 {color: #004000;} .php.geshi_code .re0 {color: #000088;} .php.geshi_code span.xtra { display:block; }
<?php
global $db_host, $db_login, $db_pass, $db_name;
$db_host = '1111';
$db_login = '111';
$db_pass = '1111';
$db_name = '11111';
if(isset($_GET['email']) && isset($_GET['uid']))
{
$db = new PDO('mysql:host='.$db_host.';dbname='.$db_name.'', $db_login, $db_pass );
$stream = $db->prepare("SELECT email FROM `subscribe` WHERE (email) values (':email')");
$stream->bindParam(':email', $_GET['email']);
$stream->execute();
global $mailtest;
$mailtest = $stream->fetchAll();
if(count($mailtest) == 0)
{
$STH = $db->prepare("INSERT INTO subscribe (user_id, email, salt, category) values (':user_id, :email, :salt, :category')");
$STH->bindParam(':user_id', $_GET['uid']);
$STH->bindParam(':email', $_GET['email']);
$STH->bindValue(':salt', "Shinkai");
$STH->bindValue(':category', '2,4,9');
$STH->execute();
$newmail = 'true';
}
else {$newmail = 'false '.count($mailtest);}
echo $newmail;
}
else
{
echo "Please, kiss my ass :3";
}
?>
1 ответов
$stream = $db->prepare("SELECT email FROM `subscribe` WHERE email = :email");
и
$STH = $db->prepare("INSERT INTO subscribe (user_id, email, salt, category) VALUES (:user_id, :email, :salt, :category)");
И избавьтесь от global variables, как только так сразу.