i am trying to write a code for taking the input (Email) from a form and save to the database
I used ajax to save the data to the xml file instead of saving to the database .. and it worked pretty well. but using xml instead of database is not secure. the user can view the whole xml and data in it.!
so i want to take the data from form and display if the email is already available in the database.! ! i want all this to happen in the background just like AJAX .. i dont want the user to get redirected to other pages or the page to be reloaded . . i wrote a php script that checks whether the email is already in the data base.
PHP
<?php
$count=0;
$email = $_POST['subs_input'];
$con1= new PDO('mysql:host=localhost; dbname=emails' , 'root' , '');
$q = "INSERT INTO `emails`.`email` VALUES ('$email')";
$q1 = "SELECT * FROM `emails`.email`";
$result = $con1->query($q1);
while($ret = $result->fetch(PDO::FETCH_ASSOC)){
$ele = $ret['email'];
if($ele == $email){
echo "Email already exists";
$count=1;
}
}
if($count==0){
$con1->query($q);
echo"subscribed sucessfully";
}
?>
instead of echoing out the statements i can wrap them in xml content and send the responseXML to the javascript ajax. all i need to know is
if(xmlhttp.readyState == 4 || xmlhttp.readyState == 0){
xmlhttp.open("POST","../text/info.php",true);
...
...
}
how to send the email(input from html) to php from ajax request. in order to access it in php.. i know this can be done pretty easily using jquery.. but I DONT WANT TO USE JQUERY. i want to learn it the hard way.
than you in advance;
.append()for adding information) - then, when you're sending, usexmlhttp.send(<FormData Object>);On the backend, you retrieve the information via$_POST