LooieENG Posted August 12, 2008 Share Posted August 12, 2008 For example, how would I do this with single quotes? mysql_query("SELECT something FROM somewhere WHERE something = '$something'"); Also, where can I find a good, easy to understand tutorial for JOIN? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/119311-mysql-query-with-single-quotes/ Share on other sites More sharing options...
Jabop Posted August 12, 2008 Share Posted August 12, 2008 mysql_query("SELECT something FROM somewhere WHERE something = '".$something."'"); Quote Link to comment https://forums.phpfreaks.com/topic/119311-mysql-query-with-single-quotes/#findComment-614595 Share on other sites More sharing options...
LooieENG Posted August 12, 2008 Author Share Posted August 12, 2008 So I still need double quotes? Quote Link to comment https://forums.phpfreaks.com/topic/119311-mysql-query-with-single-quotes/#findComment-614596 Share on other sites More sharing options...
adam84 Posted August 12, 2008 Share Posted August 12, 2008 You can use single quotes. But if you have text, it would be a good idea to use the double quotes, so you can use a php escape method to prevent any harmful data being inserted into your database or doing some harmful stuff to your databse Quote Link to comment https://forums.phpfreaks.com/topic/119311-mysql-query-with-single-quotes/#findComment-614614 Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 How about we ask the simple question of why? >_> And there's a pretty good joins tutorial on the main PHPFreaks page by Daniel. Quote Link to comment https://forums.phpfreaks.com/topic/119311-mysql-query-with-single-quotes/#findComment-614618 Share on other sites More sharing options...
LooieENG Posted August 12, 2008 Author Share Posted August 12, 2008 ^^ I was just wondering. Another question, would this work, and if not, where do I put the quote marks on the md5 bit? mysql_query("INSERT INTO users ('username', 'password') VALUES ('$_POST[username]', md5('password')"); Quote Link to comment https://forums.phpfreaks.com/topic/119311-mysql-query-with-single-quotes/#findComment-614639 Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 ^^ I was just wondering. Another question, would this work, and if not, where do I put the quote marks on the md5 bit? mysql_query("INSERT INTO users ('username', 'password') VALUES ('$_POST[username]', md5('password')"); I'd personally try something like: $query = sprintf("INSERT INTO users(username, password) VALUES ('%1$s', '%2$s')", $_POST['username'], md5($password)); Quote Link to comment https://forums.phpfreaks.com/topic/119311-mysql-query-with-single-quotes/#findComment-614659 Share on other sites More sharing options...
akitchin Posted August 12, 2008 Share Posted August 12, 2008 you can also use MySQL's native MD5 hasher: mysql_query("INSERT INTO users ('username', 'password') VALUES ('{$_POST['username']}', MD5('{$_POST['password']}'))"); Quote Link to comment https://forums.phpfreaks.com/topic/119311-mysql-query-with-single-quotes/#findComment-614704 Share on other sites More sharing options...
DarkWater Posted August 12, 2008 Share Posted August 12, 2008 Indeed you could. Quote Link to comment https://forums.phpfreaks.com/topic/119311-mysql-query-with-single-quotes/#findComment-614713 Share on other sites More sharing options...
revraz Posted August 12, 2008 Share Posted August 12, 2008 Do you know the purpose of single and double quotes? You first post was correct and shouldn't need to be changed. So I still need double quotes? Quote Link to comment https://forums.phpfreaks.com/topic/119311-mysql-query-with-single-quotes/#findComment-614736 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.