CMS im making에서 데이터베이스에 제품을 추가하려고하는데, 다른 페이지에 이미지와 함께 제품을 표시하고 싶습니다.
데이터베이스에 개체를 추가하는 한 모든 것이 정상적으로 작동하지만 데이터베이스 내의 제품 ID에 따라 업로드 한 이미지의 이름이 지정되기를 원합니다. 이미지는 나중에 연결되지 않는 디렉터리에 로컬로 저장됩니다. 레코드가 데이터베이스에 추가되고 있지만 이미지 업 로더가 올바르게 작동하지 않고 양식을 제출할 때 다음 오류가 발생합니다.
내 테이블 레이아웃은 다음과 같습니다.
id l 이름 l 수량 l 설명 l 가격
1 l 키 l 5 l 무언가 잠금 해제 l 6
알림 : 정의되지 않은 변수 : 17 행의 L : \ xampp \ htdocs \ 655487 \ addSQL.php의 querynew
주의 : 정의되지 않은 변수 : L : \ xampp \ htdocs \ 655487 \ addSQL.php on line 18
경고 : mysqli :: query () : 18 행의 L : \ xampp \ htdocs \ 655487 \ addSQL.php의 빈 쿼리
주의 : 정의되지 않은 변수 : L : \ xampp \ htdocs \ 655487 \ addSQL.php on line 18
다음과 함께 제품을 제출하는 양식입니다.
<fieldset><legend><span> Add a product to the database </span></legend>
<form id ="productsform" method="post" onsubmit="return false;" enctype="multipart/form-data">
<label> Enter a product name: <input type="text" id="name" name="name"/> </label>
<label> Enter a product quantity: <input type="number" id="quantity" name="quantity"/> </label>
<label> Enter a product description: <input type="text" id="description" name="description"/> </label>
<label> Enter a product price: <input type="text" id="price" name="price"/> </label>
<label> Upload a image of the product: <input type="file" id="file1" name="file"></label>
<input id="submit" name="submit" type="button" class="reg" value="Add Product">
<div id="status"></div>
여기에 스크립트 addSQL.php가 있습니다.
<?php
include("dbase/config_database.php");
//Stores all information passed through AJAX into the query
$name = $_POST['name'];
$quantity = $_POST['quantity'];
$description = $_POST['description'];
$price = $_POST['price'];
//Adds information to database
$query = "INSERT INTO products (name, quantity, description, price) VALUES ('$name','$quantity','$description','$price')";
//Runs the query
$result = $mysqli->query($query) OR die("Failed query $query");
echo $mysqli->error."<p>";
$querynew - ("SELECT id as 'collectid' from products WHERE name = '$name'and quantity = '$quantity'and description ='$description'and price = '$price'");
$resultnew = $mysqli->query($querynew) OR die("Failed query $querynew");
while($info = mysqli_fetch_array( $resultnew)){
$productid = $info['collectid'];
}
$image = $_FILES['file1']['name'];
$type = $_FILES['file1']['type'];
$size = $_FILES['file1']['size'];
$tmp_name = $_FILES['file1']['tmp_name'];
$imgpath = "images/".$productid.".jpg";
// Run the move_uploaded_file() function here
$moveResult = move_uploaded_file($tmp_name, $imgpath);
// Evaluate the value returned from the function if needed
$querytwo = ("SELECT * FROM products WHERE name = '$name' and quantity = '$quantity' and description = '$description' and price = '$price'");
$resulttwo = $mysqli ->query($querytwo) OR die ("Failed query $querynew");
$info = array();
while($row = mysqli_fetch_assoc($resulttwo)){
$product = array("id" => $row ['id'],
"name" => $row ['name'],
"quantity" => $row ['quantity'],
"description" => $row ['description'],
"price" => $row ['price'],
);
array_push($info,$product);
}
$json_output = json_encode($info);
echo $json_output;
?>
Anyhelp 대단히 감사하겠습니다!
오타가 있습니다. 알아 차린 것 외에는 스크립트를 테스트하지 않았습니다.
$ querynew-( "SELECT id as 'collectid ....
해야한다
$ querynew = ( "SELECT id as 'collectid ...
이것이 당신의 오류입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다