2 つのテーブルにデータを挿入しようとしているのですが、両方のテーブルに自動インクリメントが必要です。
著者を本にたどる必要があります。
ここに私が使用している私のhtmlコードとphpコードがあります。
どんな助けでも大歓迎です。
HTML コードは次のとおりです。
<form id="contact-form" method="post" action="database3.php" >
<label for="fname">First Name: <span class="required">*</span></label>
<input type="text" id="fname" name="fname" value="" placeholder="John" required="required" />
<label for="auth-name">Second Name: <span class="required">*</span></label>
<input type="text" id="sname" name="sname" value="" placeholder="Doe" required="required" /><br />
<label for="email">Email Address: <span class="required">*</span></label>
<input type="email" id="email" name="email" value="" placeholder="johndoe@example.com" required="required" />
<label for="telephone">Telephone: <span class="required">*</span></label>
<input type="text" id="telephone" name="telephone" value="" placeholder="" required="required" /><br />
<label for="genre">Genre: <span class="required">*</span></label>
<select id="genre" name="genre" placeholder="please select one..." required="required">
<option value="please-select">Please select one..</option>
<option text="murder_mystery" value="1">Murder Mystery</option>
<option text="romance" value="2">Romance</option>
<option text="sci_fi" value="3">Sci-Fi</option>
<option text="horror" value="4">Horror</option>
<option text="thriller" value="5">Thriller</option>
<option text="screen_plays" value="6">Screen Play's</option>
<option text="poetry" value="7">Poetry</option>
<option text="childrens" value="8">Children's</option>
<option text="non_fiction" value="9">Non-Fiction</option>
<option text="comedy" value="11">Comedy</option>
<option text="other" value="10">Other</option>
</select>
<label for="numpages">Number of Pages: <span class="required">*</span></label>
<select id="numpages" name="numpages">
<option value="num-page">Please Select one..</option>
<option value="0-100">0-100</option>
<option value="100-300">100-300</option>
<option value="300-500">300-500</option>
<option value="500">500+</option>
</select><br />
<label for="booktitle">Book Title: <span class="required">*</span></label>
<input type="text" id="booktitle" name="booktitle" value="" placeholder="John Doe" required="required" />
<br />
<label for="description">Book Description: <span class="required">*</span></label>
<textarea id="bookdescription" name="description" placeholder="max 40 words describing your work, this will effectively be how you sell your bookto the reader" required="required" data-minlength="20"></textarea>
<br />
<label for="synopsis">Book Synopsis: <span class="required">*</span></label>
<textarea id="synopsis" name="synopsis" placeholder="max 100 words of the synopsis of your book,to the reader"
required="required" data-minlength="20"></textarea>
<br />
<label for="file">Filename:</label>
<input type="file" name="file" id="file">
<br />
<label for="check_tc">Do you agree to the T&C<span class="required">*</span></label>
<input type="checkbox" id="check_tc" name="check_tc" required="required" />
<br />
<input type="submit" value="submit" id="submit-button" />
</form>
PHPコードは次のとおりです:-
<?php
$connection = mysql_connect("localhost", "root", "");
if(!$connection)
{
die("database connection failed: " . mysql_error());
}
$db_select = mysql_select_db("good-read", $connection);
if(!$db_select)
{
die("database selection failed: " . mysql_error());
}
$sql = "INSERT INTO author (auth_first, auth_second, auth_email, auth_telephone)
VALUES
('$_POST[fname]','$_POST[sname]','$_POST[email]', '$_POST[telephone]')";
mysql_query($sql, $connection);
echo "1 record added";
$sql_book = "INSERT INTO book (book_title, book_num_pages, book_genre_id, book_description, book_synopsis)
VALUES
('$_POST[booktitle]', '$_POST[numpages]', '$_POST[genre]','$_POST[description]', '$_POST[synopsis]')";
mysql_query($sql_book, $connection);
echo "1 record added";
mysql_close($connection);
?>