php - From SQL select to PDO -


my previous sql select code worked ajax request, want convert pdo statements.

javascript

$.ajax({       type: "post",       url: "ajax.php",       data: "mail="+ mail,       success: function(msg){       if(msg == 'mail in use'){     ....   

ajax.php

$dsn = "mysql:host=localhost;dbname=vedic;charset=utf8"; $opt = array(     pdo::attr_errmode            => pdo::errmode_exception,     pdo::attr_default_fetch_mode => pdo::fetch_assoc ); $pdo = new pdo($dsn,'root','', $opt);  if(isset($_post['mail'])){ $mail = $_post['mail'];  $stm = $pdo->prepare("select id members email='$mail'"); $stm->execute(array($id)); $name = $stm->fetchcolumn(); 

what now? how can result can use in ajax?

you supposed understand reading, not copy-paste it.
have read:

using prepared statements main reason use pdo.
every dynamic data literal has represented in query either name (:name) or regular placeholder (?).

but did do? kept data inserted in query directly:

$stm = $pdo->prepare("select id members email='$mail'"); 

why not make code using placeholder?

and ?

fix code make sensible , working.

how can result can use in ajax?

the code posted already supposed take desired value, can use anywhere wish.

please take little time investigating code, playing it, making familiar it. bear in mind site not free coding service. code answer not have working out of box. answer supposed give idea, not job.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -