iRock Posted December 12, 2007 Share Posted December 12, 2007 I can't spot the mistake here - as usual Im sure its just syntax. I just started to learn PHP yesterday. Heres the code: http://pastie.caboo.se/127816 I'm following a tutorial and in this particular video it is hard to see the difference between () {} [] etc. Should it be: $data2 = $_POST['data2']; $data3 = $_POST['data3']; $data4 = $_POST['data4']; $submit = $_POST['submit'] or $data2 = $_POST{'data2'}; $data3 = $_POST{'data3'}; $data4 = $_POST{'data4'}; $submit = $_POST{'submit'} Other than that can anyone spot a mistake? Any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 12, 2007 Share Posted December 12, 2007 Variable arrays go in [ ] Quote Link to comment Share on other sites More sharing options...
iRock Posted December 12, 2007 Author Share Posted December 12, 2007 Variable arrays go in [ ] Thanks for that. Quote Link to comment Share on other sites More sharing options...
iRock Posted December 12, 2007 Author Share Posted December 12, 2007 The elseif echo is the only problem that I am having now if anyone would check out the code and give me some feedback that would be great. Quote Link to comment Share on other sites More sharing options...
JakeTheSnake3.0 Posted December 12, 2007 Share Posted December 12, 2007 Maybe I'm not looking hard enough...but there's a couple of things to consider: 1) Where are your form inputs for data2, data3 and data4? 2) What kind of data are you expecting with data2, data3 and data4? In your IF statements, if you are just trying to see whether data2, data3, and data4 exist, use the isset() function. IF statements can be read a couple of ways...the number 1 will return TRUE and the boolean data TRUE will obviously return TRUE...so when you say... if ($submit && $data2 && $data3 && $data4) you are really saying "If all of these variables equate to TRUE (whether it be boolean TRUE or string/number 1) then blah blah blah" Quote Link to comment Share on other sites More sharing options...
iRock Posted December 12, 2007 Author Share Posted December 12, 2007 1) Where are your form inputs for data2, data3 and data4? 2) What kind of data are you expecting with data2, data3 and data4? What I have is basically a webpage where users can input information into the text fields data2, data2 and data4. The script should 1. Check that none of the fields are blank. 2. Add the values to the database if all fields have been filled in / or inform the user that one of the values is missing. Quote Link to comment Share on other sites More sharing options...
JakeTheSnake3.0 Posted December 13, 2007 Share Posted December 13, 2007 Then use the isset() function with the $_POST[] variables.... if ($submit && isset($_POST['data2']) && etc. etc. etc.) { } Or you can determine what data is being held in one of the variables when you don't input anything (it could be just "" or NULL or whatever)....and then look for that in your IF statement. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.