我無法插入到我的數據庫。我的插入語句之一,因爲當我做一個選擇*從表;我得到新的記錄。然而,我想要插入的其他表沒有任何值,當我從中選擇*。插入到MySQL數據庫不能從PHP工作
,我想插入值2代表的DDL是
CREATE TABLE Job(uid INTEGER,job_id INTEGER AUTO_INCREMENT,
input varchar(500),status varchar(100),start_time time,finish_time time,
FOREIGN KEY(uid) REFERENCES User(uid) ON DELETE CASCADE,
PRIMARY KEY(job_id))ENGINE = InnoDB;
CREATE TABLE BLAST(database varchar(100),evalue varchar(100),job_id INTEGER,
FOREIGN KEY (job_id) REFERENCES Job(job_id))ENGINE = InnoDB;
有問題的表是BLAST表。我相信這是因爲有一個job_id的外鍵,而我實際上並沒有插入該值。我認爲它只是做Job_id作業表中的job_id,但我猜我是錯的。如果有人能向我解釋該怎麼辦,我將不勝感激!
PHP代碼
<select id="database" name="database">
<option selected="selected" disabled="disabled">Database</option>
<option value="Archaea">Archaea</option>
<option value="Bacteria">Bacteria</option>
</select>
<select id="evalue" name="evalue">
<option selected="selected" disabled="disabled"> evalue <option>
<option value="0.0001">0.0001</option>
<option value="0.001">0.001</option>
</select>
<select id="hits" name="hits">
<option selected="selected" disabled="disabled"> Hits</option>
<option value="50">50</option>
<option value="100">100</option>
</select>
<input id="BlastSearch" type="text" name="BlastSearch" value='' />
<input type="submit" name="submit" value="submit" />
<button type="reset" value="Clear">Clear</button>
</form>
<?php
session_start();
require_once '../secure/database.php';
$mysqli = new mysqli($dbhost,$dbuser,$dbpass,$dbname);
}
//Insert the values into the database
if(isset($_POST['submit'])){
//declare variables to what the user defines them as
$db = $_POST['database'];
$evalue = $_POST['evalue'];
$sequence = $_POST['BlastSearch'];
//insert the values into the database
$mysqli->query("INSERT INTO `Job` (`uid`, `input`, `status`, `start_time`, `finish_time`) VALUES ('1', '" . $sequence . "', 'running' , NOW(), NOW())");
$mysqli->query("INSERT INTO `BLAST`(`database`, `evalue`, `job_id`) VALUES ('" . $db . "','" . $evalue . "', '1')") or die(mysqli_error($db));
}
?>
錯誤我收到:您的SQL語法錯誤;檢查對應於你的MySQL服務器版本使用附近的'JOB_ID '正確的語法,database
,evalue
)VALUES( '56', '0.001', '真核生物')' 在1號線
任何錯誤信息? – panther
不是我做的PHP的search.php :( – jefferymicheals
我*敢肯定那*第二次查詢將會導致錯誤。因爲你有一個字符串文字作爲列名,然後叫回來,打勾的標識符「1」在 – David