将图像上传到MySQL并检索每个表单的正确图像

时间:2015-05-26 14:34:36

标签: php html mysql html5

我必须重新解释他们说的情况。

我的html表单:

<!DOCTYPE html>
<html>
     <link rel="stylesheet" type="text/css" href="carform.css"/>
<head>
</head>
<body>

<form action="connection.php" method="post" class="smart-green">
<h1> Car listing
 <span>Please fill all the text in the fields.</span>
 </h1>
<label>
<span>Make:</span>
<select id="category">
 <option value="Alfa Romeo">Alfa Romeo</option>
 <option value="Aston Martin">Aston Martin</option>
 <option value="Audi">Audi</option>
 <option value="Austin">Austin</option>
 <option value="Bentley">Bentley</option>
 <option value="BMW">BMW</option>
 <option value="Buddy">Buddy</option>
 <option value="Buick">Buick</option>
 <option value="Cadillac">Cadillac</option>
 <option value="Chevrolet">Chevrolet</option>  
 <option value="Chrysler">Chrysler</option>
 <option value="Citroen">Citroen</option>
 <option value="Dacia">Dacia</option>
 <option value="Daewoo">Daewoo</option>
 <option value="Daihatsu">Daihatsu</option>
 <option value="Dodge">Dodge</option>
 <option value="Ferrari">Ferrari</option>
 <option value="Fiat">Fiat</option>
 <option value="Fisker">Fisker</option>
 <option value="Ford">Ford</option>
 <option value="GMC">GMC</option>
 <option value="Honda">Honda</option>
 <option value="Hummer">Hummer</option>
 <option value="Hyundai">Hyundai</option>
 <option value="Infiniti">Infiniti</option>
 <option value="Isuzu">Isuzu</option>
 <option value="Iveco">Iveco</option>
 <option value="Jaguar">Jaguar</option>
 <option value="Jeep">Jeep</option>
 <option value="Kewet">Kewet</option>
 <option value="Kia">Kia</option>
 <option value="Koenigsegg">Koenigsegg</option>
 <option value="Lada">Lada</option>
 <option value="Lamborghini">Lamborghini</option>
 <option value="Lancia">Lancia</option>
 <option value="Land Rover">Land Rover</option>
 <option value="Lexus">Lexus</option>
 <option value="Lincoln">Lincoln</option>
 <option value="Lotus">Lotus</option>
 <option value="Maserati">Maserati</option>
 <option value="Maybach">Maybach</option>
 <option value="Mazda">Mazda</option>
 <option value="McLaren">McLaren</option>
 <option value="Mercedes-Benz">Mercedes-Benz</option>
 <option value="Mercury">Mercury</option>
 <option value="MG">MG</option>
 <option value="MINI">MINI</option>
 <option value="Mitsubishi">Mitsubishi</option>
 <option value="Morgan">Morgan</option>
 <option value="Morris">Morris</option>
 <option value="Nissan">Nissan</option>
 <option value="Oldsmobile">Oldsmobile</option>
 <option value="Opel">Opel</option>
 <option value="Peugeot">Peugeot</option>
 <option value="Piaggio">Piaggio</option>
 <option value="Plymouth">Plymouth</option>
 <option value="Pontiac">Pontiac</option>
 <option value="Porsche">Porsche</option>
 <option value="Renault">Renault</option>
 <option value="Reva">Reva</option>
 <option value="Rolls Royce">Rolls Royce</option>
 <option value="Rover">Rover</option>
 <option value="Saab">Saab</option>
 <option value="Seat">Seat</option>
 <option value="Skoda">Skoda</option>
 <option value="Smart">Smart</option>
 <option value="Ssangyong">Ssangyong</option>
 <option value="Subaru">Subaru</option>
 <option value="Suzuki">Suzuki</option>
 <option value="Tazzari">Tazzari</option>
 <option value="Tesla">Tesla</option>
 <option value="Think">Think</option>
 <option value="Toyota">Toyota</option>
 <option value="Triumph">Triumph</option>
<option value="Volkswagen">Volkswagen</option>
<option value="Volvo">Volvo</option>
<option value="Others">Others</option>
</select>
</label>
<label>
<span>Title:</span>
<input id="title" type="text" name="title">
</label>
<label>
<span>Price:</span> 
<input id="price" type="text" name="price">$
</label>   <label>
<span>Description:</span>
<textarea id="description" name="description" rows="20" cols="60"></textarea>
</label>
<label>
<span>&nbsp;</span>
<input type="button" class="button" value="Send"/>
</label>
</form>


</body>
</html>

和我的php:

<?php
$con = mysqli_connect("", "", "", "");

if (mysqli_connect_errno()) {
echo "Failed to connect to mysqli: ".mysqli_connect_error();
}

$cat = mysqli_real_escape_string($con, $_POST['category']);
$tit = mysqli_real_escape_string($con, $_POST['title']);
$pri = mysqli_real_escape_string($con, $_POST['price']);
$des = mysqli_real_escape_string($con, $_POST['description']);


$sql = "INSERT INTO forsale (Category, Title, Price, Description)        VALUES     ('$cat', '$tit', '$pri', '$des')";

if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));

echo "1 record added";


mysqli_close($con);

?>

现在我缺少的是每个ID上传最多12张此图片的图片,并且能够检索属于eash发布的所有图片

1 个答案:

答案 0 :(得分:0)

您的代码if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con));

你错过了这样的结束大括号,不确定这是否是你的问题,但肯定是个问题。

if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));}