Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7a3cf68

Browse files
update
1 parent ee8fcc1 commit 7a3cf68

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed

‎LESSON 11-2 - الدرس/index.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
$username = "root";
3+
$password = "";
4+
$database = new PDO("mysql:host=localhost; dbname=codershiyar;", $username, $password);
5+
$getData = $database->prepare("SELECT * FROM post ");
6+
$getData->execute();
7+
8+
var_dump($getData->errorInfo());
9+
10+
foreach ($getData as $data) {
11+
echo "<div>" . $data["content"] . "</div>";
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Coder Shiyar</title>
7+
</head>
8+
<body>
9+
10+
<script>
11+
fetch("http://localhost/server/index.php?key=12345").then(Request => Request.json()).then(data =>{
12+
console.log(data);
13+
})
14+
</script>
15+
</body>
16+
</html>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
header("Access-Control-Allow-Origin: *");
3+
header("Content-Type: application/json; charset=UTF-8");
4+
header("Access-Control-Max-Age: 3600");
5+
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
6+
7+
$username = "root";
8+
$password = "";
9+
$database = new PDO("mysql:host=localhost; dbname=codershiyar;charset=utf8;", $username, $password);
10+
11+
$items = $database->prepare("SELECT * FROM course_release_date ");
12+
$items->execute();
13+
14+
if(isset($_GET["key"])){
15+
if($_GET["key"] == "1234"){
16+
17+
$items = $items->fetchAll(PDO::FETCH_ASSOC);
18+
print_r(json_encode($items));
19+
}else{
20+
print_r(json_encode(["error" => "كلمة مرور غير صحيحة"]));
21+
}
22+
23+
}else{
24+
print_r(json_encode(["error" => "حدث خطا ما"]));
25+
}
26+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Coder Shiyar</title>
7+
</head>
8+
<body>
9+
10+
<script>
11+
var data = {text: "test from app.html" }
12+
fetch("http://localhost/server/index.php",{
13+
method : 'POST',
14+
body : JSON.stringify(data)
15+
}).then(Request => Request.json()).then(myData =>{
16+
console.log(myData);
17+
} )
18+
</script>
19+
</body>
20+
</html>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
header("Access-Control-Allow-Origin: *");
3+
header("Content-Type: application/json; charset=UTF-8");
4+
header("Access-Control-Max-Age: 3600");
5+
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
6+
header("Access-Control-Allow-Methods: POST");
7+
8+
$data = file_get_contents("php://input");
9+
$data = json_decode($data);
10+
11+
if(isset($data->text) ){
12+
$username = "root";
13+
$password = "";
14+
$database = new PDO("mysql:host=localhost; dbname=codershiyar;charset=utf8;", $username, $password);
15+
16+
$addData = $database->prepare("INSERT INTO course_release_date(text,time,date) VALUES(:text,CURRENT_TIME,CURRENT_DATE )");
17+
$addData->bindParam("text",$data->text);
18+
19+
if($addData->execute()){
20+
print_r(json_encode(["message"=>"تم اضافة البيانات بنجاح "]));
21+
}else{
22+
var_dump($addData->errorInfo());
23+
print_r(json_encode(["error"=>"حدث خطا ما "]));
24+
}
25+
26+
}else{
27+
print_r(json_encode(["error"=>"حدث خطا ما "]));
28+
}
29+
30+
31+
32+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /