Jump to content

Why isn't my $_POST variable being set?


ksa

Recommended Posts

Attached are my 3 files. You will have to create the database and tables first to test this. I'm using MySQL. the field names for the table are:

 

Book_Id

Book_Name

Author

Book_price

 

The main form is updateinsertdata2.php. This file is the html form to work with. When you click on the 'edit' link (make sure there is data in the table first to see this link), the top of the form is filled in with data and an 'update' button appears 

 

When you click on the 'update' button the $_POST does not get set so my code does not get executed.

 

Why?

connecttodb.php

indexupdateexp.php

updateinsertdata2.php

Link to comment
Share on other sites

your $_POST data isn't the problem. your code is most likely being executed. why you are getting a symptom that makes it appear like your code isn't being executed is due to either php's output_buffering (hides output from your code and php errors if there is a header() redirect) and/or php's error reporting/display_errors (php errors are not being reported/displayed) settings that are set on your server.

 

you should be getting an error like this -

 

Notice: Undefined variable: GET in C:\xampp\htdocs\updateinsertdata2.php on line xx <----- the line where your UPDATE sql query statement is at

 

 

you need to have the following set in the php.ini on your development system -

 

error_reporting = E_ALL

display_errors = ON

output_buffering = OFF

 

make sure these are set as shown, restart your web server to get any changes made to the php.ini to take effect, and confirm that the settings actually got changed by checking the values with a phpinfo() statement in a .php script.

 

this will get your development system set up so that it will help you by showing any output from your code and from php errors.

 

once you are getting that particular Notice: ... error, it should be easy to find and fix the problem in your code.

 

next, you need to use prepared queries, with place-holders in the sql query statement for data values and use exceptions to handle database errors. this will actually simplify both your sql query and php program logic. unfortunately, the php mysqli extension is not the best choice. if you can, switch to use the php PDO extension. it is more consistent and easier to use than the mysqli extension.

Edited by mac_gyver
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.