Need help inserting values into MySQL Database

Posted 25 April 2010 - 02:44 AM

I'm trying to code a page that when someone enters in some text and clicks submit, that text gets inserted into a database and is assigned a number which is auto incremented. When I run a query from a php page to view all of the results in the table, I can see that a row is being created, but there are no values being inserted. Another issue that I'm having is that when I try and display the number that is generated from the ID column on the submission page, the ID number sisn't showing. Right now I have 2 pages coded that allows me to enter in the text and then a php page that inserts the data into table. I also created another php page to view all of the data in the table which I'm not having any problems with at the moment. The information on the table is attached.

Attached image(s)

Replies To: Need help inserting values into MySQL Database

Re: Need help inserting values into MySQL Database

Posted 25 April 2010 - 03:27 AM

There are some areas you have done mistake. First, you have used post method in the form, but while retrieving form data, you have used get method, thats why nothing is being inserted into the database. So replace these lines with $_POST method-

Re: Need help inserting values into MySQL Database

I get a number but the number is 0 instead of 461, which is the current number in the id column.

It looks like it matters where the

$BugID = mysqli_insert_id($DBConnect);

is placed, a suggestion from another place, as I moved it up below my database connection string instead of above the database close string where I had it and that's when I got the 0. I since moved it back and now I get the number that's in the id column.

Re: Need help inserting values into MySQL Database

Posted 26 April 2010 - 02:48 AM

gtrippleb, on 25 April 2010 - 08:39 PM, said:

The book I was using for an example had the

<?= variable ?>

. I didn't even think of short tags being turned on or off.

<?= $var ?> is a variation of short tags and is known as short circuit syntax which is generally used for echoing something. As it turned off by default, for maximum portability option, you need to use standard tags <?php ?>.