|
lesson56
|
|
|
we will take the data from customer and insert into database and
pint what we entered
|
|
|
lesson 56
|
|
|
insertindex.php
|
|
|
<?php
|
|
|
echo rand(111,999) .'<br><br>';
|
|
|
|
|
|
?>
|
|
|
|
|
|
|
|
|
<html>
|
|
|
<head>
|
|
|
<script>
|
|
|
function showdata(){
|
|
|
if(window.XMLHttpRequest){
|
|
|
xmlhttp = new XMLHttpRequest();
|
|
|
} else{
|
|
|
xmlhttp =new ActiveXobject('Microsoft.XMLHTTP');
|
|
|
}
|
|
|
xmlhttp.onreadystatechange = function(){
|
it will get the data from data base by using get the required
page
|
|
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
|
|
|
document.getElementById('ddata').innerHTML =
xmlhttp.responseText;
|
|
|
}
|
|
|
}
|
|
|
xmlhttp.open('GET','show.php' , true);
|
show the output from show.php page
|
|
xmlhttp.send();
|
|
|
|
|
|
}
|
|
|
showdata();
|
we are calling two times, means, after refresh
|
|
function insertdata(){
|
|
|
if(window.XMLHttpRequest){xmlhttp = new XMLHttpRequest();}
|
|
|
else{xmlhttp =new ActiveXobject('Microsoft.XMLHTTP');}
|
|
|
xmlhttp.onreadystatechange = function(){
|
|
|
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
|
|
|
{document.getElementById('msg').innerHTML =
xmlhttp.responseText;
|
|
|
showdata();
|
immediately add after adding data
|
|
}
|
|
|
}
|
using this we are sending data to to the required page
|
|
|
|
|
org = 'text='+ document.getElementById('stext').value;
|
org is calling variable text, it sends the data inisde of this
|
|
<!--text is a variable and helllo is value and org is
argument -->
|
|
|
xmlhttp.open('POST', 'insert.php', true);
|
post , means we are inserting data into server
|
|
xmlhttp.setRequestHeader('content-type','application/x-www-form-urlencoded')
|
we are using with post
|
|
<!-- using post we can insert into databse, -- >
|
|
|
xmlhttp.send(org);
|
for post
|
|
|
|
|
}
|
|
|
</script>
|
|
|
</head>
|
|
|
|
|
|
<body>
|
|
|
|
|
|
Type some text: <input type ="text" id
="stext">
|
|
|
<input type="submit" onclick
="insertdata()"><br><br>
|
|
|
|
|
|
<div id="msg">
</div><!-- data is inserted or not using this div -->.
|
|
|
<div id ="ddata"></div>
|
|
|
|
|
|
|
|
|
</body>
|
|
|
</html>
|
|
|
show.php
|
|
|
<?php
|
whenever is called, data is print on that page required
|
|
|
|
|
require 'dbconnect.php';
|
dbcooenct
|
|
$query ="SELECT `data` FROM `somedata` ";
|
selct data all data inside of this table
|
|
if($query_run = mysqli_query($mycon, $query)){
|
run this query
|
|
$num_rows = mysqli_num_rows($query_run);
|
find how many rows
|
|
if ($num_rows >=1){
|
|
|
while ($row = mysqli_fetch_assoc($query_run)){
|
print that rows
|
|
echo $row['data'].'<br><br>';
|
accessing
|
|
}
|
|
|
}
|
|
|
}
|
|
|
?>
|
|
|
insert.php
|
|
|
<?php
|
|
|
require 'dbconnect.php';
|
whenever data is send form user , itw uill cehck the data is
tehre , and write query and to insert and data is insert
|
|
if (isset ($_POST['text'])){
|
|
|
$text = $_POST['text'];
|
get the data from index page
|
|
$text = mysqli_real_escape_string($mycon, $text);
|
writee into data base without comma or with esc
|
|
if(!empty($text)){
|
|
|
$query = "INSERT INTO `somedata` (`id`, `data`) VALUES
(NULL,'$text')";
|
insert into required colimn
|
|
if ($query_run = mysqli_query ($mycon, $query)){
|
create quere
|
|
echo 'data inserted succesfulluy';
|
|
|
}else {echo 'failed';}
|
|
|
}
|
|
|
else {echo 'please enter some text';}
|
|
|
|
|
|
}
|
|
|
?>
|
|
| rand |
| window.XMLHttprequest |
| new XMLHttprequest |
| new ActiveXobject('Microsoft.XMLHTTP'); |
| xmlhttp.onreadystatechange |
| lhttp.readyStat |
| responseText; |
| open |
| send |
| xmlhttprequest |
| onreadystatechange |
| readystat |
| status |
| reposetext |
| open |
| setrequestheader |
| post |
| send(arfgument) |
| query |
| select frorm |
| mysqli_query |
| mysqli_num_rows |
| mysqli_Fetch_assoc |
| $roq['data'] |
| isset |
| $_POST |
| mysqli_real_escape |
| insert into |
| query |
| mysqli_query |
| we will take the data from customer and insert into database and pint what we entered |
| how to print random number |
| how to check browser |
| how to ready to get respinse |
| how to check response is good ornot |
| how to send the reecieved data to div |
| what request have to send |
| how tos end |
| how tocheck browser |
| how toready to reciever |
| how to check what we recieverf |
| how to pprint we received |
| whats thing we have to send |
| what request we have to post |
| how to send the argument |
| if date is inserttd, it is hwos wew inserted |
No comments:
Post a Comment