probably very simple, ADDED EXTRA QUESTION!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
barrowvian
Forum Commoner
Posts: 47
Joined: Tue Aug 19, 2008 3:49 pm

probably very simple, ADDED EXTRA QUESTION!

Post 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.
Last edited by barrowvian on Mon Feb 09, 2009 2:58 pm, edited 1 time in total.
barrowvian
Forum Commoner
Posts: 47
Joined: Tue Aug 19, 2008 3:49 pm

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

Post by barrowvian »

Nevermind.....just tried changing the field 'default' to 'default_value' and it decided to work 8O
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

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

Post by papa »

Reserved name :)
barrowvian
Forum Commoner
Posts: 47
Joined: Tue Aug 19, 2008 3:49 pm

Re: probably very simple, ADDED EXTRA QUESTION!

Post by barrowvian »

please see edited first comments for new question
Post Reply