Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Projet_idaw
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Liang Wu
Projet_idaw
Commits
84db5bf3
Commit
84db5bf3
authored
Apr 03, 2020
by
Raulin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
aliments complet (crud)
parent
ede81403
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
89 additions
and
20 deletions
+89
-20
.DS_Store
.DS_Store
+0
-0
aliments.php
aliments.php
+45
-13
ajouter_aliment.php
api/ajouter_aliment.php
+21
-7
delete_aliment.php
api/delete_aliment.php
+11
-0
modifier_aliment.php
api/modifier_aliment.php
+12
-0
No files found.
.DS_Store
View file @
84db5bf3
No preview for this file type
aliments.php
View file @
84db5bf3
...
@@ -7,32 +7,57 @@
...
@@ -7,32 +7,57 @@
<script
type=
"text/javascript"
>
<script
type=
"text/javascript"
>
$
(
document
).
ready
(
function
()
{
$
(
document
).
ready
(
function
()
{
$
(
'#table_aliments'
).
DataTable
();
$
(
'#table_aliments'
).
DataTable
();
resetForm
();
}
);
}
);
function
resetForm
()
{
document
.
getElementById
(
"id"
).
value
=
""
document
.
getElementById
(
"aliment"
).
value
=
""
;
document
.
getElementById
(
"cat"
).
value
=
""
;
document
.
getElementById
(
"submit_button"
).
value
=
"Ajouter"
;
};
</script>
</script>
<script
type=
"text/javascript"
>
<script
type=
"text/javascript"
>
$
(
document
).
ready
(
function
()
{
$
(
document
).
ready
(
function
()
{
$
.
getJSON
(
'https://eden.imt-lille-douai.fr/~charlotte.raulin/Projet/api/afficher_aliments.php'
,
$
.
getJSON
(
'https://eden.imt-lille-douai.fr/~charlotte.raulin/Projet/api/afficher_aliments.php'
,
function
(
json
){
function
(
json
){
// console.log(json);
table
=
$
(
'#tbody_aliment'
);
table
=
$
(
'#tbody_aliment'
);
table
.
html
(
''
);
table
.
html
(
''
);
// cf. https://api.jquery.com/jQuery.getJSON/
// cf. https://api.jquery.com/jQuery.getJSON/
$
.
each
(
json
,
function
(
key
,
val
)
{
$
.
each
(
json
,
function
(
key
,
val
)
{
table
.
append
(
'<tr><td>'
+
val
[
1
]
+
'</td><td>'
+
val
[
2
]
+
'</td></tr>'
);
// table.append('
<
tr
><
td
>
'+val[0]+'
<
/td><td>'+val
[
1
]
+'</
td
><
td
>
'+val[2]+'
<
/td><td><button '
+
// 'onclick="onEdit('+val[0]+',\''+val[1]+'\',\''+val[2]+'\')">Modifier
<
/button></
td
><
/tr>'
)
;
table
.
append
(
'<tr><td>'
+
val
[
0
]
+
'</td><td>'
+
val
[
1
]
+
'</td><td>'
+
val
[
2
]
+
'</td><td><button '
+
'onclick="onEdit('
+
val
[
0
]
+
',
\'
'
+
val
[
1
]
+
'
\'
,
\'
'
+
val
[
2
]
+
'
\'
)">Modifier</button></td><td><button '
+
'onclick="onDelete('
+
val
[
0
]
+
')">Supprimer</button></td></tr>'
);
});
});
}
}
);
);
});
// $.getJSON('https://eden.imt-lille-douai.fr/~charlotte.raulin/Projet/api/afficher_aliments.php',
function
onEdit
(
id
,
nom
,
type
)
{
// function(json){
document
.
getElementById
(
"id"
).
value
=
id
;
// $.('#tbody_aliment').html('');
document
.
getElementById
(
"aliment"
).
value
=
nom
;
// for (let i = 1; i
<
json
.
lenght
;
i
++
){
document
.
getElementById
(
"cat"
).
value
=
type
;
// $('#tbody_aliment').append('
<
tr
><
td
>
'json[i][1]+'
<
/td><td>'+json
[
i
][
2
]
+'</
td
><
/tr>'
)
;
document
.
getElementById
(
"submit_button"
).
value
=
'Modifier'
;
// }
};
// };
function
onDelete
(
id
){
// );
var
varID
=
id
;
$
.
ajax
({
url
:
'api/delete_aliment.php'
,
type
:
'POST'
,
data
:
{
'varID'
:
varID
},
success
:
function
(
varID
)
{
alert
(
varID
);
// reponse contient l'affichage du fichier PHP (soit echo)
}
});
});
location
.
reload
();
}
</script>
</script>
</head>
</head>
...
@@ -43,9 +68,12 @@
...
@@ -43,9 +68,12 @@
<thead>
<thead>
<tr>
<tr>
<th>
ID
</th>
<th>
Aliment
</th>
<th>
Aliment
</th>
<th>
Type
</th>
<th>
Type
</th>
<th>
AjoutAuJournal
</th>
<th>
Modifier
</th>
<th>
Supprimer
</th>
<th>
Ajouter au Journal
</th>
</tr>
</tr>
</thead>
</thead>
<tbody
id=
"tbody_aliment"
><tbody>
<tbody
id=
"tbody_aliment"
><tbody>
...
@@ -58,6 +86,9 @@
...
@@ -58,6 +86,9 @@
<tr>
<tr>
<td>
<td>
<form
id=
"form_aliment"
action=
"api/ajouter_aliment.php"
method=
"POST"
>
<form
id=
"form_aliment"
action=
"api/ajouter_aliment.php"
method=
"POST"
>
<div>
<input
type=
"text"
id=
"id"
name=
"id"
style=
"display : none"
>
</div>
<div>
<div>
<label>
Aliment
</label>
<label>
Aliment
</label>
<input
type=
"text"
id=
"aliment"
name=
"aliment"
required
>
<input
type=
"text"
id=
"aliment"
name=
"aliment"
required
>
...
@@ -72,7 +103,8 @@
...
@@ -72,7 +103,8 @@
</div>
</div>
<div
class=
"form-action-buttons"
>
<div
class=
"form-action-buttons"
>
<input
type=
"submit"
value=
"Ajouter"
>
<input
type=
"submit"
value=
"Ajouter"
id=
'submit_button'
>
</div>
</div>
</form>
</form>
</td>
</td>
...
...
api/ajouter_aliment.php
View file @
84db5bf3
<?php
<?php
require_once
(
"template.php"
);
require_once
(
"template.php"
);
if
(
isset
(
$_POST
[
"aliment"
])
&&
isset
(
$_POST
[
"cat"
])){
if
(
isset
(
$_POST
[
'id'
])
&&
$_POST
[
'id'
]
!=
""
){
//si l'id est renseigné il s'agit d'une modification
if
(
isset
(
$_POST
[
"aliment"
])
&&
isset
(
$_POST
[
"cat"
])){
$requete
=
"UPDATE `ALIMENTS` SET `NAME_ALIMENT` = '"
.
$_POST
[
'aliment'
]
.
"', `TYPE_ALIMENT` = '"
.
$_POST
[
'cat'
]
.
"' WHERE `ALIMENTS`.`ID_ALIMENT` = "
.
$_POST
[
'id'
];
$mysqli
->
query
(
$requete
);
$msg
=
"L'aliment a bien été modifié"
;
}
else
{
$msg
=
"Il manque des informations"
;
}
}
else
{
//sinon il s'agit d'un ajout
if
(
isset
(
$_POST
[
"aliment"
])
&&
isset
(
$_POST
[
"cat"
])){
$requete
=
"INSERT INTO `ALIMENTS` (`ID_ALIMENT`,`NAME_ALIMENT`, `TYPE_ALIMENT`) VALUES (NULL, '"
.
$_POST
[
'aliment'
]
.
"', '"
.
$_POST
[
'cat'
]
.
"')"
;
$requete
=
"INSERT INTO `ALIMENTS` (`ID_ALIMENT`,`NAME_ALIMENT`, `TYPE_ALIMENT`) VALUES (NULL, '"
.
$_POST
[
'aliment'
]
.
"', '"
.
$_POST
[
'cat'
]
.
"')"
;
$mysqli
->
query
(
$requete
);
$mysqli
->
query
(
$requete
);
$msg
=
"L'aliment a bien été ajouté"
;
$msg
=
"L'aliment a bien été ajouté"
;
}
else
{
}
else
{
$msg
=
"Il manque des informations"
;
$msg
=
"Il manque des informations"
;
}
}
}
echo
$msg
;
echo
$msg
;
api/delete_aliment.php
0 → 100644
View file @
84db5bf3
<?php
require_once
(
"template.php"
);
$requete
=
"DELETE FROM `ALIMENTS` WHERE `ALIMENTS`.`ID_ALIMENT` = "
.
$_POST
[
'varID'
];
$mysqli
->
query
(
$requete
);
$msg
=
"L'aliment a été supprimé"
;
echo
$msg
;
api/modifier_aliment.php
0 → 100644
View file @
84db5bf3
<?php
require_once
(
"template.php"
);
if
(
isset
(
$_POST
[
"Id"
])
&&
isset
(
$_POST
[
"aliment"
])
&&
isset
(
$_POST
[
"cat"
])){
$requete
=
"UPDATE `ALIMENTS` SET `NAME_ALIMENT` = '"
.
$_POST
[
'aliment'
]
.
"', `TYPE_ALIMENT` = '"
.
$_POST
[
'cat'
]
.
"' WHERE `ALIMENTS`.`ID_ALIMENT` = 23"
;
$mysqli
->
query
(
$requete
);
$msg
=
"L'aliment a bien été modifié"
;
}
else
{
$msg
=
"Il manque des informations"
;
}
echo
$msg
;
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment