I created a function and it does not work. After staring at it for 15 minutes trying it different ways, I can’t get it to work. Can anyone tell me what is wrong with my syntax? The variable $user_id is a number and $input is a string. I’m aware that mysql is deprecated and it is something I’m working on. I just want to know what is wrong with the sql, because after all it is a sql issue.
function insert_what_i_do( $user_id, $input)
{
if (mysql_result(mysql_query("SELECT `user_id` FROM `profile` WHERE `user_id` = $user_id"), 0) !== 1)
{
mysql_query("INSERT INTO `profile` (user_id, what_i_do) VALUES ($user_id, '$input')");
}
else
{
mysql_query("UPDATE `profile` SET `what_i_do` = '$input' WHERE `user_id` = $user_id");
}
};
This is with plain
MySQL, please take a good look on what I did there, and it’s not advisable to usemysql_*function anymore as they are deprecated. Note the quoted$input?You need to learn to use PDO: