Connecting Tech Pros Worldwide Help | Site Map

INSERT New Member in to DATABASE

Member
 
Join Date: Mar 2008
Posts: 34
#1: Mar 25 '08
Hi

I am trying to create a form for new member to create an account. There are 2 php files. File 1 [nuform.php] is a form where user can enter their data for registration purpose. File 2 [nm.php] sends typed data to database. My problem is I cann't send MySQL query to database to add a new account. Can any one help me.

file 1 'nuform.php'
Expand|Select|Wrap|Line Numbers
  1.  <html>
  2.  
  3. <title> Member Information</title>
  4. <?php
  5. echo
  6.      "<form action='nm.php' method='post'>
  7.     <p>Login Name  <input type='text' name='loginName'></p>
  8.      <p>Surname     <input type='text' name=Surname'></p>
  9.     <p>First Name  <input type='text' name='Firstname'></p>
  10.      <p>Select your Country</p>
  11.      <p><SELECT name="live"></p>
  12.      <p><option value="France">France</p>
  13.      <p><option value="Spain">Spain</p>
  14.      <p><option value="Australia">Australia</p>
  15.      <p><option value="United Kingdom">United Kingdom</p>
  16.      </SELECT>
  17.      <p><input type='Submit'></p>
  18.      </form>"
  19.  
  20. </html>
  21. ?>
  22.  
  23. file 2 'nm.php'
  24.  
  25. <?php
  26.  
  27.  
  28. $user="username";
  29. $host="localhost";
  30. $password="password";
  31. $database = "test";
  32.  
  33.  
  34. $connection = mysql_connect($host,$user,$password) //open connection to MySQL
  35.         or die ("couldn't connect to server");
  36.  
  37.  
  38. $db = mysql_select_db($database,$connection) // open session to Database
  39.         or die ("Couldn't select database");
  40.  
  41. $sql= "INSER INTO member (loginName, Surname, Firstname, live)values '".$_POST['loginName']." ".$_POST['Surname']." ".$_POST          ['Firstname']." ".$_POST['live']."'"
  42.  
  43. ?>
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#2: Mar 25 '08

re: INSERT New Member in to DATABASE


USe code tags to display code on this forum.

You don't need to insert your own numbers if you do this.

Thanks.
Member
 
Join Date: Mar 2008
Posts: 34
#3: Mar 25 '08

re: INSERT New Member in to DATABASE


Quote:

Originally Posted by markusn00b

USe code tags to display code on this forum.

You don't need to insert your own numbers if you do this.

Thanks.

thanks for telling me
ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#4: Mar 25 '08

re: INSERT New Member in to DATABASE


To debug this, echo the $sql statement before the insert so you can check that it is correct and change the mysql_query die part as[php]or die ("Couldn't execute query: ".mysql_error());[/php] and you will see any error.

Ronald
Member
 
Join Date: Mar 2008
Posts: 34
#5: Mar 25 '08

re: INSERT New Member in to DATABASE


Quote:

Originally Posted by ronverdonk

To debug this, echo the $sql statement before the insert so you can check that it is correct and change the mysql_query die part as[php]or die ("Couldn't execute query: ".mysql_error());[/php] and you will see any error.

Ronald


Thanks Ronverdonk... Its working now...
hsriat's Avatar
Expert
 
Join Date: Jan 2008
Location: Bath, UK
Posts: 1,609
#6: Mar 25 '08

re: INSERT New Member in to DATABASE


Line 41.
Use commas between the variables.

[EDIT]
Ignore this if you already solved.
Member
 
Join Date: Mar 2008
Posts: 34
#7: Mar 25 '08

re: INSERT New Member in to DATABASE


Quote:

Originally Posted by hsriat

Line 41.
Use commas between the variables.

[EDIT]
Ignore this if you already solved.


You are right, there were silly mistakes in line 41. Thanks for your help;

regards

Infoseekar
hsriat's Avatar
Expert
 
Join Date: Jan 2008
Location: Bath, UK
Posts: 1,609
#8: Mar 25 '08

re: INSERT New Member in to DATABASE


Quote:

Originally Posted by infoseekar

You are right, there were silly mistakes in line 41. Thanks for your help;

regards

Infoseekar

Also tell me, is the echo statement at line 5 working?
Member
 
Join Date: Mar 2008
Posts: 34
#9: Mar 25 '08

re: INSERT New Member in to DATABASE


Quote:

Originally Posted by hsriat

Also tell me, is the echo statement at line 5 working?

No, I have deleted that statement now..
hsriat's Avatar
Expert
 
Join Date: Jan 2008
Location: Bath, UK
Posts: 1,609
#10: Mar 25 '08

re: INSERT New Member in to DATABASE


Quote:

Originally Posted by infoseekar

No, I have deleted that statement now..

Use \" when you have to send a quote to the html.
eg.<SELECT name=\"live\">
Member
 
Join Date: Mar 2008
Posts: 34
#11: Mar 25 '08

re: INSERT New Member in to DATABASE


Quote:

Originally Posted by hsriat

Use \" when you have to send a quote to the html.
eg.<SELECT name=\"live\">


thank you very much.. you have been very helpful..
hsriat's Avatar
Expert
 
Join Date: Jan 2008
Location: Bath, UK
Posts: 1,609
#12: Mar 25 '08

re: INSERT New Member in to DATABASE


You are welcome. :)

Harpreet
Reply