/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Is there anything wrong with this sql update?

[code=php]//sanitize inputs
$userid = mysql_real_escape_string($user_username); // mysql_real_escape_string() needs to be called before mysql_query()

//MySQL Query
$q = “UPDATE table2purchstats SET userid = ‘{$userid}’, purchstat_a = ‘{$purchstat_a}’, purchstat_b = ‘{$purchstat_b}’, purchstat_c = ‘{$purchstat_c}’, purchstat_d = ‘{$purchstat_d}’, purchstat_e = ‘{$purchstat_e}’, purchstat_f = ‘{$purchstat_f}’, purchstat_g = ‘{$purchstat_g}’, purchstat_h = ‘{$purchstat_h}’, purchstat_i = ‘{$purchstat_i}’, purchstat_j = ‘{$purchstat_j}’, purchstat_k = ‘{$purchstat_k}’, purchstat_l = ‘{$purchstat_l}’, purchstat_m = ‘{$purchstat_m}’, purchstat_n = ‘{$purchstat_n}’, purchstat_o = ‘{$purchstat_o}’, purchstat_p = ‘{$purchstat_p}’, purchstat_q = ‘{$purchstat_q}’, purchstat_r = ‘{$purchstat_r}’, purchstat_s = ‘{$purchstat_s}’, purchstat_t = ‘{$purchstat_t}’, purchstat_u = ‘{$purchstat_u}’, purchstat_v = ‘{$purchstat_v}'”;
// Uncomment this next line if you have trouble with your MySQL syntax.
//exit(“<pre style=’font:normal 10pt sans-serif;’>$q</pre>”);
$sqlResult = mysql_query($q, $link) or die( __LINE__.’ ‘.mysql_error() );
}

// Equal to 1 or should it be greater than zero?
//if ( 0 < mysql_affected_rows($sqlResult) ) {
if (mysql_affected_rows($sqlResult) == 1) {
echo “success”;
} else {
echo”failure”;
}
[/code]

I am getting this error:

Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /…/congrats.php on line 98

Line 98:

[code=php]
if (mysql_affected_rows($sqlResult) == 1) {
[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@Design-is-BSauthorMay 26.2008 — I was able to get rid of the error, but it still won't update:

[code=php]

//sanitize inputs
$userid = mysql_real_escape_string($user_username); // mysql_real_escape_string() needs to be called before mysql_query()

//MySQL Query
$q = "UPDATE table2purchstats SET userid = '{$userid}', purchstat_a = '{$purchstat_a}', purchstat_b = '{$purchstat_b}', purchstat_c = '{$purchstat_c}', purchstat_d = '{$purchstat_d}', purchstat_e = '{$purchstat_e}', purchstat_f = '{$purchstat_f}', purchstat_g = '{$purchstat_g}', purchstat_h = '{$purchstat_h}', purchstat_i = '{$purchstat_i}', purchstat_j = '{$purchstat_j}', purchstat_k = '{$purchstat_k}', purchstat_l = '{$purchstat_l}', purchstat_m = '{$purchstat_m}', purchstat_n = '{$purchstat_n}', purchstat_o = '{$purchstat_o}', purchstat_p = '{$purchstat_p}', purchstat_q = '{$purchstat_q}', purchstat_r = '{$purchstat_r}', purchstat_s = '{$purchstat_s}', purchstat_t = '{$purchstat_t}', purchstat_u = '{$purchstat_u}', purchstat_v = '{$purchstat_v}'";
//Uncomment this next line if you have trouble with your MySQL syntax.
//exit("<pre style='font:normal 10pt sans-serif;'>$q</pre>");
$sqlResult = mysql_query($q, $link) or die( __LINE__.' '.mysql_error() );
}

// Equal to 1 or should it be greater than zero?
//if ( 0 < mysql_affected_rows($sqlResult) ) {
if (mysql_affected_rows() == 1) {
echo "success";
} else {
echo"failure";
}
[/code]
Copy linkTweet thisAlerts:
@Design-is-BSauthorMay 26.2008 — This is the line being submitted though MySQL, seems fine to me..:

UPDATE table2purchstats SET userid = 'brian.senchak', purchstat_a = '1', purchstat_b = '0', purchstat_c = '0', purchstat_d = '0', purchstat_e = '0', purchstat_f = '0', purchstat_g = '0', purchstat_h = '0', purchstat_i = '0', purchstat_j = '0', purchstat_k = '0', purchstat_l = '0', purchstat_m = '0', purchstat_n = '0', purchstat_o = '0', purchstat_p = '0', purchstat_q = '0', purchstat_r = '0', purchstat_s = '1', purchstat_t = '1', purchstat_u = '1', purchstat_v = '1'

1 = checked

0 = unchecked
Copy linkTweet thisAlerts:
@Design-is-BSauthorMay 26.2008 — Should have been using an INSERT rather than UPDATE.
×

Success!

Help @Design-is-BS 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.19,
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,
)...