Gazz1982 Posted June 5, 2008 Share Posted June 5, 2008 I'm trying to create a global variable inputted from a form with name="myusername" then use the variable in a sql query $sql="Select * from login where EMAIL='________' "; How would I do this? Link to comment https://forums.phpfreaks.com/topic/108870-adding-a-global-variable/ Share on other sites More sharing options...
discomatt Posted June 5, 2008 Share Posted June 5, 2008 Assuming the form method is POST... $_POST['myusername'] Link to comment https://forums.phpfreaks.com/topic/108870-adding-a-global-variable/#findComment-558458 Share on other sites More sharing options...
Gazz1982 Posted June 5, 2008 Author Share Posted June 5, 2008 so how would I utilise the varible in an sql query? Link to comment https://forums.phpfreaks.com/topic/108870-adding-a-global-variable/#findComment-558473 Share on other sites More sharing options...
silverblaze Posted June 5, 2008 Share Posted June 5, 2008 try using if ur form's action is post use this: $sql="Select * from login where EMAIL='$_POST[myusername]' "; if ur form's action is get use this: $sql="Select * from login where EMAIL='$_GET[myusername]' "; hope this will help... Link to comment https://forums.phpfreaks.com/topic/108870-adding-a-global-variable/#findComment-558476 Share on other sites More sharing options...
discomatt Posted June 5, 2008 Share Posted June 5, 2008 Also, make sure you sanitize the user input, so they can't inject bad SQL into your query $sql = 'SELECT `rows` FROM `login` WHERE `email` = \'' . mysql_real_escape_string( $_POST['myusername'] ) . '\''; Link to comment https://forums.phpfreaks.com/topic/108870-adding-a-global-variable/#findComment-558478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.