所以,這裏是我使用MySQL查詢不使用PHP的工作,但在查詢的phpmyadmin的SQL運行
<form action="upload.php" method="post" enctype="multipart/form-data">
<table border="2px">
<tr>
<td>Date</td>
<td>Day</td>
<td>Height</td>
<td>Weight</td>
<td>Biceps(Open)</td>
<td>Biceps(Curled)</td>
<td>Photo</td>
<td>Action</td>
</tr>
<tr>
<td><input type="date" name = "date"></td>
<td><select name="day">
<?php for ($x = 1; $x <= 100; $x++) { ?>
<option>
<?php echo $x;
} ?></option>
</select>
</td>
<td><select name="height">
<?php for ($x = 170; $x <= 180; $x++) { ?>
<option>
<?php echo $x;
} ?></option>
</select> Centimeters
</td>
<td><select name="weight">
<?php for ($x = 60; $x <= 80; $x++) { ?>
<option>
<?php echo $x;
} ?></option>
</select> Kilograms
</td>
<td><select name="biceps_o">
<?php for ($x = 10; $x <= 15; $x++) { ?>
<option>
<?php echo $x;
} ?></option>
</select> Inches
</td>
<td><select name="biceps_c">
<?php for ($x = 10; $x <= 15; $x++) { ?>
<option>
<?php echo $x;
} ?></option>
</select> Inches
</td>
Select image to upload:
<td><input type="file" name="fileToUpload" id="fileToUpload"></td>
<td><input type="submit" value="Add" name="submit"></td>
</tr>
</table>
</form>
這裏的HTML表單的upload.php的文件
<?php
$target_dir = "images/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif") {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
$date = $_POST['date'];
$day = $_POST['day'];
$height = $_POST['height'];
$weight = $_POST['weight'];
$biceps_o = $_POST['biceps_o'];
$biceps_c = $_POST['biceps_c'];
echo $sql_query = "INSERT INTO gym (date, day, height, weight, biceps_o, biceps_c, image) VALUES('$date', '$day', '$height', '$weight', '$biceps_o', '$biceps_c', '$target_file')";
if($sql_result = mysql_query($sql_query))
echo "Data Successfully Added!";
else
echo "Data Entry Failed!";
?>
但是當我運行的代碼並上傳我的數據它提供了以下
文件是圖像 - 圖像/ jpeg.The文件 aid62387-728px交你的眼s-Step-2.jpg已上傳.INSERT INTO健身房(日期,日期,身高,體重,biceps_o,biceps_c,圖片) VALUES('2016-08-15','1','170',' 60','10','10', 'images/aid62387-728px-Cross-Your-Eyes-Step-2.jpg')數據輸入失敗!
好吧,圖像上傳完美,但查詢運行不正常。 但相同的查詢
INSERT INTO健身房(日期,星期,身高,體重,biceps_o,biceps_c,圖像) VALUES( '2016年8月15日', '1', '170','60 」, '10', '10', '圖像/ aid62387-728px交你,眼睛步-2.JPG')
工作完全正常,當我在phpMyAdmin的SQL運行它。可能是什麼問題?
使用mysql_error找出什麼是發生 – Jens
** **停止使用deprected'mysql_ *'API。在準備好的語句中使用'mysqli_ *'或'PDO',以防止SQL注入 – Jens
你的mysql連接在哪裏? – Rijin