I am building a mini library management system but ran into a few issues and was hoping I could get some tips and suggestions.
Currently I have two pages: one insert.php, and one HTML page.
When I successfully insert a book or transaction into the database a new page opens up and I receive a success status message.
Is it possible to combine both these pages into one and return the success message below the submit button?
I tried using the following to pull lms_status_types_status_id directly from the database but failed:
<select name="lms_status_types_status_id" id="individual" multiple="multiple"> <option value="0" SELECTED>Select User</option> <?php foreach($RET as $userdata){ ?> <option value="<?php echo $userdata['lms_status_types_status_id']; ?>"></option> <?php } ?> </select>
Any idea what I am doing wrong here?
I have tried asking Google for help but found it difficult to implement what was floating around. I am entirely new to php so please excuse me!
insert.php
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$RET = DBGet(DBQuery("SELECT * FROM lms_transactions"));
mysql_select_db("my_db", $con);
$sql="INSERT INTO lms_books (book_id, tag, title, author, year)
VALUES
('$_POST[book_id]','$_POST[tag]','$_POST[title]' ,'$_POST[author]' ,'$_POST[year]')";
$sql="INSERT INTO lms_transactions (student_id, lms_books_tag, lms_books_book_id, lms_status_types_status_id)
VALUES
('$_POST[student_id]','$_POST[lms_books_tag]','$_POST[lms_books_book_id]','$_POST[lms_status_types_status_id]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
HTML File
<h2> Library Management System</h2>
<h3>Check-In/Check-Out Book:</h3>
<form action="/insert.php" method="post">
Student ID: <input type="text" name="student_id">
Book Tag: <input type="text" name="lms_books_tag">
Book ISBN: <input type="text" name="lms_books_book_id">
Status: <select name="lms_status_types_status_id">
<option value="Checked-In">Checked-In</option>
<option value="Checked-Out">Checked-Out</option>
</select>
<input type="submit">
</form>
<h3>Insert Book:</h3>
<form action="/insert.php" method="post">
Book ISBN: <input type="text" name="book_id">
Tag: <input type="text" name="tag">
Title: <input type="text" name="title">
Author: <input type="text" name="author">
Year: <input type="text" name="year">
<input type="submit">
</form>