I am having trouble inserting into my database. One of my insert statements works because when I do a Select * from table; i get the new records. However the other table that I want to be inserted doesnt have any values when I select * from it.
The DDL of the 2 tables that I want the values inserted are
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;
The table that has issues is the BLAST Table. I believe it is because there is a foreign key of job_id and I dont actually insert that value in. I thought it would just do the same job_id as the job_id in the Job table but I guess im wrong. If someone could explain to me what to do I would greatly appreciate it!
PHP code
<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));
}
?>
ERROR I AM GETTING: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''job_id',database, evalue) VALUES ('56','0.001', 'Eukaryota')' at line 1