/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] PHP MySQL UPDATE not working

Can someone let me know what I have wrong?

[code=php]
$busname = $_POST[‘busname’];
$busadd = $_POST[‘busadd’];
$buscity = $_POST[‘buscity’];
$busstate = $_POST[‘busstate’];
$buszip = $_POST[‘buszip’];
$busphone = $_POST[‘busphone’];
$url = $_POST[‘url’];
$catid = $_POST[‘catid’];
$typeid = $_POST[‘typeid’];
$busid = $_POST[‘busid’];

if(isset($url))
$website = 1;
else
$website = 0;

mysql_query(“UPDATE businesses SET busname = ‘$busname’ AND busadd = ‘$busadd’ AND buscity = ‘$buscity’ AND busstate = ‘$bustate’ AND buszip = ‘$buszip’ AND busphone = ‘$busphone’ AND website = ‘$website’ AND url = ‘$url’ AND catid = ‘$catid’ AND typeid = ‘$typeid WHERE busid = ‘$busid'”)
or die(mysql_error());
[/code]

I have also tried replacing the AND with commas and still no luck.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 07.2010 — Update syntax uses commas to separate column=value pairs:
<i>
</i>UPDATE table SET col1='val1', col2='val2', col3='val3' WHERE colx=123
Copy linkTweet thisAlerts:
@ChipzzzApr 07.2010 — In your query you have:

typeid = '$typeid

instead of:

typeid = '$typeid'

(missing the second " ' ")

It's always the little things that get you ? .

Have a nice day,

Chipzzz
Copy linkTweet thisAlerts:
@monarch_684authorApr 07.2010 — This is what I changed it to but nothing updates:

[code=php]mysql_query("UPDATE businesses SET busname='$busname', busadd='$busadd', buscity='$buscity', busstate='$bustate', buszip='$buszip', busphone='$busphone', website='$website', url='$url', catid='$catid', typeid='$typeid' WHERE busid = '$busid'")
or die(mysql_error());[/code]
Copy linkTweet thisAlerts:
@ChipzzzApr 07.2010 — I've never really trusted the " ' " in the context in which you are using them. If you are sure your $_POST array contains what you think it does and your mysql field names are all spelled correctly, I would try one of the following (the first is probably the least error-prone):
<i>
</i>mysql_query("UPDATE businesses SET busname='" . $busname . "', busadd='" . $busadd . "', buscity='" . $buscity . "', busstate='" . $bustate . "', buszip='" . $buszip . "', busphone='" . $busphone'" . ", website='" . $website . "', url='" . $url . "', catid='" . $catid'" . ", typeid='" . $typeid . "' WHERE busid = '" . $busid . "'")
or die(mysql_error());

Or else:
<i>
</i>mysql_query("UPDATE businesses SET busname="$busname", busadd="$busadd", buscity="$buscity", busstate="$bustate", buszip="$buszip", busphone="$busphone", website="$website", url="$url", catid="$catid", typeid="$typeid" WHERE busid = "$busid"")
or die(mysql_error());


Best of luck,

Chipzzz
Copy linkTweet thisAlerts:
@NogDogApr 07.2010 — You might want to verify that all the variables have the correct values, especially the one used in the where clause.
[code=php]
$query = "
UPDATE businesses
SET
busname='$busname',
busadd='$busadd',
buscity='$buscity',
busstate='$bustate',
buszip='$buszip',
busphone='$busphone',
website='$website',
url='$url',
catid='$catid',
typeid='$typeid'
WHERE busid = '$busid'
";
$result = mysql_query($query) or die(mysql_error()."<br />n$query");
if(mysql_affected_rows($result) == 0)
{
user_error("No rows updated<br />n$query");
}
[/code]
Copy linkTweet thisAlerts:
@monarch_684authorApr 07.2010 — Thanks everyone for the help. No one caught my mistake, but after looking at the code this morning, it was updating but it helps if I spell everything correctly......?. Here is the updated code that works.

[code=php]$busname = $_POST['busname'];
$busadd = $_POST['busadd'];
$buscity = $_POST['buscity'];
$busstate = $_POST['busstate'];
$buszip = $_POST['buszip'];
$busphone = $_POST['busphone'];
$url = $_POST['url'];
$catid = $_POST['catid'];
$typeid = $_POST['typeid'];
$busid = $_POST['busid'];

if(isset($url))
$website = 1;
else
$website = 0;

mysql_query("UPDATE businesses SET busname='$busname', busadd='$busadd', buscity='$buscity', busstate='$busstate', buszip='$buszip', busphone='$busphone', website='$website', url='$url', catid='$catid', typeid='$typeid' WHERE busid = '$busid'")
or die(mysql_error());[/code]
Copy linkTweet thisAlerts:
@fxrahulOct 12.2016 — Update syntax uses commas to separate column=value pairs:
<i>
</i>UPDATE table SET col1='val1', col2='val2', col3='val3' WHERE colx=123
[/QUOTE]


thankyou for the help
×

Success!

Help @monarch_684 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...