Created
March 9, 2017 07:46
-
-
Save Mauryashubham/262c15062f54daf2dc7721ea34a6bc6e to your computer and use it in GitHub Desktop.
Add Form Data in Database Using JavaScript in PHP (By Using HTML INNER values)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
@author : Shubham Maurya, | |
Email id : [email protected] | |
**/ | |
//connect to mysql database | |
$con = mysqli_connect("localhost", "root", "", "test") or die("Error " . mysqli_error($con)); | |
if(isset($_POST['verify']) && isset($_POST['verify1']) && isset($_POST['verify2'])) | |
{ | |
$name=$_POST['verify']; | |
$pass=$_POST['verify1']; | |
$mob=$_POST['verify2']; | |
//Insert | |
$q="INSERT INTO register(name,password,mobile) VALUES('".$name."','".$pass."','".$mob."')"; | |
if(mysqli_query($con, $q)) | |
{ | |
echo "Done"; | |
} | |
else | |
{ | |
echo "Not"; | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hi all , Welcome to Maurya Tricks , Today we are going to discuss , How to Add Form Data in Database Using JavaScript in PHP (By Using HTML INNER values) | |
1.Make a Database names "test" and make a table named "register" as given below | |
CREATE TABLE `register` ( | |
`id` int(11) NOT NULL, | |
`name` text NOT NULL, | |
`password` varchar(255) NOT NULL, | |
`mobile` bigint(20) NOT NULL | |
) ENGINE=InnoDB DEFAULT CHARSET=latin1; | |
OR make your own table | |
2.Make a file in notepad and save it as index.php and paste the below code. | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Read Data Using JavaScript</title> | |
<script type="text/javascript"> | |
//Submit Values using ajax | |
function done() | |
{ | |
var html1=document.getElementById("verify_status").innerHTML; | |
var html2=document.getElementById("verify_status1").innerHTML; | |
var html3=document.getElementById("verify_status2").innerHTML; | |
if((html1) && (html2) && (html3) ) | |
{ | |
$.ajax({ | |
type: 'post', | |
url: 'ajax.php', | |
data: { | |
verify:html1, | |
verify1:html2, | |
verify2:html3, | |
}, | |
success: function (response) { | |
$( '#status' ).html(response); | |
if(response=="Done") | |
{ | |
var elem=document.getElementById("status"); | |
elem.style.color = "#8a6d3b"; | |
return true; | |
} | |
else | |
{ | |
var elem=document.getElementById("status"); | |
elem.style.color = "green"; | |
return false; | |
} | |
} | |
}); | |
} | |
{ | |
$( '#status' ).html('Problem'); | |
return false; | |
} | |
} | |
//Give Values To Span | |
function done1() | |
{ | |
$( '#verify_status' ).html('Shubham'); | |
$( '#verify_status1' ).html('Shubham'); | |
$( '#verify_status2' ).html('9818'); | |
} | |
</script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | |
</head> | |
<body> | |
<!-- Get Values --> | |
<input type="button" name="done1" onclick="done1();" value="click To Get Values"><br> <!--Click To Assign Values --> | |
<span id="verify_status" style="color: red;font-size: 12px"></span><br><br> | |
<span id="verify_status1" style="color: red;font-size: 12px"></span><br><br> | |
<span id="verify_status2" style="color: red;font-size: 12px"></span><br><br> | |
<!-- Submit Values --> | |
<input type="button" name="done" onclick="done();" value="Submit Values"> <!--Click To Submit Values --> | |
<span id="status" style="color: red;font-size: 12px"></span><br> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment