ok, in edit.php change your SQL statement to read:
$result = mysql_query("SELECT * FROM $db_table WHERE id=$_GET[editid]"); do this for forward compatability and security sake.
in update.php change your SQL statement to:
$result = mysql_query("UPDATE $db_table SET loaddate=$_POST[loaddate], origcity=$_POST[origcity], origstate=$_POST[origstate], destcity=$_POST[destcity], deststate=$_POST[deststate] WHERE id=$_POST[ID]");
what i think was happening is that update.php was no longer within the same scope as index.php. since $_POST is super-global and is present everywhere that problem should be solved.
arrrgghhh - php & mysql not playing nice together..!
Moderator: General Moderators
- mydimension
- Moderator
- Posts: 531
- Joined: Tue Apr 23, 2002 6:00 pm
- Location: Lowell, MA USA
- Contact:
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Just want to add a couple of adjustments to mydimension's code:
and
The reason I've done this is firstly because you must quote your array element names so $_POST['ID'] not $_POST[ID] because otherwise PHP does extra work looking for a constant called ID before it realises there isn't one and decides you probably meant an element name 'ID'. Secondly keep the SQL statement in a variable of it's own instead of just writing it straight into the mysql_result() function so that you can echo it out to make sure that all the variables are being passed properly. Finally always have some form of error handling for your MySQL commands - using mysql_error() may not be appropriate when you put the site into production but you can easily change the die statements to just read 'or die('There has been an error with the database')'.
Mac
Code: Select all
$sql = "SELECT * FROM $db_table WHERE id=".$_GETї'editid'];
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');Code: Select all
$sql = "UPDATE $db_table SET loaddate='".$_POSTї'loaddate']."', origcity='".$_POSTї'origcity']."', origstate='".$_POSTї'origstate']."', destcity='".$_POSTї'destcity']."', deststate='".$_POSTї'deststate']."' WHERE id=".$_POSTї'ID'];
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');The reason I've done this is firstly because you must quote your array element names so $_POST['ID'] not $_POST[ID] because otherwise PHP does extra work looking for a constant called ID before it realises there isn't one and decides you probably meant an element name 'ID'. Secondly keep the SQL statement in a variable of it's own instead of just writing it straight into the mysql_result() function so that you can echo it out to make sure that all the variables are being passed properly. Finally always have some form of error handling for your MySQL commands - using mysql_error() may not be appropriate when you put the site into production but you can easily change the die statements to just read 'or die('There has been an error with the database')'.
Mac
- DiamondLil
- Forum Newbie
- Posts: 15
- Joined: Fri Oct 04, 2002 11:14 am
yes, it was introduced in php 4.1
take a look at http://www.php.net/manual/en/reserved.v ... ables.post
take a look at http://www.php.net/manual/en/reserved.v ... ables.post
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
For PHP 4.0.6 or lower $_POST can be replaced with $HTTP_POST_VARS (this array will also work in PHP 4.1 up). The main difference between them (aside from one being quicker to type than the other) is that if want to use $HTTP_POST_VARS in a function you need to declare it global but you don't have to do that with $_POST.
Have a read of the manual page volka pointed you towards as it also explains the other pre-defined arrays that are available to you.
Mac
Have a read of the manual page volka pointed you towards as it also explains the other pre-defined arrays that are available to you.
Mac
- DiamondLil
- Forum Newbie
- Posts: 15
- Joined: Fri Oct 04, 2002 11:14 am
Thank you twigletmac & mydimension, not just for the proper code but more importantly for the time you took to explain WHY it was the proper code (yes, it's all working now
.
One last question, though: you mentioned that I had to declare it globally, I didn't do anything over than replace the $_POST w/ the $HTTP_POST_VARS. Why is is working?
volka - I've been, but a lot of the info is still over my head until I start trying to use bits of it. I'll go take another read through, see if more of it starts to sink in now. Thank you.
One last question, though: you mentioned that I had to declare it globally, I didn't do anything over than replace the $_POST w/ the $HTTP_POST_VARS. Why is is working?
volka - I've been, but a lot of the info is still over my head until I start trying to use bits of it. I'll go take another read through, see if more of it starts to sink in now. Thank you.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You only have to declare it global in a function for example if you had
If you wanted to change $_POST to $HTTP_POST_VARS you'd have to add another line to your function making $HTTP_POST_VARS global:
It only applies when you are using the arrays in functions that you have written yourself. For more info on user-defined functions:
http://www.php.net/manual/en/functions.php
Mac
Code: Select all
function my_function()
{
print_r($_POST);
}Code: Select all
function my_function()
{
global $HTTP_POST_VARS;
print_r($HTTP_POST_VARS);
}http://www.php.net/manual/en/functions.php
Mac