HI im trying to added extra fields to my register.php , but i keep getting a error message saying 'Error:user not added to database'

I've simply tried to edit the original code using the same methods used for the previous fields yet it still doesn't work. im sure my mysql database is setup fine i just think its got something to do with how i edited the code can somebody please help...thanks

Ive commented out the parts ive added with '!!!ADDED!!!' along side...hope somebody can help me.


Thanks

<?php
// dbConfig.php is a file that contains your
// database connection information. This
// tutorial assumes a connection is made from
// this existing file.
include ("_mmServerScripts/dbConfig.php");
 
 
//Input vaildation and the dbase code
if ( $_GET["op"] == "reg" )
 {
 $bInputFlag = false;
 foreach ( $_POST as $field )
  {
  if ($field == "")
   {
   $bInputFlag = false;
   }
  else
   {
   $bInputFlag = true;
   }
  }
 // If we had problems with the input, exit with error
 if ($bInputFlag == false)
  {
  die( "Problem with your registration info. "
   ."Please go back and try again.");
  }
 
 // Fields are clear, add user to database
 //  Setup query
 $q = "INSERT INTO `dbUsers` (`username`,`email`,`password`)"           /*`firstname`,`lastname`,`company`,) "        !!!ADDED!!! */
  ."VALUES ('".$_POST["username"]."', "
					  
  
  /*."VALUES ('".$_POST["firstname"]."', "   		CANT EXCUTE MORE FIELDS TO SAVE DATA				!!!ADDED!!!!
  ."VALUES ('".$_POST["lastname"]."', "
  ."VALUES ('".$_POST["company"]."', "*/
					  
					  
  ."PASSWORD('".$_POST["password"]."'), "
  ."'".$_POST["email"]."')";
 //  Run query
 $r = mysql_query($q);
 
 // Make sure query inserted user successfully
 if ( !mysql_insert_id() )
  {
  die("Error: User not added to database.");
  }
 else
  {
  // Redirect to thank you page.
Header("Location: register.php?op=thanks");
  }
 } // end if
 
 
//The thank you page
elseif ( $_GET["op"] == "thanks" )
 {
 echo "<h2> Thanks for registering!</h2> ";
 }
 
//The web form for input ability
else
 {
 echo "<form action=\"?op=reg\" method=\"POST\"> \n";
 echo "Username: <input name=\"username\" MAXLENGTH=\"16\"> <br /> \n";
 
 /*echo "First Name: <input name=\"firstname\" MAXLENGTH=\"16\"> <br /> \n";						!!!ADDED!!!
 echo "Last Name: <input name=\"lastname\" MAXLENGTH=\"16\"> <br /> \n";
 echo "Company: <input name=\"company\" MAXLENGTH=\"20\"> <br /> \n";*/
 
 echo "Password: <input type=\"password\" name=\"password\" MAXLENGTH=\"16\"> <br /> \n";
 echo "Email Address: <input name=\"email\" MAXLENGTH=\"25\"> <br /> \n";
 echo "<input type=\"submit\"> \n";
 echo "</form> \n";
 }
// EOF
?>

Recommended Answers

All 2 Replies

have you setup the additional rows in the database?

You should try posting this in the php section on the forum. You might have more success.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.