次のような変数を設定してみました:$test_id = mysql_insert_id($dbc);
挿入された最後の行の ID を取得したかったからです。データベースに接続して行を挿入することはできますが、次の行 ($test_id を設定) には次のように書かれています: supplied argument is not a valid MySQL-Link resource
. 何か案は?
コードは次のとおりです。
$user_id = $_SESSION['user_id'];
$q = "INSERT INTO tests (user_id, title, subject, creation_date) VALUES ('$user_id', '$title', '$subj', NOW())"; //query to insert test details into tests table
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
$test_id = mysql_insert_id($dbc);
if (mysqli_affected_rows($dbc) == 1) {//if the query ran correctly and the test details were added to the database
$q = "INSERT INTO content (test_id, field1) VALUES ($test_id, '$content')"; //query to insert test content into content table
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
$dbc は次のように定義されます。
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASS, DB_NAME);