reportingsjr Posted April 5, 2006 Share Posted April 5, 2006 Okay, im trying to set up a forum with PHP (just a test one) and I did something wrong here. every time you put in the password and username it goes to this and half the code pops up!! Can you tell me what happened here?(ill bold where the code starts that shows up on the page) <?php$name = '$_POST['usrname']'$pwd = '$_POST['pwd']'// set database server access variables:$host = "localhost";$user = "root";$pass = "*cant give this*";$db = "forum";// open connection$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");//create query$query = "INSERT INTO `members` VALUE ( NULL,".$name."NULL".$pwd.");//execute query$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); //see if it workedif (mysql_num_rows($result) >[B] 0){ echo "Thank you for registering echo ".$name."! Your account has been created. Please go back and log in.";}else{echo "Sorry, account couldnt be created. Please come back and try again";}//free result memorymysql_free_result($result);//close connection to MySQLmysql_close($connection);?>[/B] All im trying to do is insert the persons username and password into a table called members in a database called forum.EDIT: from [b ] to [/b ] in the code is what shows up Link to comment Share on other sites More sharing options...
pulpfiction Posted April 5, 2006 Share Posted April 5, 2006 I am guessing the error is because of the below statement//create query$query = "INSERT INTO `members` VALUE ( NULL,".$name."NULL".$pwd.");Try changing it to this.. I guess this should work.$query = "INSERT INTO members VALUES(NULL,'$name',NULL,'$pwd')"; Link to comment Share on other sites More sharing options...
reportingsjr Posted April 5, 2006 Author Share Posted April 5, 2006 I hope it will. thank you for the help. Link to comment Share on other sites More sharing options...
reportingsjr Posted April 5, 2006 Author Share Posted April 5, 2006 No =[ didnt work. Link to comment Share on other sites More sharing options...
Little Goat Posted April 5, 2006 Share Posted April 5, 2006 I'm no php expert, but it looks like the php thought that the > right before it shows up on the page was supposed to end it. Link to comment Share on other sites More sharing options...
Selacius Posted April 6, 2006 Share Posted April 6, 2006 Fix this:$query = "INSERT INTO `members` VALUE ( NULL,".$name."NULL".$pwd.");Should be: $query = "INSERT INTO members VALUE (NULL, $name, NULL, $pwd)";That should work. Also, for this:echo "Thank you for registering echo ".$name."! Your account has been created. Please go back and log in.";You can make it just this:echo "Thank you for registering $name! Your account has been created. Please go back and log in.";No need for the second echo. Link to comment Share on other sites More sharing options...
reportingsjr Posted April 11, 2006 Author Share Posted April 11, 2006 selacius.. In PHP, putting variablea and text together doesnt work. thats why the periods are there. Link to comment Share on other sites More sharing options...
Selacius Posted April 11, 2006 Share Posted April 11, 2006 Wanna make a bet? I've done it on 90% of my website. Trust me, it works. http://ca.php.net/manual/en/function.echo.php Look at the examples. Link to comment Share on other sites More sharing options...
reportingsjr Posted April 11, 2006 Author Share Posted April 11, 2006 You can, you arent supposed to though. Link to comment Share on other sites More sharing options...
Chocolate570 Posted April 11, 2006 Share Posted April 11, 2006 Are you running this on a server or your own hard disk? If the latter, then most of it wont work. Link to comment Share on other sites More sharing options...
reportingsjr Posted April 11, 2006 Author Share Posted April 11, 2006 Oh, I guess thats why. Thank you chocolate (I am runnning on my hard disk). Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now