Hi,
I must be missing something obvious.
I cannot get this function to run the update query on Line 6, although
the call to run the query evaluates true, and both update_cat_total
functions execute, while the function itself returns true.
A var_dump shows that all the variables are valid, and I can run the
exact same update query at the mysql command line without errors. I've
echoed mysql_error() before and after the call to mysql_query() and no
errors show up.
But the update itself never runs! Can anyone see why?
function new_category($category_id=null) {
global $category_id_new;
if (create_category($_SESSION['cat_name'])) {
// update this page with the new category_id
$query = "UPDATE
about
SET
category_id = $category_id_new
WHERE
about_id = $_SESSION[about_id]";
if ($result = mysql_query($query)) {
if (update_cat_total('add', $category_id_new) &&
update_cat_total('remove', $category_id)) {
return true;
}
else {
return false;
}
}
else {
return false;
}
}
else {
return false;
}
}
Thanks
J Moore 11 2150
>$query = "UPDATE about SET category_id = $category_id_new WHERE about_id = $_SESSION[about_id]";
I think you want "about_id = $_SESSION['about_id']"; (notice the quotes
around 'about_id'). To be safe, you can also write it like this:
$query = "UPDATE about SET catergory_id = $catergory_id_new
WHERE about_id = " . $_SESSION['about_id'];
John Moore wrote: $query = "UPDATE about SET category_id = $category_id_new WHERE about_id = $_SESSION[about_id]";
You can't use multi-line strings like that in PHP. I presume in your code
it is actually written:
$query = "UPDATE about SET category_id = $category_id_new WHERE about_id = $_SESSION[about_id]";
Then you can't use array values like that in strings. Zeldor was partly
right that it needs quotes around the key (because that is a string, not a
constant), but it also needs curly braces around the whole name if you are
going to use it inside the string:
$query = "... about_id = {$_SESSION['about_id']}";
For goodness sake, see http://php.net/manual/en/language.ty...string.parsing
--
E. Dronkert
I use multi-line strings like that all the time. Obviously I use curly
braces, quotes etc correctly (by the second or third attempt) but
there's nothing to stop you using lines like
db_query("CREATE TABLE {$sys['test_db_table_prefix']}idx (
idx_uid MEDIUMINT NOT NULL AUTO_INCREMENT,
idx_added_user VARCHAR(255),
idx_added_dtm DATETIME,
idx_type VARCHAR(255),
idx_category VARCHAR(255),
idx_subcat VARCHAR(255),
idx_name VARCHAR(255),
idx_company VARCHAR(255),
idx_phone VARCHAR(255),
idx_email VARCHAR(255),
idx_street VARCHAR(255),
idx_area VARCHAR(255),
idx_town VARCHAR(255),
idx_near VARCHAR(255),
idx_region VARCHAR(255),
idx_country VARCHAR(255),
idx_area_search VARCHAR(255),
idx_skill_search VARCHAR(255),
idx_other1 VARCHAR(255),
idx_other2 VARCHAR(255),
idx_other3 VARCHAR(255),
idx_other4 VARCHAR(255),
idx_other5 VARCHAR(255),
idx_other6 VARCHAR(255),
idx_other7 VARCHAR(255),
idx_other8 VARCHAR(255),
PRIMARY KEY (idx_uid)
)
");
Of course, it doesn't usually wrap like that
On Mon, 31 Oct 2005 09:54:48 +0100, in comp.lang.php Ewoud Dronkert
<fi*******@lastname.net.invalid> wrote: John Moore wrote: $query = "UPDATE about SET category_id = $category_id_new WHERE about_id = $_SESSION[about_id]";
You can't use multi-line strings like that in PHP. I presume in your code it is actually written:
$query = "UPDATE about SET category_id = $category_id_new WHERE about_id = $_SESSION[about_id]";
Then you can't use array values like that in strings. Zeldor was partly right that it needs quotes around the key (because that is a string, not a constant), but it also needs curly braces around the whole name if you are going to use it inside the string:
$query = "... about_id = {$_SESSION['about_id']}";
For goodness sake, see http://php.net/manual/en/language.ty...string.parsing
Thanks,
I changed the query to read like this:
$query = "UPDATE about SET category_id = $category_id_new WHERE
about_id = {$_SESSION['about_id']}";
All on one single line.
But no dice- no update occurs! I've echoed out the query itself, and
the variables are showing up as they should:
UPDATE about SET category_id = 31 WHERE about_id = 5
I wrote this function to execute 2 more functions IF this query
evaluates true. Both these functions are executing, but the
category_id field is not updating.
I dont mind rewriting my code, but I wish I could understand why when
it doesn't work as expected.
Thanks to all of you for trying to help.
J Moore
Try something along the lines of
$result = mysql_query($sql) or die("<br />Could not run query $sql
Reason: " . mysql_error());
to find out what it's complaining about.
($result = mysql_query($query)) will always return true even if the
query fails.
Ian
>But no dice- no update occurs! I've echoed out the query itself, and the variables are showing up as they should:
UPDATE about SET category_id = 31 WHERE about_id = 5
Did you try taking the query that get's echoed out and pasting into
some other MySQL client (i.e. the command line version) ?
On 31 Oct 2005 05:46:12 -0800, in comp.lang.php "Ian B"
<ia********@gmail.com> wrote: Try something along the lines of
$result = mysql_query($sql) or die("<br />Could not run query $sql Reason: " . mysql_error());
to find out what it's complaining about.
Thanks Ian,
I just tried your suggestion, calling the query like this:
$result = mysql_query($query) or die("<br>Could not run query $sql
Reason: " . mysql_error());
But the script didn't die, the function continued to execute, and no
update took place.
($result = mysql_query($query)) will always return true even if the query fails.
Ian
I tested the result like this:
if ($result) {
// keep doing stuff
}
else {
return false;
}
Here is the current version of this function:
function new_category2($category_id=null) {
global $category_id_new;
if (create_category($_SESSION['cat_name'])) {
// update this page with the new category_id
$query = "UPDATE about SET category_id = $category_id_new WHERE
about_id = {$_SESSION['about_id']}";
$result = mysql_query($query) or die("<br>Could not run query $sql
Reason: " . mysql_error());
if ($result) {
// both new and old categories must be updated to reflect new
totals
if (update_cat_total('add', $category_id_new) &&
update_cat_total('remove', $category_id)) {
return true;
}
else {
return false;
}
}
else {
return false;
}
}
else {
return false;
}
}
I'm going to try this under a different operating system. I'm just not
understanding why the update wouldn't occur here. This is PHP 4.4.3
running mysql 4.0.16-nt on Apache 1.3.24.
What kills me is that the update_cat_total() function updates a
different table using the exact same syntax for the query- and updates
the field every time.
Thanks again,
J Moore
On 31 Oct 2005 06:31:42 -0800, in comp.lang.php "ZeldorBlat"
<ze********@gmail.com> wrote: Did you try taking the query that get's echoed out and pasting into some other MySQL client (i.e. the command line version) ?
Thanks,
Yeah- I'm keeping the client open so I can run the update manually as
needed. Every time this update fails, it throws my totals off, so I
have to update manually every time I run the script. I'm up to my 35th
try now.
J Moore
Another thought...
Have you actually got an about_id equal to 5 (or whatever) because if
you haven't, then the query will not raise an error but also not update
anything.
and is about_id numeric? (Off the top of my head, I'm not sure what
you'd get if it was a VARCHAR, but it's easier for you to check than
for me to test :-)
Ian
On 31 Oct 2005 06:58:49 -0800, in comp.lang.php "Ian B"
<ia********@gmail.com> wrote: Another thought...
Have you actually got an about_id equal to 5 (or whatever) because if you haven't, then the query will not raise an error but also not update anything.
and is about_id numeric? (Off the top of my head, I'm not sure what you'd get if it was a VARCHAR, but it's easier for you to check than for me to test :-)
Ian
Hi Ian,
All the id fields are int.
But I just found a problem with my global variable at the beginning of
the function. I'm going to get rid of it and try to add that variable
as a parameter.
I think the update is running, it's the variable that isn't changing.
Thanks again,
J Moore This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Penn Markham |
last post by:
Hello all,
I am writing a script where I need to use the system() function to call
htpasswd. I can do this just fine on the command line...works great
(see attached file, test.php). When my...
|
by: Highlander416 |
last post by:
This is driving me crazy.
I need to create a UDF that would return a TRUE/FALSE (bit) value based
on a comparison it does.
CREATE FUNCTION dbo.SelectedByApplication
(
@ApplicationID int,...
|
by: laredotornado |
last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to
have my Javascript function execute from the BODY's "onload" method,
but if there is already an onload method defined, I would...
|
by: Raphael Bauduin |
last post by:
Hi,
I'm looking at the logging of a database we'll put in production soon.
I've seen some posts on this list about history tables, like mentioned in...
|
by: Mr Newbie |
last post by:
I am often in the situation where I want to act on the result of a function,
but a simple boolean is not enough. For example, I may have a function
called
isAuthorised ( User, Action ) as ?????...
|
by: sara |
last post by:
I am trying my first functions in my code. I have a set of queries
that runs to create temp tables with the right data for some reports.
They can run for a long time, so I want the user to know...
|
by: pbmods |
last post by:
AN INTRODUCTION TO FUNCTION OBJECTS
LEVEL: INTERMEDIATE
PREREQS: OBJECTS
You've seen it before. You're setting up an XMLHttpRequest call, and you need to execute a function when it returns, so...
|
by: souporpower |
last post by:
Hello All
I am trying to activate a link using Jquery. Here is my code;
<html>
<head>
<script type="text/javascript" src="../../resources/js/
jquery-1.2.6.js"</script>
<script...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
| |