我正在嘗試管理面板的工作。我下載了這個例子管理面板設計:http://medialoot.com/item/html5-admin-template/PHP MySQL插入到GET方法
HTML結構:http://pastebin.ubuntu.com/5940949/
我試過PHP代碼,
<?php
if(isset($_GET['submit'])){
if($_FILES["carImage"]["error"] > 0){
echo '<script type="text/javascript">alert('."File not upload" . $_FILES["carImage"]["error"].');</script>';
}else{
if(!is_dir("../inc/imj/cars")){
mkdir("../inc/imj/cars");
}
$carImage_ = "../inc/imj/cars".$_FILES["carImage"]["name"];
move_uploaded_file($_FILES["carImage"]["tmp_name"],$carImage_);
mysql_query("
INSERT INTO contents ('indexId','catId','carModelName','carCash','carImage','carAlt','carTitle','carKMH','carWeight','carWheelInch','carColur','info')
VALUES (NULL,'".$_GET['catId']."','".$_GET['carModelName']."','".$_GET['carCash']."','".$carImage_."','".$_GET['carAlt']."','".$_GET['carTitle']."','".$_GET['carKMH']."','".$_GET['carWeight']."','".$_GET['carWheelInch']."','".$_GET['carColur']."','".$_GET['info']."')
");
}
}
?>
我試圖替代查詢代碼,
mysql_query("
INSERT INTO contents ('indexId','catId','carModelName','carCash','carImage','carAlt','carTitle','carKMH','carWeight','carWheelInch','carColur','info')
VALUES (NULL,".$_GET['catId'].",".$_GET['carModelName'].",".$_GET['carCash'].",".$carImage_.",".$_GET['carAlt'].",".$_GET['carTitle'].",".$_GET['carKMH'].",".$_GET['carWeight'].",".$_GET['carWheelInch'].",".$_GET['carColur'].",".$_GET['info'].")
");
我猜的文件不上傳。所以不行。
因爲錯誤;
注意:未定義指數:carImage在..
注意:未定義指數:更多資料在..
注:表contents.indexId是主鍵和自動遞增。
如何解決纔好呢?
感謝您的關注。
UPDATE
圖片上傳的問題是;
<?php
$catId = isset($_GET['catId']) ? $_GET['catId'] : "";
$carModelName = isset($_GET['carModelName']) ? $_GET['carModelName'] : "";
$carCash = isset($_GET['carCash']) ? $_GET['carCash'] : "";
$carAlt = isset($_GET['carAlt']) ? $_GET['carAlt'] : "";
$carTitle = isset($_GET['carTitle']) ? $_GET['carTitle'] : "";
$carKMH = isset($_GET['carKMH']) ? $_GET['carKMH'] : "";
$carWeight = isset($_GET['carWeight']) ? $_GET['carWeight'] : "";
$carWheelInch = isset($_GET['carWheelInch']) ? $_GET['carWheelInch'] : "";
$carColur = isset($_GET['carColur']) ? $_GET['carColur'] : "";
$info = isset($_GET['info']) ? $_GET['info'] : "";
if(isset($_GET['submit'])){
if($_FILES["carImage"]["error"] > 0){
echo '<script type="text/javascript">alert('."File not upload" . $_FILES["carImage"]["error"].');</script>';
}else{
$carUrl_ = "../inc/imj/urun";
if(!is_dir($carUrl_)){mkdir($carUrl_);}
$carImage_ = $carUrl_.$_FILES["carImage"]["name"];
$carUrlName = $_FILES["carImage"]["name"];
move_uploaded_file($_FILES["carImage"]["tmp_name"],$carImage_);
mysql_query("
INSERT INTO contents ('indexId','catId','carModelName','carCash','carImage','carAlt','carTitle','carKMH','carWeight','carWheelInch','carColur','info')
VALUES (".$catId.",".$_GET['carModelName'].",".$_GET['carCash'].",".$carUrlName.",".$carAlt.",".$carTitle.",".$carKMH.",".$carWeight.",".$carWheelInch.",".$carColur.",".$info.")
");
}
}
?>
更新2
<?php
$catId = isset($_GET['catId']) ? $_GET['catId'] : "";
$carModelName = isset($_GET['carModelName']) ? $_GET['carModelName'] : "";
$carCash = isset($_GET['carCash']) ? $_GET['carCash'] : "";
$carAlt = isset($_GET['carAlt']) ? $_GET['carAlt'] : "";
$carTitle = isset($_GET['carTitle']) ? $_GET['carTitle'] : "";
$carKMH = isset($_GET['carKMH']) ? $_GET['carKMH'] : "";
$carWeight = isset($_GET['carWeight']) ? $_GET['carWeight'] : "";
$carWheelInch = isset($_GET['carWheelInch']) ? $_GET['carWheelInch'] : "";
$carColur = isset($_GET['carColur']) ? $_GET['carColur'] : "";
$info = isset($_GET['info']) ? $_GET['info'] : "";
if(isset($_GET['submit'])){
mysql_query("
INSERT INTO contents ('indexId','catId','carModelName','carCash','carImage','carAlt','carTitle','carKMH','carWeight','carWheelInch','carColur','info')
VALUES (".$catId.",".$_GET['carModelName'].",".$_GET['carCash'].",tryImg.png,".$carAlt.",".$carTitle.",".$carKMH.",".$carWeight.",".$carWheelInch.",".$carColur.",".$info.")
");
}
?>
我認爲你最好在這裏使用POST代替GET。你嘗試過嗎? – Maximus2012
另外,你確定錯誤是在MySQL查詢?錯誤可能在代碼的其他部分嗎? – Maximus2012
我不能使用INSERT INTO方法將行添加到表中。 – fthmad9