Forum Moderators: coopster

Message Too Old, No Replies

PHP and MySQL; using forms to insert multiple records into one table.

         

Fullest Empty

10:57 pm on Mar 21, 2004 (gmt 0)

10+ Year Member



EDIT: Ne need to reply. I managed to figure out the problem. It was because I mis-placed a capital letter. Curse you, case-sensitivty!

Using PHP and MySQL, all I simply want to do is insert multiple records into the same table... but alas, being the ignorant newbie that I am, it isn't causing me much hassle.

I want the user to be able to type into multiple text fields that are then declared as variables and submitted to the database. Help?

This is my pathetic coding thus far:

[PHP]
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<p>
Type book title:<textarea name="booktitle"></textarea><br>
Type ISBN here:<textarea name="isbn"></textarea><br>
Type Author here:<textarea name="Author"></textarea><br>
Type Genre here:<textarea name="Genre"></textarea><br>
<input type="submit" name="submit" value="SUBMIT" >
</p>
</form>

<?php

if (isset($_POST['submit'])) {
$booktitle = $_POST['booktitle'];
$isbn = $_POST['isbn'];
$author = $_POST['author'];
$genre = $_POST['genre'];
$insert = "INSERT INTO Book SET
Title='$booktitle',
ISBN='$isbn',
Author='$author',
Genre='$genre';
if (@mysql_query($insert)) {
echo('Book Title has been added.<br>'); }
else {
echo('Error in submission:' . mysql_error());
}}

?>

[/PHP]

I keep getting errors everytime I play around with it. Can anyone shed any light?

[edited by: Fullest_Empty at 12:36 am (utc) on Mar. 22, 2004]

Moonface

11:33 pm on Mar 21, 2004 (gmt 0)

10+ Year Member



First thing i noticed was no closing quote for the $insert string i.e. should be:

$insert = "INSERT INTO Book SET
Title='$booktitle',
ISBN='$isbn',
Author='$author',
Genre='$genre'";