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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
"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) |
|
|||
|
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. |
|
|||
|
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 :). |
|
|||
|
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.) |
|
|||
|
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.) > |
|
|||
|
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()); |
|
|||
|
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(); |