Jump to content

Help, something went wrong.


reportingsjr
 Share

Recommended Posts

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...