[PHP + MySQL] SQL query incorrect?

Skilled Illusionist
Joined
Jul 1, 2007
Messages
367
Reaction score
1
I'm not sure but I think it's the query. MySQL is connected all fine, it just wont add this data to the database.
PHP:
	$input	= $_GET['x'];
	settype($input, "integer");
	
	if ($input == 1)
	{
		mysql_query("INSERT INTO `scores` (option) VALUES ('good')");
		out();
	}
	elseif ($input == 2)
	{
		mysql_query("INSERT INTO `scores` (option) VALUES ('bad')");
		out();
	}
	else
	{
		out();
	}

Thanks in advance for your help (:
 
Erm.. ok I don't have the slightest idea what RazorSword was trying to tell.. and learn indenting!

PHP:
    $input = $_GET['x'];
    
    if ($input == "1")
    {
        mysql_query("INSERT INTO `scores` (option) VALUES ('good')");
        out();
    }
    elseif ($input == "2")
    {
        mysql_query("INSERT INTO `scores` (option) VALUES ('bad')");
        out();
    }
    else
    {
        out();
    }

Why SetType?

Else do:
PHP:
    $input = $_GET['x'];
    
    switch($input)
    {
        case "1": $in = "good";
                        break;
        case "2": $in = "bad";
                        break;
        default: $in = "err";
                     break;
    }
    
    mysql_query("INSERT INTO `scores` (option) VALUES ('$in')");
    out();

Idk 100% about the switch statement, u'll get it I hope =']
 
I've fixed it, W3Schools showed me the way :)
Thanks to you's two for trying, though.

PHP:
	/* get vote */
	$input = $_GET['x'];
	settype($input, "integer");
	
	switch($input)
	{
		case 1:
			$op = 'good';
			break;
		case 2:
			$op = 'bad';
			break;
		default:
			out();
	}
	
	mysql_query("INSERT INTO `twilightv`.`scores` (`ID`, `option`) VALUES (NULL, '" . $op . "')");
 
Back