好的,所以我正在尝试创建一个可用列以在输入相同的字段后递增,但它似乎不起作用,我已经尝试了很长时间。我知道代码一团糟,但请有人帮忙吗?
$make = strtolower($_POST['make']);
$fuel = $_POST['fuel'];
$transmission = $_POST['transmission'];
$size = $_POST['size'];
$doors = $_POST['doors'];
/*$date = time();*/
date_default_timezone_set('Europe/London');
$date = date('y-m-d');
$connect = mysql_connect ("localhost", "root", "**********");
mysql_select_db ("car");
$query = "SELECT * FROM type WHERE make = '$make'";
$result = mysql_query($query);
$row = mysql_num_rows($result);
$amount = $row+1;
$id = $make."[".$amount."]";
if (isset($_POST['submit'])){
if ($make&&$fuel&&$transmission&&$size&&$doors)
{
/*if ($fuel!== $fueltype['0','1','2','3'])*/
if ($fuel=='text')
{
$msg = ("Please enter a valid fuel type: Petrol, Diesel, LPG or Electric");
}
else
if ($transmission=='text')
{
$msg = ('Please enter a valid transmission type: Manual, Auto or Semi-auto');
}
else
if(strpos($size,".") == false){
$msg = ('Please enter the valid engine size: 1.0, 1.4, 1.6 etc');
}
else
if(!preg_match("/^[0-9]+$/",$doors)){
$msg = ('Please enter the number of doors. 3, 5 etc');
}
else{
//Creates the id
$query = mysql_query("SELECT * FROM type");
$numrows = mysql_num_rows($query);
if ($numrows!=0){
while ($row = mysql_fetch_assoc($query)){
$dbid = $row["id"];
$dbmake = $row["make"];
$dbfuel = $row["fuel"];
$dbtransmission = $row["transmission"];
$dbsize = $row["size"];
$dbdoors = $row["doors"];
}
if ($make==$dbmake&&$fuel==$dbfuel&&$transmission==$dbtransmission&&$size==$dbsize&&$doors==$dbdoors){
print_r($dbid);
print_r($dbmake);
print_r($dbfuel);
print_r($dbtransmission);
print_r($dbsize);
print_r($dbdoors);
mysql_query("UPDATE type SET available=available+1 ON DUPLICATE KEY id = id ");
}
else{
//increments the available column '$make'+'[#]'
$query = "SELECT * FROM type WHERE id = '$id'";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
$inc = $numrows+1;
$available = $inc;
$query = mysql_query ("INSERT INTO type VALUES ('$id', '$make', '$fuel', '$transmission', '$size', '$doors', '$date', '$available')");
$msg = ("Car has been added to database. <a href='database.php'>View database?</a>");
}
}
}
}