|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Just trying to finish this online tutorial!
I've looked at a few PHP/MySQL ebooks, online tutorials... etc, and none of them seem to agree on anything!
From one example to the next the code just doesn't match, at all. One used a constant mysql_connect("localhost"); variable in everything he did with sql! I *really* didn't understand that one. Anyway, I just want to understand why this isn't working, and what I can do to make it work. I've turned the Global_Whatchamidooky on, but still not working. (I'd rather not go that route anyway, when I find hosting I can't be assured they'll have it turned on). The error I keep getting is the "undefined variables" error. I get it in *every* manual example and online tutorial. I really must be looking in the wrong places... I've tried definding the variables with " $variable = $_POST['variable']; " but that results in an error such as.. "Notice: Undefined index: first in C:\Documents and Settings\Blake Gilroy\My Documents\My Webs\webworks\php\tut1\insert.php on line 14" Here's the complete page I'm working with atm. It seemed (initially) to be the most recent and "together" example. (the header and footer includes aren't part of the sample, I just wanted things to look pretty on my end) PHP Code:
|
|
#2
|
||||
|
||||
|
PHP Code:
I changed "<?" to "<?php" because that's standard now. Additionally, I stuck the actual processing into an if block so that it's only evaluated if POST variables have been sent (so if the form has been submitted -- else, you're attempting to use variables that haven't been filled, and you get the notices you're reporting). I also added a die statement to your query statement to facilitate debugging. And finally, I converted all your variables to references to the $_POST array. The code you've supplied wouldn't work with register_globals turned off, and my philosophy tends to be that it's better to just use the $_POST array rather than assigning values to other variables, as it keeps you always in scope and makes the code more self-documenting, if a little more unsightly.
__________________
Please don't PM me asking for solutions outside the scope of a thread. Keeping all responses in a thread stands to help others who come along later, which is after all what this forum's all about. |
|
#3
|
|||
|
|||
|
Excellent, thank you very much. I have one question (since the perpose of doing this was to understand it)
ok.. maybe a few questions PHP Code:
On that line what is the perpose of the underlined area's ('','" . $_POST["first"] . "','" . $_POST... I guess it's the syntax I'm mostly not understanding here. I'll just guess, please let me know if I'm kind of getting it. The whole set of values is enclosed in the initial double brackets. The first comma... I understand that the first variable is enclosed in the two comma's but I don't understand why. Then the first variable (first) is inclosed in the single quotes, but why is there a double quote after that single quote, why's that? The period seems to be another beggining and end spot too, does that exist because this is all part of the $_POST array? If you could even point me somewhere that would explain all those things to me that would be muchly appreciated. I know *how* to do it now, I would just like to understand what I'm doing ![]() |
|
#4
|
||||
|
||||
|
This is just the notation I tend to prefer because it keeps me from having variables/arrays all jammed together inside double quotes. Basically, the dot is a concatenation operator, which you can use to glue strings and variables together. Since I don't like having arrays and variables inside long double-quoted strings, I break the string and variable/array portions apart and use the dot operator to glue them together.
There's one thing that may be confusing here -- the first variable after "VALUES(" is an empty set of single quotes rather than a double-quote. It looks sort of like a double-quote on my screen, and I could see how that would be confusing indeed. |
|
#5
|
|||
|
|||
|
Thanks for all your help. I had taken a break from my php/mysql endeavor to move and your explanation of your notation filled in the blanks I had from before. I now feel comfortable moving on to the few more complicated things.
Thanks again! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Just trying to finish this online tutorial! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|