Page 1 of 1

probably very simple, ADDED EXTRA QUESTION!

Posted: Mon Feb 09, 2009 3:42 am
by barrowvian

Code: Select all

 
<?php
    $query = "SELECT hex FROM style WHERE default=1";
    $result = mysql_query("$query", $connection);
    if(!$result){
        die("Database query failed: " . mysql_error());
    }
    while($row = mysql_fetch_array($result)){
        echo $row["hex"] . "<br />";
    }
?>
 
Everything else works fine, but when I run this I get the following error;

"Database query failed: 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 '=1' at line 1"

Now I understand what the failed message is saying, however I just cant see where Im going wrong with my SQL statement as I've used statements as trivial as this before without problems.

*******************************************************************

Right, now that the above is working I need to extend on it further;

Code: Select all

    if ($selected_radio == 'blue') {
        $query = "UPDATE style SET default_value = 1 WHERE name='$selected_radio'";
        $result = mysql_query("$query", $connection);
        if(!$result){die("SQL failed: " . mysql_error());}
 
My new issue is that when the user selects this radio button it will change the default_value to 1 - all well and good, however, if they then select another radio button then that default_value will also be set as 1 (ending up with 2 values set as 1). What I need to do is when a radio button is selected is change the selected default_value to 1 and the rest to 0.

I've not done much with SQL before so any insight as to the direction I need to take would be great.

Re: probably very simple, but I just cant see it

Posted: Mon Feb 09, 2009 3:46 am
by barrowvian
Nevermind.....just tried changing the field 'default' to 'default_value' and it decided to work 8O

Re: probably very simple, but I just cant see it

Posted: Mon Feb 09, 2009 4:09 am
by papa
Reserved name :)

Re: probably very simple, ADDED EXTRA QUESTION!

Posted: Mon Feb 09, 2009 6:19 pm
by barrowvian
please see edited first comments for new question