Updating a field in a DB with PHP.
Moderator: General Moderators
Updating a field in a DB with PHP.
I have a DB that I am pulling information from. The information is tied to someone's name, and has a specific id with each entry. I have added a modify button because I would like to modify certain fields on ONE specific entry found. I make my changes, and would like for the changes to append to the existing field with a date stamp. I am having a problem with the UPDATE command, and cannot get it to write back to the DB. When I assign a variable to use in the UPDATE command it kicks back a message saying it is an undefined variable, even though I declared as a global variable. Any suggestions?
-
pinehead18
- Forum Contributor
- Posts: 329
- Joined: Thu Jul 31, 2003 9:20 pm
"$sql = "UPDATE tablename SET field='$var' WHERE user='$user'";" The problem I am having is stemming from the variable "$var" not being sent from the previous page.
I have two fields that need to come over from the previous page. I put my UPDATE command just as you have it before and it tells me that "$var" is an undefined variable. When I declare it at the top (or as a glodal variable) it still tells me that it is undefined. Why?
I have two fields that need to come over from the previous page. I put my UPDATE command just as you have it before and it tells me that "$var" is an undefined variable. When I declare it at the top (or as a glodal variable) it still tells me that it is undefined. Why?
Hi,
the prob could be that - if you're using PHP > 4.2 and REGISTER_GLOBALS is off - $var needs to be redeclared like this:
step 1:
step 2:
I hope this helps.
-bluenote
the prob could be that - if you're using PHP > 4.2 and REGISTER_GLOBALS is off - $var needs to be redeclared like this:
step 1:
Code: Select all
<?php
echo "input type="text" name="var" value=\someVal">";
?>Code: Select all
<?php
$var = $_POST["var"]; or if using GET
$var = $_GET["var"]; or if unknown
$var = $_REQUEST["var"]; or if input type field was file
$var = $_FILES["var"];
?>-bluenote
Last edited by bluenote on Thu Jan 29, 2004 7:26 am, edited 1 time in total.