Click to See Complete Forum and Search --> : MYSql Field not Being Filled


mrwilson
01-01-2007, 08:33 AM
I have a very simple (read 1st) database to keep track of books
Using PhpMyAdmin, I have copied the connect (no problem here) script and the insert script. I am using a form to insert the data so obviously had to rewite the insert part. The problem is, that the database will not pick up the $post from the 1st field and insert the data into the database. is there something I am missing in the following scripts?
MySQL
$sql = ("INSERT INTO `books`(`Book`, `Year`, `Author`, `Number`, `Series`, `Recommendation`, `Status`, `Key`)
VALUES ('$_Post[Book]', '$_POST[Year]', '$_POST[Author]', '$_POST[Number]', '$_POST[Series]', '$_POST[Recomendation]', '$_POST[Status]', NULL)");

There are 3 text fields in the Db, and all three are configured the same. The first text field BOOK is the one that does not accept data. It does work fine when entered from PhpMyAdmin.
The form for the first field is a normal form:
Book Name: <input name="Book" type="text" tabindex="1" maxlength="200" size="50"

All other fields inthe db accept the form data properly.
I get no error messages, plus use a small php script to tell me what data I entered on the post page. That shows the data was entered properly.

Any thoughts or further code required?

mrwilson
01-01-2007, 08:51 AM
I guess looking at your code someplace else other than an editor works wonders. I seen the problem as soon as I posted it! the problem was obviously the ('$_Post[Book]', part.

I guess this thread can be removed, thanks.

chazzy
01-01-2007, 09:53 PM
thus the problem with string manipulation


$sql = "INSERT INTO `books`(`Book`, `Year`, `Author`, `Number`, `Series`, `Recommendation`, `Status`, `Key`)
VALUES ('$_Post[Book]', '$_POST[Year]', '$_POST[Author]', '$_POST[Number]', '$_POST[Series]', '$_POST[Recomendation]', '$_POST[Status]', NULL)";
When you reference members of the $_POST array, you should be indexing them by name. I'm assuming you don't have a defined variable named "Book" or "Author" etc. They should be referenced as $_POST['Book'] or $_POST['Author']. However, you need to properly list them.

code should be something like this:

.. VALUES('".$_POST['Book']."'...


While I doubt this is your problem, it's more of a "how to write code that can be read for debugging". I'm not sure what you're doing after you set the variable $sql. Could you tell us with the code maybe?

mrwilson
01-03-2007, 09:23 PM
The whole problem went away when I spelled $_Post like this, then corrected it to $_POST.

Dont know why that made a difference, but it did. Incidently, what I had pasted there for code was directly out of PhpMyAdmin except that I had to change the normal syntax to $_POST Syntax to get the data from the form.

No, no variables, this was a direct from form to database transfer.

<== VALUES('".$_POST['Book']."'...==>
You appear to be putting double " "s in your code, but PhpMyAdmin does not. What am i missing here? The array works just fine as I have it in the original posting. hehe now I am confused!

chazzy
01-03-2007, 11:00 PM
are you using PHPMyAdmin's generate PHP code function?

mrwilson
01-04-2007, 04:46 PM
Yes I am using PHPMyAdmin to create the code. I do not change the syntax `` "" '' in any way