INSERT New Member in to DATABASE | Member | | Join Date: Mar 2008
Posts: 34
| |
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' - <html>
-
-
<title> Member Information</title>
-
<?php
-
echo
-
"<form action='nm.php' method='post'>
-
<p>Login Name <input type='text' name='loginName'></p>
-
<p>Surname <input type='text' name=Surname'></p>
-
<p>First Name <input type='text' name='Firstname'></p>
-
<p>Select your Country</p>
-
<p><SELECT name="live"></p>
-
<p><option value="France">France</p>
-
<p><option value="Spain">Spain</p>
-
<p><option value="Australia">Australia</p>
-
<p><option value="United Kingdom">United Kingdom</p>
-
</SELECT>
-
<p><input type='Submit'></p>
-
</form>"
-
-
</html>
-
?>
-
-
file 2 'nm.php'
-
-
<?php
-
-
-
$user="username";
-
$host="localhost";
-
$password="password";
-
$database = "test";
-
-
-
$connection = mysql_connect($host,$user,$password) //open connection to MySQL
-
or die ("couldn't connect to server");
-
-
-
$db = mysql_select_db($database,$connection) // open session to Database
-
or die ("Couldn't select database");
-
-
$sql= "INSER INTO member (loginName, Surname, Firstname, live)values '".$_POST['loginName']." ".$_POST['Surname']." ".$_POST ['Firstname']." ".$_POST['live']."'"
-
-
?>
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | 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
| | | 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
|  | Moderator | | Join Date: Jul 2006 Location: The Netherlands
Posts: 4,139
| | | 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
| | | 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...
|  | Expert | | Join Date: Jan 2008 Location: Bath, UK
Posts: 1,609
| | | 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
| | | 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
|  | Expert | | Join Date: Jan 2008 Location: Bath, UK
Posts: 1,609
| | | 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
| | | 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..
|  | Expert | | Join Date: Jan 2008 Location: Bath, UK
Posts: 1,609
| | | 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
| | | 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..
|  | Expert | | Join Date: Jan 2008 Location: Bath, UK
Posts: 1,609
| | | re: INSERT New Member in to DATABASE
You are welcome. :)
Harpreet
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,358 network members.
|