zeeshan Posted March 11, 2008 Share Posted March 11, 2008 what is the problem in this script<?phpfunction usernameTaken($username){ global $conn; if(!get_magic_quotes_gpc()){ $username = addslashes($username); } $q = "select username from info = '$username'"; $result = mysql_query($q,$conn); return (mysql_numrows($result) > 0);$con = mysql_connect("localhost","tutkings_zxq_net_z","computer");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("tutkings_zxq_net_info", $con);$sql="INSERT INTO info (username,password,confirmpassword,email)VALUES('$_POST[username]','$_POST[password]','$_POST[confirmpassword]','$_POST[email]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "you username has been added,Sucessfully now you can log in";mysql_close($con)?> Link to comment Share on other sites More sharing options...
Wander Posted March 11, 2008 Share Posted March 11, 2008 u forgot the } at the end of the function (below return) Link to comment Share on other sites More sharing options...
Peppe L-G Posted March 11, 2008 Share Posted March 11, 2008 $q = "select username from info = '$username'"; That's an incorrect question, I think. It should look like this:"SELECT this_column FROM this_table WHERE this_column = 'this_value'" If you use mysql_error you will properly get an error message: mysql_query($sql) or die(mysql_error()); Link to comment Share on other sites More sharing options...
zeeshan Posted March 11, 2008 Author Share Posted March 11, 2008 ok i will edit it and tell u is it works or not as some one said where should i add this "}" Link to comment Share on other sites More sharing options...
justsomeguy Posted March 11, 2008 Share Posted March 11, 2008 I'm working on my English, so if I use the language wrong, tell me please, or I will never be better. That's an incorrect question, I think. It should look like this:Even though they are exact synonyms (mean the same thing), when we refer to SQL statements we call them "queries" instead of "questions".ok i will edit it and tell u is it works or not as some one said where should i add this "}"Add it after the return statement. A return statement stops the function, so that's where you should put the closing bracket. Link to comment Share on other sites More sharing options...
Peppe L-G Posted March 11, 2008 Share Posted March 11, 2008 Even though they are exact synonyms (mean the same thing), when we refer to SQL statements we call them "queries" instead of "questions".Ohh... I should have figured that out (mysql_query etc.), but thanks.And zeeshan, if you read the reply from Wander carefully, you'll see that he mentioned where. Link to comment Share on other sites More sharing options...
zeeshan Posted March 11, 2008 Author Share Posted March 11, 2008 here is the edited script but it is giving me this message on the browserphrase errror:problem in the script called insert.php the below is the insert.php script <?php$con = mysql_connect("localhost","tutkings_zxq_net_z","computer");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("tutkings_zxq_net_info", $con);$sql="INSERT INTO info (username,password,confirmpassword,email)VALUES('$_POST[username]','$_POST[password]','$_POST[confirmpassword]','$_POST[email]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "you username has been added,Sucessfully now you can log in";mysql_close($con)function usernameTaken($username){ global $conn; if(!get_magic_quotes_gpc()){ $username = addslashes($username); } $q = "select username from users where username = '$username'"; $result = mysql_query($q,$conn); return (mysql_numrows($result) > 0);}?> Link to comment Share on other sites More sharing options...
justsomeguy Posted March 11, 2008 Share Posted March 11, 2008 You're missing a semicolon after this line:mysql_close($con)Also, you're never actually using the usernametaken function. You only define it. Link to comment Share on other sites More sharing options...
zeeshan Posted March 11, 2008 Author Share Posted March 11, 2008 what i did not get u at ur last line Also, you're never actually using the usernametaken function. You only define it. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 11, 2008 Share Posted March 11, 2008 You never use the function. You define the function, you say what it is, but you don't use it. You don't actually check if the username is taken, you only set up a function that will do that if you actually use it, but you don't use it. You'll probably want to read through at least the language reference, read from "basic syntax" up through "functions". You might also be able to read in your native language.http://www.php.net/manual/en/langref.phpBut you're going to need to learn how to use PHP before you actually try to use it. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.