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; //---DELETE ENTRY FROM DATABASE--- should be //---UPDATE ENTRY IN DATABASE---...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

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

//---DELETE ENTRY FROM DATABASE---

should be

//---UPDATE ENTRY IN DATABASE---

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

This is the ouput for......

$query = "UPDATE calendar_events SET event_title = '" . $title . "',";

$query .= "event_start = " . $date . ", event_shortdesc = '".$desc."'";

$query .= " WHERE id = ". $event;


test2 2006-02-23 01:00:00 testYou have an error in your SQL syntax.
Check the manual that corresponds to your MySQL server version for the
right syntax to use near '01:00:00, event_shortdesc = 'test' WHERE id
=' at line 1

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

Versions of software being used:

MySQL v3.23.49
PHP v4.4.1

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

Lag wrote:
> This is the ouput for......
>
> $query = "UPDATE calendar_events SET event_title = '" . $title . "',";
>
> $query .= "event_start = " . $date . ", event_shortdesc = '".$desc."'";
>
> $query .= " WHERE id = ". $event;
>
>
> test2 2006-02-23 01:00:00 testYou have an error in your SQL syntax.
> Check the manual that corresponds to your MySQL server version for the
> right syntax to use near '01:00:00, event_shortdesc = 'test' WHERE id
> =' at line 1
>


It's telling you the same thing everyone else has been saying - although
not so clearly.

ALL non-numeric data MUST be within single quotes. And 01:00:00 is not
numeric data.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #15 (permalink)  
Old 02-24-2006
Lag
 
Posts: n/a
Default Re: QUERY AND UPDATE PROBLEM

I added a count ($count) to see if or how many rows were being
affected.............even though I am tagging them by id, which auto
increments for each new event. I am not selecting any row, even though
I know the id is correct. I went into the database to make sure.

This is the code and the result of running the code.

//---UPDATE ENTRY IN DATABASE---
$result = mysql_query("SELECT * FROM calendar_events WHERE
id='.$event'",$conn);
$count = mysql_num_rows($result);
$query = "UPDATE calendar_events SET event_title = '$title',
event_start = '$date', event_shortdesc = '$desc' WHERE id = '$result'";
mysql_query($query) or die(mysql_error());

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

echo "<br>Record Updated! Rows Affected: $count";
mysql_close();

?>

This is the result....

test2 2006-02-23 01:00:00 test
Record Updated! Rows Affected: 0

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

Sorry, I completely overlooked that..........I changed it and now am
getting this...............

You have an error in your SQL syntax. Check the manual that corresponds
to your MySQL server version for the right syntax to use near '' at
line 1.

Thanks for the help.

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

Lag wrote:
> I added a count ($count) to see if or how many rows were being
> affected.............even though I am tagging them by id, which auto
> increments for each new event. I am not selecting any row, even though
> I know the id is correct. I went into the database to make sure.
>
> This is the code and the result of running the code.
>
> //---UPDATE ENTRY IN DATABASE---
> $result = mysql_query("SELECT * FROM calendar_events WHERE
> id='.$event'",$conn);
> $count = mysql_num_rows($result);
> $query = "UPDATE calendar_events SET event_title = '$title',
> event_start = '$date', event_shortdesc = '$desc' WHERE id = '$result'";
> mysql_query($query) or die(mysql_error());
>
> //LIST ITEMS
> echo "$event $title $date $desc";
>
> echo "<br>Record Updated! Rows Affected: $count";
> mysql_close();
>
> ?>
>
> This is the result....
>
> test2 2006-02-23 01:00:00 test
> Record Updated! Rows Affected: 0
>


What is the type of column `id`? If it's numeric, then it should NOT be
in single quotes.

Also in your update statement $result is a result set, not an id. You
need to use "UPDATE calendar_events..... WHERE id= '$event'".

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #18 (permalink)  
Old 02-24-2006
Jerry Stuckle
 
Posts: n/a
Default Re: QUERY AND UPDATE PROBLEM

Lag wrote:
> Sorry, I completely overlooked that..........I changed it and now am
> getting this...............
>
> You have an error in your SQL syntax. Check the manual that corresponds
> to your MySQL server version for the right syntax to use near '' at
> line 1.
>
> Thanks for the help.
>


Echo your query before you run it to see if it's what you think it is.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #19 (permalink)  
Old 02-24-2006
noone
 
Posts: n/a
Default Re: QUERY AND UPDATE PROBLEM

Lag wrote:
> This is the ouput for......
>
> $query = "UPDATE calendar_events SET event_title = '" . $title . "',";
>
> $query .= "event_start = " . $date . ", event_shortdesc = '".$desc."'";
>
> $query .= " WHERE id = ". $event;
>
>
> test2 2006-02-23 01:00:00 testYou have an error in your SQL syntax.
> Check the manual that corresponds to your MySQL server version for the
> right syntax to use near '01:00:00, event_shortdesc = 'test' WHERE id
> =' at line 1
>


okay.. show us the entire script - remove any passwords, usernames etc...

add:

echo $query."<br>;

so we can see the query as the database sees it...

in
MySQL> show fields from calendar_events;

In your code, I do not see where you are selecting the data to see if it
changed or not (or are you doing this in MySql -- is so, copy/paste the
select statement and the result so we can see what you are doing.

Basic troubleshooting techniques -- make sure what you are contatenating
is what you think it should be...





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

What do you get when you run this code?

$query1 = "select * from calendar_events where id = '$event'";
$result = mysql_query($query1);
$data = mysql_fetch_assoc($result);
print "<pre>";
print_r($data);
print "</pre>";

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 12:21 PM.


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