Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a little further expl. about HTTP_'variable'_VAR ? 1

Status
Not open for further replies.

DiamondLil

Technical User
Jul 16, 2002
107
US
Hi guys. I just got to revisted my not-quite-working-yet script trying to update a mysql database from a form(html & php), can you help?

page is supposed to look like: (except of course that the submit button is actually supposed to submit the variables to the db)


I'm using :
<form method=&quot;post&quot; action=&quot;<?php echo $PHP_SELF?>&quot;>

<?php
$HTTP_['loadavaildate','origcity','origstate','destcity','deststate']_VARS;
if ($newentry == &quot;submit&quot;) {
$sql = &quot;INSERT INTO prologiloads SET
loaddate='$loadavaildate',
origcity='$origcity',
origstate='$origstate',
destcity='$destcity',
deststate='$deststate'&quot;;

if (@mysql_query($sql)) {
echo &quot;<p>Your entry has been added.</p>&quot;;
} else {
echo &quot;<p>There has been an error adding your entry: &quot; .
mysql_error() . &quot;</p>&quot;;

}
}
//mysql_close();
?>

I'm not sure where to put the HTTP_'variable'_VAR; . I also know the syntax is wrong -the line keeps getting pegged for errors, not sure how to fix it. I have another section before this one that just pulls and displays the info that the user should be able to change, should this go up there or in this php section?

-L.
 
Another question -
I shouldn't have to create/track sessions yet for the above, should I? (please please say no.....)
 
I think you're very confused over the use of the predefined global arrays.

The global predefined variables are arrays which contain data that might be pertinent to your script. You don't have to do anything -- PHP sets them up for you every time your script runs.

The original variables were called $HTTP_[GET|POST|COOKIE|SERVER|SESSION|ENV]_VARS. (For those of you who don't understand regular expression shorthand, I mean they were called $HTTP_GET_VARS, $HTTP_POST_VARS, etc).

In PHP versions 4.1.0 and newer, a new set of variables are available, called $_[GLOBALS|SERVER|GET|POST|COOKIE|FILES|ENV|REQUEST|SESSION] (again, that's $_GLOBALS, $_SERVER, etc).

NOTE:The older variables are deprecated. If you are using a version of PHP where these variables are available, you should use them. It is very possible that the older variables will go away in a future version of PHP. Also, the new variables are &quot;super-global&quot;, where the old are merely &quot;global&quot;. You do not have to use the &quot;global&quot; directive in a function to reference the new variables.

Each of the predefined variables contains specific information. $_GET contains all data sent to the script from an HTML <form> tag which used the &quot;GET&quot; method (or where the method was not specified -- GET-method is the default). If you have a form in your HTML which has a text input named &quot;foo&quot;, when that form is submitted, the data from &quot;foo&quot; will be in $_GET['foo'].

Likewise, $_POST contains all data from forms which use the &quot;method=POST&quot; attribute, $_COOKIE contains all the cookie data sent by the browser, and so on.

Look here for more information on the super-global predefined variables:

In the case of your script, your query-building line should read something like:

$sql = &quot;INSERT INTO prologiloads SET
loaddate='$_GET[loadavaildate]',
origcity='$_GET[origcity]',
origstate='$_GET[origstate]',
destcity='$_GET[destcity]',
deststate='$_GET[deststate]'&quot;; ______________________________________________________________________
TANSTAAFL!
 
/nudge sleipnir214 :)

I think he meant POST instead of GET in all the variables.

/looks at the original method of POST and whistles.... ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Thanks for the explanation. You're right, yes, confusion.
Bear with me..
So are you saying that I need not specifically address & tell PHP to remember these variables because it's previouly 'built-in functionality' does it for me?

Example from somewhere else-> in Macromedia Director's Lingo, at the beginning of each script you must state 'Global nameofyourvariable' for director to search the scripts and find where it is defined, and use that value in any other script. If you don't - nada, it doesn't work. This is not the case with PHP because if I use the predifined $HTTP_GET(or POST)_VARS it acts like a global variable placeholder for any field in the form on that pg?


 
I haven't got it, have I?
<insert dejected sigh>
DB doesn't like:

<?php

$HTTP_POST_VARS;
if ($newentry == &quot;submit&quot;) {
$sql = &quot;INSERT INTO prologiloads SET
loaddate='$_POST[loadavaildate]',
origcity='$_POST[origcity]',
origstate='$_POST[origstate]',
destcity='$_POST[destcity]',
deststate='$_POST[deststate]'&quot;;

if (@mysql_query($sql)) {
echo &quot;<p>Your entry has been added.</p>&quot;;
} else {
echo &quot;<p>There has been an error adding your entry: &quot; .
mysql_error() . &quot;</p>&quot;;

}


}

//mysql_close();
?>
 
Yes, the global arrays, $HTTP_POST_VARS, $_POST, etc., are automagically created for you when you invoke your script. They are always there, even if they're empty. For example, if you send data to a PHP script from a &quot;GET&quot;-method form, PHP will create both $_POST and $_GET for you, even though $_POST will be empty.

Therefore, you can delete the line which reads &quot;
Code:
$HTTP_POST_VARS;
&quot;. It doesn't do anything.


Remove the &quot;@&quot;-sign from the front of your mysql_query() function. That &quot;@&quot;-sign turns off warning messages, which you probably need to see right now. ______________________________________________________________________
TANSTAAFL!
 
Got it! Thank you. I'm spending more time in that site to which you posted a link. Lots of info....

Hmm... took the @ off. Not seeing any errors? Just loads the initial query then the form, then i do a test to see if it works ...nothing...
 
Does PHP run the line of code where it prints out the success message, or the line where it prints out the failure message?
______________________________________________________________________
TANSTAAFL!
 
If the mysql_query() call in the if-statement you posted is running, one or the other must run. On an INSERT query, mysql_query() returns TRUE on success and FALSE on failure.

your SQL INSERT statement inside a larger if-statement block (if ($newentry == 'submit').....). Is your code entering that block? ______________________________________________________________________
TANSTAAFL!
 
I know it should return one or the other but I get nothing on submit : .

If it doesn't give me a specific error msg or an error on a particular line, how do I find out if its running a particular line of code?
 
I usually put print statements in them which print things like &quot;foo1&quot;, &quot;foo2&quot;, etc.

I can tell from the foos in the output which sections of code are working.

______________________________________________________________________
TANSTAAFL!
 
Got it. That last post is inspiring all kinds of foo jokes.

I'll try it to see if I can't get closer. Thanks for your help, I appreciate it. May need to come bug ya' again, though...I haven't even gotten to the edit & delete records....

Lil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top