View Full Version : is there an error in this i am not seeing?
godofreality
05-21-2009, 06:07 AM
i have several queries run through a switch they all work except for this the switch syntax is all correct but for sum reason the code below is stubborn and won't work....
mysql_query("UPDATE style SET background = '$a', div = '$b', border = '$c', font_color = '$d' WHERE username = '$username'");
Old Pedant
05-21-2009, 06:23 AM
Well, not to ask a silly question, but did you DEBUG???
For example, did you write out the text of that query to make sure it's what you think it should be???
Maybe coding it thus:
$sql = "UPDATE style "
. " SET background = '$a', div = '$b', border = '$c', font_color = '$d' "
. " WHERE username = '$username'";
echo "DEBUG SQL: " . $sql . "<hr>";
mysql_query( $sql );
...
And excuse me, but I don't see any "switch" in there. What are you talking about??
godofreality
05-21-2009, 06:32 AM
the reason the switch isn't there is bcuz there is nothing wrong with the switch but since ur interested in seeing it here u go....
<?php
include('/home/lawlocau/public_html/session_control.php');
$username = $_POST['username'];
$mode = $_GET['mode'];
$a = $_POST['a'];
$b = $_POST['b'];
$c = $_POST['c'];
$d = $_POST['d'];
$e = $_POST['e'];
$f = $_POST['f'];
$g = $_POST['g'];
$h = $_POST['h'];
$i = $_POST['i'];
$j = $_POST['j'];
$k = $_POST['k'];
$l = $_POST['l'];
$m = $_POST['m'];
$n = $_POST['n'];
$o = $_POST['o'];
$p = $_POST['p'];
$q = $_POST['q'];
$r = $_POST['r'];
$s = $_POST['s'];
$t = $_POST['t'];
$con = mysql_connect("localhost","lawlocau_lawlo","default");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
switch($mode)
{
case 'style':
mysql_select_db("lawlocau_users", $con);
mysql_query("UPDATE style SET background = '$a', div = '$b', border = '$c', font_color = '$d' WHERE username = '$username'");
echo "makes it this far";
break;
case 'personal':
mysql_select_db("lawlocau_users", $con);
mysql_query("UPDATE personal SET name = '$a', location = '$b', age = '$c', gender = '$d', hobbies = '$e', interests = '$f', music = '$g', movies = '$h', others = '$i' WHERE username = '$username'");
break;
case 'contact':
mysql_select_db("lawlocau_users", $con);
mysql_query("UPDATE contact SET email = '$a', website_1 = '$b', website_2 = '$c', aim = '$d', yahoo = '$e', msn = '$f', xfire = '$g', other_label = '$h', other_value = '$i' WHERE username = '$username'");
break;
}
echo $mode . " " . $username . " " . $a . " " . $b . " " . $c . " " . $d . " " . $e . " " . $f . " " . $g . " " . $h . " " . $i . " " . $j . " " . $k . " " . $l . " " . $m . " " . $n . " " . $o . " " . $p . " " . $q . " " . $r . " " . $s . " " . $t;
?>
Old Pedant
05-21-2009, 06:48 AM
Gotcha. I thought you meant a switch that changed the values being passed to the *one* query. Didn't realize you meant multiple queries. Makes much more sense, now.
Well, I sure don't see it, so did you do the debug I suggested??
And if the debug looks right, did you then try executing the same query (as displayed in the debug) directly against the DB???
Old Pedant
05-21-2009, 06:52 AM
One remote possibility: Maybe the table name or one of the field names in that query is a reserved word in MySQL??? I don't see any obvious culprits, but you could always play it safe and enclose the table name and all field names in `...` (that's the back-tick character, same key as ~ on most keyboards).
$sql = "UPDATE `style` "
. " SET `background` = '$a', `div` = '$b', `border` = '$c', `font_color` = '$d' "
. " WHERE `username` = '$username'";
echo "DEBUG SQL: " . $sql . "<hr>";
mysql_query( $sql );
Surely overkill to use it on things like font_color, but it never hurts to use it.
godofreality
05-21-2009, 06:55 AM
yeah it looks identical to what i have there and all the values r passing to the sql properly but for sum reason the table just will not update with the data
godofreality
05-21-2009, 06:58 AM
lol ok this is messed up u know i had those originally but none of my other queries were working so i tried it without and they started working so i removed em all and that query stopped working now i readded those and it is working again.....
and this is why i hate coding
Fumigator
05-21-2009, 06:13 PM
You really need to error check your queries. It'll save you a ton of frustration. PHP does not error check MySQL queries automatically. And if you assign the query text to a variable, you can then easily echo out the query text which makes troubleshooting much less painful.
$query = "UPDATE style SET background = '$a', div = '$b', border = '$c', font_color = '$d' WHERE username = '$username'";
$result = mysql_query($query);
//error check it
if (!result) {
die("OH CRAP MY UPDATE ERRORED OUT! The query: $query<br />The error: ".mysql_error());
}
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.