Form Will Not Update MySQL DB

Form Will Not Update MySQL DB

am 12.08.2007 02:09:28 von chrisv

Hello everyone.

I have a simple form that is designed to update a single database
record at a time. It works fine until my pageaction variable is set
to "update". The update conditional code doesn't execute. It is
supposed to trigger an mysql record update using a predefined query.
The username used to query the database has all privileges, so that
isn't the problem. An suggestions? Here is the code:


------------------------------------------------------------ ------------------------------------------------------------ --------------------------

//get your hbc database connection
include "db_connect.php";


/
************************************************************ *********************************/

$cid =
$_REQUEST['consumer_id'];
$fullname =
$_REQUEST['consumer_fullname'];

/
************************************************************ *********************************/

$date = $_REQUEST['consumer_date'];
$nursingfacility =
$_REQUEST['consumer_nursing_facility'];
$nursingfacilityaddress =
$_REQUEST['consumer_nursing_facility_address'];
$coordinator = $_REQUEST['consumer_coordinator'];
$casenote = $_REQUEST['consumer_note'];
$isn = $_REQUEST['consumer_isn'];
$status = $_REQUEST['consumer_status'];


$pageaction = $_REQUEST['pageaction'];
$change = $_REQUEST['change'];

/
************************************************************ ***********************************/


//handles all EDIT->UPDATE FUNCTIONS
//with $pageaction var

if($pageaction=="update"){

if($fullname!=""){

$file_update = "UPDATE `hbc_consumers`
SET
`hbc_consumers`.`consumer_fullname`='$fullname'
WHERE `hbc_consumers`.`consumer_id`='$cid'";

$result_of_updated_file = mysql_query($file_update)
or die(mysql_error());

}//use elseif to add more options

}//end UPDATE FUNCTIONS




/
*----------------------------------------------------------- --------*/
/**************************** QUERY ONE
******************************/
/
*----------------------------------------------------------- --------*/

/* GETS the CONSUMER RECORD */
$Select_consumer= "SELECT *
FROM `hbc_consumers`
WHERE `consumer_id`='$cid'";

/* HOLDS CONSUMER RECORD data */
$Query_consumer = mysql_query($Select_consumer) or
die(mysql_error());

$fetch_consumer_info = mysql_fetch_array($Query_consumer);

$cid =
$fetch_consumer_info['consumer_id'];
$fullname =
$fetch_consumer_info['consumer_fullname'];
$date =
$fetch_consumer_info['consumer_date'];
$nursingfacility =
$fetch_consumer_info['consumer_nursing_facility'];
$nursingfacilityaddress =
$fetch_consumer_info['consumer_nursing_facility_address'];
$coordinator =
$fetch_consumer_info['consumer_coordinator'];
$casenote =
$fetch_consumer_info['consumer_note'];
$isn =
$fetch_consumer_info['consumer_isn'];
$status =
$fetch_consumer_info['consumer_status'];


?>


"http://www.w3.org/TR/html4/loose.dtd">



Home By Choice Consumer Management - Edit Consumer File<br /> Page



width="780px">



width="10px">



cellspacing="0" width="780">










>

HBC Consumer Profile H4>


 

cellpadding="10" cellspacing="0" >

action="show_profile.php" method="post">
name="pageaction" value="update">
name="consumer_id" value="">




------------------------------------------------------------ ------------------------------------------------------------ -----------------

other similar options afterwards....

Re: Form Will Not Update MySQL DB

am 12.08.2007 02:29:24 von chrisv

Pastebin link for better formatting:

http://pastebin.com/m67c0039e



Thanks





On Aug 11, 7:09 pm, chrisv wrote:
> Hello everyone.
>
> I have a simple form that is designed to update a single database
> record at a time. It works fine until my pageaction variable is set
> to "update". The update conditional code doesn't execute. It is
> supposed to trigger an mysql record update using a predefined query.
> The username used to query the database has all privileges, so that
> isn't the problem. An suggestions? Here is the code:
>
> ------------------------------------------------------------ ------------------------------------------------------------ --------------------------
> >
> //get your hbc database connection
> include "db_connect.php";
>
> /
> ************************************************************ *********************************/
>
> $cid =
> $_REQUEST['consumer_id'];
> $fullname =
> $_REQUEST['consumer_fullname'];
>
> /
> ************************************************************ *********************************/
>
> $date = $_REQUEST['consumer_date'];
> $nursingfacility =
> $_REQUEST['consumer_nursing_facility'];
> $nursingfacilityaddress =
> $_REQUEST['consumer_nursing_facility_address'];
> $coordinator = $_REQUEST['consumer_coordinator'];
> $casenote = $_REQUEST['consumer_note'];
> $isn = $_REQUEST['consumer_isn'];
> $status = $_REQUEST['consumer_status'];
>
> $pageaction = $_REQUEST['pageaction'];
> $change = $_REQUEST['change'];
>
> /
> ************************************************************ ***********************************/
>
> //handles all EDIT->UPDATE FUNCTIONS
> //with $pageaction var
>
> if($pageaction=="update"){
>
> if($fullname!=""){
>
> $file_update = "UPDATE `hbc_consumers`
> SET
> `hbc_consumers`.`consumer_fullname`='$fullname'
> WHERE `hbc_consumers`.`consumer_id`='$cid'";
>
> $result_of_updated_file = mysql_query($file_update)
> or die(mysql_error());
>
> }//use elseif to add more options
>
> }//end UPDATE FUNCTIONS
>
> /
> *----------------------------------------------------------- --------*/
> /**************************** QUERY ONE
> ******************************/
> /
> *----------------------------------------------------------- --------*/
>
> /* GETS the CONSUMER RECORD */
> $Select_consumer= "SELECT *
> FROM `hbc_consumers`
> WHERE `consumer_id`='$cid'";
>
> /* HOLDS CONSUMER RECORD data */
> $Query_consumer = mysql_query($Select_consumer) or
> die(mysql_error());
>
> $fetch_consumer_info = mysql_fetch_array($Query_consumer);
>
> $cid =
> $fetch_consumer_info['consumer_id'];
> $fullname =
> $fetch_consumer_info['consumer_fullname'];
> $date =
> $fetch_consumer_info['consumer_date'];
> $nursingfacility =
> $fetch_consumer_info['consumer_nursing_facility'];
> $nursingfacilityaddress =
> $fetch_consumer_info['consumer_nursing_facility_address'];
> $coordinator =
> $fetch_consumer_info['consumer_coordinator'];
> $casenote =
> $fetch_consumer_info['consumer_note'];
> $isn =
> $fetch_consumer_info['consumer_isn'];
> $status =
> $fetch_consumer_info['consumer_status'];
>
> ?>
>
> > "http://www.w3.org/TR/html4/loose.dtd">
>
>
>
> Home By Choice Consumer Management - Edit Consumer File<br /> > Page
>
>
>
>

bgcolor="#FFFF9D">
Name: 

if($change ==
"fullname"){

echo
" maxlength=\"45\" size=\"15\">


\"submit\" value=\"Update\">";
}else{

echo "
".
$fullname."
href=\"show_profile.php?consumer_id=$cid&change=fullname\">



";
}
?>
> width="780px">
>
>
>

> > width="10px">
>
>
>

> > cellspacing="0" width="780">
>
>
>
>
>
>
>
>
>
>

>
>
>

HBC Consumer Profile > H4>
>


>
 

> > cellpadding="10" cellspacing="0" >
>
> > action="show_profile.php" method="post">
> > name="pageaction" value="update">
> > name="consumer_id" value="">
>
>
>
>
> ------------------------------------------------------------ ------------------------------------------------------------ -----------------
>
> other similar options afterwards....

Re: Form Will Not Update MySQL DB

am 12.08.2007 09:49:55 von petersprc

Noit sure, is the form parameter name "fullname", instead of
"consumer_fullname"...

$fullname = $_REQUEST['consumer_fullname'];


On Aug 11, 8:09 pm, chrisv wrote:
> Hello everyone.
>
> I have a simple form that is designed to update a single database
> record at a time. It works fine until my pageaction variable is set
> to "update". The update conditional code doesn't execute. It is
> supposed to trigger an mysql record update using a predefined query.
> The username used to query the database has all privileges, so that
> isn't the problem. An suggestions? Here is the code:
>
> ------------------------------------------------------------ ------------------------------------------------------------ --------------------------
> >
> //get your hbc database connection
> include "db_connect.php";
>
> /
> ************************************************************ *********************************/
>
> $cid =
> $_REQUEST['consumer_id'];
> $fullname =
> $_REQUEST['consumer_fullname'];
>
> /
> ************************************************************ *********************************/
>
> $date = $_REQUEST['consumer_date'];
> $nursingfacility =
> $_REQUEST['consumer_nursing_facility'];
> $nursingfacilityaddress =
> $_REQUEST['consumer_nursing_facility_address'];
> $coordinator = $_REQUEST['consumer_coordinator'];
> $casenote = $_REQUEST['consumer_note'];
> $isn = $_REQUEST['consumer_isn'];
> $status = $_REQUEST['consumer_status'];
>
> $pageaction = $_REQUEST['pageaction'];
> $change = $_REQUEST['change'];
>
> /
> ************************************************************ ***********************************/
>
> //handles all EDIT->UPDATE FUNCTIONS
> //with $pageaction var
>
> if($pageaction=="update"){
>
> if($fullname!=""){
>
> $file_update = "UPDATE `hbc_consumers`
> SET
> `hbc_consumers`.`consumer_fullname`='$fullname'
> WHERE `hbc_consumers`.`consumer_id`='$cid'";
>
> $result_of_updated_file = mysql_query($file_update)
> or die(mysql_error());
>
> }//use elseif to add more options
>
> }//end UPDATE FUNCTIONS
>
> /
> *----------------------------------------------------------- --------*/
> /**************************** QUERY ONE
> ******************************/
> /
> *----------------------------------------------------------- --------*/
>
> /* GETS the CONSUMER RECORD */
> $Select_consumer= "SELECT *
> FROM `hbc_consumers`
> WHERE `consumer_id`='$cid'";
>
> /* HOLDS CONSUMER RECORD data */
> $Query_consumer = mysql_query($Select_consumer) or
> die(mysql_error());
>
> $fetch_consumer_info = mysql_fetch_array($Query_consumer);
>
> $cid =
> $fetch_consumer_info['consumer_id'];
> $fullname =
> $fetch_consumer_info['consumer_fullname'];
> $date =
> $fetch_consumer_info['consumer_date'];
> $nursingfacility =
> $fetch_consumer_info['consumer_nursing_facility'];
> $nursingfacilityaddress =
> $fetch_consumer_info['consumer_nursing_facility_address'];
> $coordinator =
> $fetch_consumer_info['consumer_coordinator'];
> $casenote =
> $fetch_consumer_info['consumer_note'];
> $isn =
> $fetch_consumer_info['consumer_isn'];
> $status =
> $fetch_consumer_info['consumer_status'];
>
> ?>
>
> > "http://www.w3.org/TR/html4/loose.dtd">
>
>
>
> Home By Choice Consumer Management - Edit Consumer File<br /> > Page
>
>
>
>

> bgcolor="#FFFF9D">
> Name: 
> >
> if($change ==
> "fullname"){
>
> echo
> " > maxlength=\"45\" size=\"15\">
>
> > \"submit\" value=\"Update\">";
> }else{
>
> echo "
> ".
> $fullname."
> > href=\"show_profile.php?consumer_id=$cid&change=fullname\">
>
>
>
> ";
> }
> ?>
>
> width="780px">
>
>
>

> > width="10px">
>
>
>

> > cellspacing="0" width="780">
>
>
>
>
>
>
>
>
>
>

>
>
>

HBC Consumer Profile > H4>
>


>
 

> > cellpadding="10" cellspacing="0" >
>
> > action="show_profile.php" method="post">
> > name="pageaction" value="update">
> > name="consumer_id" value="">
>
>
>
>
> ------------------------------------------------------------ ------------------------------------------------------------ -----------------
>
> other similar options afterwards....

Re: Form Will Not Update MySQL DB

am 13.08.2007 13:31:16 von Frobinrobin

yeah agree with petersprc - seems you have the input name on the form
as 'fullname' but you are using $_REQUEST['consumer_fullname']??

The best way to solve ur own problem (and I make these silly mistakes
ALL the time) is to
a) echo your query to the page and try it directly in your database
b) use print_r($any_var); (with

 tags for formatting) to
see the contents of arrays (i.e. use print_r($_POST);)

Also I dont see how you are using the "$result_of_updated_file"
variable as the script doesnt show any conditional for it. Personally
I use the "mysql_affected_rows" function and a conditional:

if(mysql_affected_rows($result) > 0)
{
echo "success";
}
else
{
echo mysql_error();
}

Also I've just started using foreach($_POST) loop to validate the
whole post, as well as unset($_POST['input_name']) to remove unwanted
posts.. it's a really sweet way of running functions on all form
variables.

Re: Form Will Not Update MySQL DB

am 13.08.2007 14:08:46 von Jerry Stuckle

FrobinRobin wrote:
> yeah agree with petersprc - seems you have the input name on the form
> as 'fullname' but you are using $_REQUEST['consumer_fullname']??
>
> The best way to solve ur own problem (and I make these silly mistakes
> ALL the time) is to
> a) echo your query to the page and try it directly in your database
> b) use print_r($any_var); (with

 tags for formatting) to
> see the contents of arrays (i.e. use print_r($_POST);)
>
> Also I dont see how you are using the "$result_of_updated_file"
> variable as the script doesnt show any conditional for it. Personally
> I use the "mysql_affected_rows" function and a conditional:
>
> if(mysql_affected_rows($result) > 0)
> {
> echo "success";
> }
> else
> {
> echo mysql_error();
> }
>
> Also I've just started using foreach($_POST) loop to validate the
> whole post, as well as unset($_POST['input_name']) to remove unwanted
> posts.. it's a really sweet way of running functions on all form
> variables.
>

This is not necessarily accurate. If you update a row with the same
information that originally was in the row, MySQL will not change the
row (no need to, is there?), and mysql_affected_rows() will return zero.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Form Will Not Update MySQL DB

am 13.08.2007 14:12:40 von Jerry Stuckle

chrisv wrote:
> Hello everyone.
>
> I have a simple form that is designed to update a single database
> record at a time. It works fine until my pageaction variable is set
> to "update". The update conditional code doesn't execute. It is
> supposed to trigger an mysql record update using a predefined query.
> The username used to query the database has all privileges, so that
> isn't the problem. An suggestions? Here is the code:
>



When you say the code "doesn't execute", what do you mean? Do you
actually get there and the mysql_query fails, or don't you even get to
the code?

As others have noted, your $fullname should be $consumer_fullname, but
this should just put an empty (not null) value in the field. It should
also give you an E_NOTICE about using an undefined variable if you have
those on (highly recommended for a development system).

What is the return from mysql_query()? If it is false, what is the
message returned by mysql_error()?

Or, if you're not sure you get this far, try an echo statement right
before your query to ensure you got there.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Form Will Not Update MySQL DB

am 14.08.2007 11:48:59 von Frobinrobin

On Aug 13, 1:08 pm, Jerry Stuckle wrote:
> FrobinRobin wrote:
> > yeah agree with petersprc - seems you have the input name on the form
> > as 'fullname' but you are using $_REQUEST['consumer_fullname']??
>
> > The best way to solve ur own problem (and I make these silly mistakes
> > ALL the time) is to
> > a) echo your query to the page and try it directly in your database
> > b) use print_r($any_var); (with

 tags for formatting) to
> > see the contents of arrays (i.e. use print_r($_POST);)
>
> > Also I dont see how you are using the "$result_of_updated_file"
> > variable as the script doesnt show any conditional for it. Personally
> > I use the "mysql_affected_rows" function and a conditional:
>
> > if(mysql_affected_rows($result) > 0)
> > {
> > echo "success";
> > }
> > else
> > {
> > echo mysql_error();
> > }
>
> > Also I've just started using foreach($_POST) loop to validate the
> > whole post, as well as unset($_POST['input_name']) to remove unwanted
> > posts.. it's a really sweet way of running functions on all form
> > variables.
>
> This is not necessarily accurate. If you update a row with the same
> information that originally was in the row, MySQL will not change the
> row (no need to, is there?), and mysql_affected_rows() will return zero.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================- Hide quoted text -
>
> - Show quoted text -

Thats good to know! Thanks Jerry :)
Time to update my form validation then... lol

> bgcolor="#FFFF9D">
> Name: 
> >
> if($change ==
> "fullname"){
>
> echo
> " > maxlength=\"45\" size=\"15\">
>
> > \"submit\" value=\"Update\">";
> }else{
>
> echo "
> ".
> $fullname."
> > href=\"show_profile.php?consumer_id=$cid&change=fullname\">
>
>
>
> ";
> }
> ?>
>