这次我又回来了另一个问题。解决了解析后的问题。我似乎无法使用我的sql语句上传我的数据库,其中一些看起来非常错误。我在网上搜索了5天但无济于事。
我想更新数据库表。使用where子句。 where子句将使用下拉列表中的选定值。
以下是我的编码:
Edit.php
<!DOCTYPE HTML>
<html><meta charset="ISO-8859-1">
<head>
<title>Kinder App - Edit</title>
</head>
<style> body {background-image: url("/KinderApp/images/Untitled-1.png"); background-repeat: no-repeat;}]
header {color:black; background-color:white;}
footer {color:green; background-color:lightgrey; }
h1 {font-family:Comic Sans, Comic Sans MS, cursive; font-size:50px; }
h6 {font-family:Comic Sans, Comic Sans MS, cursive; font-size:15px; color: red; font-weight:bold; }
span {font-family:Comic Sans, Comic Sans MS, cursive; font-size: 15px; color:blue; }
</style>
<link href="general.css" type="text/css" rel="stylesheet" />
<script src="dropzone.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
function display_c(){
var refresh=1000; // Refresh rate in milli seconds
mytime=setTimeout('display_ct()',refresh)
}
function display_ct() {
var strcount
var x = new Date()
document.getElementById('ct').innerHTML = x;
tt=display_c();
}
function showModule(str)
{
if (str=="")
{
document.getElementById("id").value="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var data = JSON.parse(xmlhttp.responseText);
{
for(var i=0;i<data.length;i++) {
document.getElementById("name").value = data[i].mname;
document.getElementById("desc").value = data[i].mdesc;
document.getElementById("icon").value = data[i].micon;
document.getElementById("vers").value = data[i].mvers;
document.getElementById("loca").value = data[i].mloca;
}
}
}
}
xmlhttp.open("GET","getmodule.php?q="+str,true);
xmlhttp.send();
}
function editModule(str)
{
if (str=="")
{
document.getElementById("id").value="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var data = JSON.parse(xmlhttp.responseText);
{
for(var i=0;i<data.length;i++) {
document.getElementById("name").value = data[i].mname;
document.getElementById("desc").value = data[i].mdesc;
document.getElementById("icon").value = data[i].micon;
document.getElementById("vers").value = data[i].mvers;
document.getElementById("loca").value = data[i].mloca;
}
}
}
}
xmlhttp.open("POST","edit_file.php?q="+str,true);
xmlhttp.send();
}
</script>
<body onload=display_ct();>
<center><header>Kinder App</header></center>
<br>
<center><h1>Edit</h1></center>
<br>
<form action="edit_file.php" class="dropzone"><center><h2>Drag and Drop to upload</h2>
<br><h6>WARNING: uploading files with the same file name will oveerwrite the uploaded one.</h6></center></form>
<form action="edit_file.php" method="POST">
<center><table border="1" width="50%">
<tr>
<td><center>Module ID:</center></td>
<td><center>
<select id="id" name="mID" class="quform-tooltip chosen-select" onchange="showModule(this.value)">";
<?php
define("DB_USER", "root");
define("DB_PASSWORD", "");
define("DB_HOST", "localhost");
define("DB_NAME", "kp2admin");
//echo '<select name="mID">';
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$result = mysqli_query($dbc, "SELECT Module_ID FROM module ORDER BY Module_ID");
if ($result != null) {
echo '<option value="" selected>Select</option>';
$num_results = mysqli_num_rows($result);
for ($i=0; $i<$num_results; $i++) {
$row = mysqli_fetch_array($result);
$mId = $row['Module_ID'];
echo '<option value="' .$mId. '">' .$mId. '</option>';
}
//echo '</select>';
}
mysqli_close($dbc);
?>
</select>
</center></td>
</tr>
<tr>
<td><center>Module Name:</center></td>
<td><center><input type="text" id="name" name="mName"/></center></td></tr>
<tr>
<td><center>Description:</center></td>
<td><center><input type="text" id="desc" name="mDesc"/></center></td>
</tr>
<tr>
<td><center>Icon:</center></td>
<td><center><input type="text" id="icon" name="icon"/></center></td>
</tr>
<tr>
<td><center>Version:</center></td>
<td><center><input type="text" id="vers" name="mVersion"/></center></td>
</tr>
<tr>
<td><center>Location:</center></td>
<td><center><input type="text" id="loca" name="mLocate"/></center></td>
</tr>
</table>
</center>
<center><input type="submit" value="Update Details"></center>
</form>
<p><center><a href="list_modules.php">See all files</a></center></p>
<p align="right"><b><span id='ct' ></span></b></p>
<p id="demo"></p>
<form name="myform" action="KinderAppAdmin.html" method="POST">
<input type="image" src="/KinderApp/images/sds.png" name="image" width="61" height="49">
</form>
<footer><center>Copyright © All Rights Reserved</center></footer>
</body>
</html>
&#13;
edit_file.php:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Kinder App Login - Administrator</title>
</head>
<style>
body {background-image: url("/KinderApp/images/Untitled-1.png"); background-repeat: no-repeat;}]
header {color:black; background-color:white;}
footer {color:green; background-color:lightgrey; }
h1 {font-family:Comic Sans, Comic Sans MS, cursive; font-size:50px; }
span {font-family:Comic Sans, Comic Sans MS, cursive; font-size: 15px; color:blue; }
div {font-family:Comic Sans, Comic Sans MS, cursive; font-size: 15px; color:blue; }
table, th, td {border: 0px solid black; border-collapse: collapse;}
</style>
<script type="text/javascript">
function display_c(){
var refresh=1000; // Refresh rate in milli seconds
mytime=setTimeout('display_ct()',refresh)
}
function display_ct() {
var strcount
var x = new Date()
document.getElementById('ct').innerHTML = x;
tt=display_c();
}
</script>
<body onload=display_ct();>
<center><header>Kinder App</header></center>
<br>
<center><h1>Kinder App - Add Details</h1></center>
<?php
$ds = DIRECTORY_SEPARATOR; //1
$storeFolder = 'uploads'; //2
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name']; //3
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds; //4
$targetFile = $targetPath. $_FILES['file']['name']; //5
move_uploaded_file($tempFile,$targetFile); //6
}
define ("DB_USER", "root");
define ("DB_PASSWORD", "");
define ("DB_HOST", "localhost");
define ("DB_NAME", "kp2admin");
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$moduleId=$_POST["mID"];
$moduleName=$_POST["mName"];
$description=$_POST["mDesc"];
$icon=$_POST["icon"];
$version=$_POST["mVersion"];
$location=$_POST["mLocate"];
$sql = "UPDATE module SET 'Module_Name' = '".$moduleName."', 'Description' = '".$description."', 'Icon' = ".$icon.",
'Version' = ".$version.", 'Location' = '".$location."'
WHERE Module_ID LIKE '".$moduleId."'" ;
echo "<center><div><b>Details Updated.</b></div></center>";
mysqli_query($dbc, $sql);
mysqli_close($dbc);
?>
<form name="myform" action="KinderAppAdmin.html" method="POST">
<input type="image" src="/KinderApp/images/sds.png" name="image" width="61" height="49">
</form>
<p align="right"><b><span id='ct' ></span></b></p>
<footer><center>Copyright © All Rights Reserved</center></footer>
</body>
</html>
&#13;