PHP에 고유 ID를 추가하는 빠른 방법이 있습니까?이 포럼을 통해 스크롤했지만 내 목표를 달성하는 훨씬 간단한 방법이 있기를 바랍니다.PHP mysql upload에 고유 한 ID를 추가하십시오.
기본적으로 완벽하게 작동하는 업로드가 있습니다. mysql에서 자동 증가 고유 ID 필드를 사용하여 생성되는 각 항목에 제품 코드를 추가하려고합니다. 유일한 "문제의 라인을"코드에 -
이제 주어진 모든 작품<form enctype="multipart/form-data" action="addfurn.php" method="POST">
<table width="100%" border="2" cellpadding="5"class="myaccount">
<tr>
<td>Title: </td>
<td><input type="text" name="title" /></td>
</tr>
<tr>
<td>Description: </td>
<td><input type="text" name = "desc" /></td>
</tr>
<tr>
<td>Price: </td>
<td><input type="text" name = "price" /></td>
</tr>
<tr>
<td>P&P: </td>
<td><input type="text" name = "pandp" /></td>
</tr>
<tr>
<td>Main Image: </td>
<td><input type="file" name="photo" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" class="CMSbutton" value="Add" /></td>
</tr>
</table>
</form>
가 :
<?php include 'dbc.php'; page_protect();
if(!checkAdmin()) {header("Location: login.php");
exit();
}
$host = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);
$login_path = @ereg_replace('admin','',dirname($_SERVER['PHP_SELF']));
$path = rtrim($login_path, '/\\');
foreach($_GET as $key => $value) {
$get[$key] = filter($value);
}
foreach($_POST as $key => $value) {
$post[$key] = filter($value);
}
?>
<?php
if($_FILES['photo']) //check if we uploading a file
{
$target = "images/furnishings/";
$target = $target . basename($_FILES['photo']['name']);
$title = mysql_real_escape_string($_POST['title']);
$desc = mysql_real_escape_string($_POST['desc']);
$price = mysql_real_escape_string($_POST['price']);
$pandp = mysql_real_escape_string($_POST['pandp']);
$pic = "images/furnishings/" .(mysql_real_escape_string($_FILES['photo']['name']));
$productcode = "FUR000" .(mysql_real_escape_string($_POST['id']));
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
mysql_query("INSERT INTO `furnishings` (`title`, `desc`, `price`, `pandp`, `photo`,`productcode`) VALUES ('$title', '$desc', '$price', '$pandp', '$pic', '$productcode')") ;
echo "The product has been added to the furnishings category";
}
else
{
echo "Please fill out the specifications and select the respective file to upload for the main image";
}
}
?>
다음과 같은 HTML :
지금까지 나는 다음과 같은 PHP를
$productcode = "FUR000" .(mysql_real_escape_string($_POST['id']));
ID가 아직 생성되지 않았으므로 삽입 쿼리에 추가 할 수 없다고 가정하므로 내 테이블을 sql은 추가 된 각 새 항목에 대해 FUR000을 반환합니다.
새로운 라인을 추가하는 것과 비슷한 방식으로이 라인을 mysql에서 자동 증분하도록 수정하는 방법이 있습니까? 아니면 HTML 테이블의 각 항목에 고유 한 코드를 포함해야합니까?
많은 도움을 주셨습니다.
감사 JD
그는 무엇에 관해 말하고 있습니까? "mysql upload"란 무엇입니까? –
미안 해요 - PHP는 MySQL의 삽입 ..... – JD2011