QUERY AND UPDATE PROBLEM

This is a discussion on QUERY AND UPDATE PROBLEM within the PHP Language forums, part of the PHP Programming Forums category; Having a problem updating my database from a web page, through a submission form. Can anyone help? ----THIS IS MY ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-23-2006
Lag
 
Posts: n/a
Default QUERY AND UPDATE PROBLEM

Having a problem updating my database from a web page, through a
submission form. Can anyone help?

----THIS IS MY CODE IN update.php----(user, pass, and database are
typed in directly, I changed them here for securiy reasons :) )

<?php

/*---CONNECT TO DATABASE---*/

$conn = mysql_connect("localhost", "user", "pass") or
die(mysql_error());
mysql_select_db("database",$conn) or die(mysql_error());

$event = $_GET["id"];
$title=$_POST['title'];
$date=$_POST['datetime'];
$desc=$_POST['desc'];

//---UPDATE ENTRY IN DATABASE---
$query = "UPDATE 'calendar_events' SET 'event_title' = '$title',
'event_start' = '$date', 'event_shortdesc' = '$desc' WHERE 'id' =
$event";

//LIST ITEMS
echo "$event $title $date $desc";

mysql_query($query);
echo "Record Updated";
mysql_close();

?>

-----------------------THIS IS THE
OUTPUT-------------------------------------
TEST changed 2006-02-22 06:00:00 TESTING EDITINGRecord Updated
--------------------------------------------------------------------------------------------
The original information was "TEST 2006-02-22 06:00:00 TESTING EDITING"
I changed "TEST" to "TEST changed" in the submit form on a previous
page.

I included the echo to see if my information was truly getting passed,
it is. I passed the id, title, event_start, and event_shortdesc from
the previous page where the submission form is located. Why isn't my
database entry (row) updating? Please help.

Reply With Quote
  #2 (permalink)  
Old 02-23-2006
Kimmo Laine
 
Posts: n/a
Default Re: QUERY AND UPDATE PROBLEM

"Lag" <lagoron@gmail.com> wrote in message
news:1140671438.716831.205800@u72g2000cwu.googlegr oups.com...
> Having a problem updating my database from a web page, through a
> submission form. Can anyone help?
>
> ----THIS IS MY CODE IN update.php----(user, pass, and database are
> typed in directly, I changed them here for securiy reasons :) )
>
> <?php
>
> /*---CONNECT TO DATABASE---*/
>
> $conn = mysql_connect("localhost", "user", "pass") or
> die(mysql_error());
> mysql_select_db("database",$conn) or die(mysql_error());
>
> $event = $_GET["id"];
> $title=$_POST['title'];
> $date=$_POST['datetime'];
> $desc=$_POST['desc'];
>
> //---UPDATE ENTRY IN DATABASE---
> $query = "UPDATE 'calendar_events' SET 'event_title' = '$title',
> 'event_start' = '$date', 'event_shortdesc' = '$desc' WHERE 'id' =
> $event";
>
> //LIST ITEMS
> echo "$event $title $date $desc";
>
> mysql_query($query)


put:
or die(mysql_error());
here and see what the problem is.

Debugging is a difficult skill to learn.

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)


Reply With Quote
  #3 (permalink)  
Old 02-23-2006
samudasu
 
Posts: n/a
Default Re: QUERY AND UPDATE PROBLEM

Don't quote the table name or field names. Only quote the variables for
example '$title'.

Reply With Quote
  #4 (permalink)  
Old 02-23-2006
Marcin Dobrucki
 
Posts: n/a
Default Re: QUERY AND UPDATE PROBLEM

Lag wrote:
> Having a problem updating my database from a web page, through a
> submission form. Can anyone help?
>
> ----THIS IS MY CODE IN update.php----(user, pass, and database are
> typed in directly, I changed them here for securiy reasons :) )
>
> <?php
>
> /*---CONNECT TO DATABASE---*/
>
> $conn = mysql_connect("localhost", "user", "pass") or
> die(mysql_error());
> mysql_select_db("database",$conn) or die(mysql_error());
>
> $event = $_GET["id"];
> $title=$_POST['title'];
> $date=$_POST['datetime'];
> $desc=$_POST['desc'];
>
> //---UPDATE ENTRY IN DATABASE---
> $query = "UPDATE 'calendar_events' SET 'event_title' = '$title',
> 'event_start' = '$date', 'event_shortdesc' = '$desc' WHERE 'id' =
> $event";
>
> //LIST ITEMS
> echo "$event $title $date $desc";
>
> mysql_query($query);
> echo "Record Updated";
> mysql_close();
>
> ?>


require_once ("DB.php"); // PEAR::DB
$db =& DB::connect(/*db params*/);

$fields = array ("event_title" => $title,
"event_start" => $date,
"event_shortdesc" => $desc);
$res = $db->autoExecute("calendar_events",$fields,
DB_AUTOQUERY_UPDATE,
"id = " . $event);
if (DB::isError($res)) die ($res->getMessage());
echo "Record updated";

With a small change you can also use the autoExecute for inserts with
just about identical code without repeating yourself.
Reply With Quote
  #5 (permalink)  
Old 02-23-2006
noone
 
Posts: n/a
Default Re: QUERY AND UPDATE PROBLEM

Lag wrote:
> Having a problem updating my database from a web page, through a
> submission form. Can anyone help?
>
> ----THIS IS MY CODE IN update.php----(user, pass, and database are
> typed in directly, I changed them here for securiy reasons :) )
>
> <?php
>
> /*---CONNECT TO DATABASE---*/
>
> $conn = mysql_connect("localhost", "user", "pass") or
> die(mysql_error());
> mysql_select_db("database",$conn) or die(mysql_error());
>
> $event = $_GET["id"];
> $title=$_POST['title'];
> $date=$_POST['datetime'];
> $desc=$_POST['desc'];
>
> //---UPDATE ENTRY IN DATABASE---
> $query = "UPDATE 'calendar_events' SET 'event_title' = '$title',
> 'event_start' = '$date', 'event_shortdesc' = '$desc' WHERE 'id' =
> $event";
>
> //LIST ITEMS
> echo "$event $title $date $desc";
>
> mysql_query($query);
> echo "Record Updated";
> mysql_close();
>
> ?>
>
> -----------------------THIS IS THE
> OUTPUT-------------------------------------
> TEST changed 2006-02-22 06:00:00 TESTING EDITINGRecord Updated
> --------------------------------------------------------------------------------------------
> The original information was "TEST 2006-02-22 06:00:00 TESTING EDITING"
> I changed "TEST" to "TEST changed" in the submit form on a previous
> page.
>
> I included the echo to see if my information was truly getting passed,
> it is. I passed the id, title, event_start, and event_shortdesc from
> the previous page where the submission form is located. Why isn't my
> database entry (row) updating? Please help.
>


Why are you quoting the table names. This is VERY POOR programming
style and the database name (depending on database engine) Will
interpret tablea and 'tablea' as two different tables. Database entity
names are case insensitive.

As someone that has been around databases for a very long time, do not
quote anything but text columns in the database - and then you must in
order for it to work :).
Reply With Quote
  #6 (permalink)  
Old 02-23-2006
Lag
 
Posts: n/a
Default Re: QUERY AND UPDATE PROBLEM

Thanks for the help......will try these things to get it to work.
Haven't been doing this long, php mysql programming, so yeah my code is
going to be bad and messy.......LOL.

Reply With Quote
  #7 (permalink)  
Old 02-24-2006
Lag
 
Posts: n/a
Default Re: QUERY AND UPDATE PROBLEM

I removed the quotes and the same thing still happens......the
variables are passed but the database doesn't update.
Any other help you can give would be appreciated.

CODE: $query = "UPDATE calendar_events SET event_title = $title,
event_start = $date, event_shortdesc = $desc WHERE id = $event" or
die(mysql_error());

OUTPUT: test 2006-02-23 01:00:00 testingRecord Updated.
(original information: test 2006-02-23 01:00:00 testRecord Updated.)

Reply With Quote
  #8 (permalink)  
Old 02-24-2006
noone
 
Posts: n/a
Default Re: QUERY AND UPDATE PROBLEM

Lag wrote:
> I removed the quotes and the same thing still happens......the
> variables are passed but the database doesn't update.
> Any other help you can give would be appreciated.
>
> CODE:


(modified for readability)

$query = "UPDATE calendar_events SET event_title = '" . $title . "',";
$query .= "event_start = " . $date . ", event_shortdesc = '".$desc."'";
$query .= " WHERE id = ". $event;

text should be enclosed in single quotes.
($title and $desc are text fields)

Can you give me the output of "show fields from calendar_events;"

You may also need to enclose the $date field....

or
die(mysql_error());
>
> OUTPUT: test 2006-02-23 01:00:00 testingRecord Updated.
> (original information: test 2006-02-23 01:00:00 testRecord Updated.)
>

Reply With Quote
  #9 (permalink)  
Old 02-24-2006
samudasu
 
Posts: n/a
Default Re: QUERY AND UPDATE PROBLEM

Like i said in my earlier post, quote the variables in the query.

$query = "UPDATE calendar_events SET event_title = '$title',
event_start = '$date', event_shortdesc = '$desc' WHERE id = '$event'";

This part, "or die(mysql_error())" is NOT part of the query. It should
be used like this:
mysql_query($query) or die(mysql_error());

Reply With Quote
  #10 (permalink)  
Old 02-24-2006
Lag
 
Posts: n/a
Default Re: QUERY AND UPDATE PROBLEM

I tried and it still passes the variables but does not update.....I
even tried using the root user and password, thinking I didn't update
the user privileges in MySQL server. But that didn't work either.
Thanks for the help, any other ideas?

$event = $_GET["id"];
$title=$_POST['title'];
$date=$_POST['datetime'];
$desc=$_POST['desc'];

//---DELETE ENTRY FROM DATABASE---
$query = "UPDATE calendar_events SET event_title = '$title',
event_start = '$date', event_shortdesc = '$desc' WHERE id = '$event'";

//LIST ITEMS
echo "$event $title $date $desc";

@mysql_query($query) or die(mysql_error());
echo "Record Updated";
mysql_close();

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:29 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0