Hi there, I'm having a problem getting values inserting properly. What I'm doing is inserting values into a table with an auto incremented key, I then use select to return this key and then I want to insert that into a few more relation tables. But its inserting 0 instead of the proper value. The value is printing out fine on its own so I'm not sure what's going wrong. I've also been trying to find a more elegant way to do those queries, it's a rough draft :P
<?php
ini_set('session.cache_limiter','private');
session_start();
if(isset($_POST['submitbutton'])){
$title=$_POST['title'];
$author=$_POST['author'];
$bio=$_POST['bio'];
//$ISBN=$_POST['ISBN'];
$libref=$_POST['libref'];
//$series=$_POST['series'];
//$volume=$_POST['volume'];
// $publisher=$_POST['publisher'];
// $year=$_POST['year'];
// $status=$_POST['status'];
// $section=$_POST['section'];
$summary=$_POST['summary'];
@mysql_connect($_SESSION['hostname'],$_SESSION['username'],$_SESSION['password']) or die("Access to db server denied");
@mysql_select_db($_SESSION['db']) or die("Access to database denied");
mysql_query("insert ignore into authors(aname, abio) values('$author', '$bio')") or die(mysql_error());
$aid=@mysql_query("select aid from authors where aname = '$author'");
echo mysql_result($aid, 1);
mysql_query("insert ignore into books(title, summary, quantity) values('$title', '$summary', '1')") or die(mysql_error());
print("added books");
$bid=@mysql_query("select bid from books where title = '$title'")or die(mysql_error());
echo mysql_result($bid, 1);
//@mysql_query("insert ignore into ISBN values('$ISBN')")or die(mysql_error());
mysql_query("insert ignore into libraryReference values('$libref')")or die(mysql_error());
mysql_query("insert ignore into librarybook values('$libref', '$bid')")or die(mysql_error());
//mysql_query("insert ignore into hasISBN values('$libref', '$ISBN')")or die(mysql_error());
//mysql_query("insert ignore into bookFormat values('$libref', '$fid')")or die(mysql_error());
//$secID=@mysql_query("select secID from Section where Section = '$section'");
//mysql_query("insert ignore into areInSection('$libref', '$secID')")or die(mysql_error());
//$sid=@mysql_query("select sid from status where status = '$status'");
//mysql_query("insert ignore into areAvailable values('$libref', '$sid')")or die(mysql_error());
mysql_query("insert ignore into authorsWrite values('$aid', '$libref')")or die(mysql_error());
//mysql_query("insert ignore into publishers(name) values ('$publisher')")or die(mysql_error());
///$pid=@mysql_query("select pid from publishers where pname = '$publisher'")or die(mysql_error());
//mysql_query("insert ignore into booksPub values('$libref', '$pid', '$year')")or die(mysql_error());
//mysql_query("insert ignore into authorsPub values('$aid', '$pid')")or die(mysql_error());
//mysql_query("insert ignore into series(title) values('$series')");
//$serID = "select serID from series where title = '$series'";
//mysql_query("insert into areInSeries values ('$libref', '$serID', '$volume')")or die(mysql_error());
}
?>
mysql_query("insert ignore into librarybook values('$libref', '$bid')")or die(mysql_error());
this is the one that's failing, if I select * from librarybook it returns a bid = 0 for every entry. Also the ignore isn't working, I was trying to find a way to stop duplicate entries from being made, ie: if the title is all ready listed in the books table don't enter it a second time. A quick internet search suggested ignore.