Jump to content

pls help me

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
riyazbasha

riyazbasha

    Newbie

  • Members
  • Pip
  • 4 posts
Hi , I hve created register form which contains details of
(firstname,lastname,username,password,confirm password,email,confirm email,date of birth,gender,address,state,country.)
So my problem is i have simply registered to this form,there is no database shown of my these filled details where i have create tables in myphpadmin.

So pls say how to send register form filled details of users to database.

Iam using database.

waiting for ur reply.

#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
I guess you are using MySQL then.
do you know any SQL?

you need to write a Insert query and send it to your database with the information you want to store.

INSERT INTO tablename (fieldname1, fieldname2 [...], fieldnameN) VALUES (value1, value2, [...], valueN)

did this make it clearer to you?
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall

#3
mnmtanish

mnmtanish

    Newbie

  • Members
  • PipPip
  • 23 posts
I'll assume you are using PHP
First make an HTML Form

<form method="post" action="sql.php">

<input ......>

...

<input type="submit" ...>

</form>


Then make a simple php file

<?php

$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');

$firstname = $mysqli->real_escape_string($_POST['firstname']);

/* and the rest */

$country = $mysqli->real_escape_string($_POST['country']);

$mysqli->query("

INSERT INTO tablename (firstname, lastname, ... , country)

VALUES ( '$firstname' , '$lastname' , ... , '$country' )

");

header("Location: http://mydestination.com");

?>



#4
mnmtanish

mnmtanish

    Newbie

  • Members
  • PipPip
  • 23 posts
ALso checkout
PHP MySQL Insert Into

#5
selvaa89

selvaa89

    Newbie

  • Members
  • Pip
  • 3 posts
Hi,

First of all you must be sure of what method (get/post) you are using to submit form(In method attribute i.e,<form method="post" action="yourscript.php" />)
If you are using post method, you can access the data from $_POST[] array. ie, $firstname=$_POST['firstname'].
else you can get it from "$_GET[]" array.

Then you can create a dynamic query using the data you obtained from post or get array.

ie,
$query="insert into foo(firstname) values($firstname)";

then just pass the query to your DB.

Hope this will answer your question.

#6
chad

chad

    Learning Programmer

  • Members
  • PipPipPip
  • 68 posts
for that you must make sure you have the right names for your text boxes in your form
a simple example is this
<?php
mysql_connect('localhost','root','');
mysql_select_db('riyaz');

if($_REQUEST["Send"])
{
    $insert = mysql_query("INSERT INTO user_tbl set firstname = '".$_POST['firstname']."',
    lastname = '".$_POST['lastname']."'");

    # or you could use the other method

    $insert = mysql_query("INSERT INTO user_tbl (firstname,lastname) VALUES('".$_POST['firstname']."','".$_POST['lastname']."')");

    if($insert) { echo 'Successful'; }
    else { echo 'unsuccessfull'; }
}

# note that you must only choose one method i gave not both of them because that will do the query twice!
?>

<form action="" method="post">
<input type="text" name="firstname" size="30">
<input type="text" name="lastname" size="30">
<input type="submit" name="send" value="Send">
</form>

Edited by Orjan, 09 February 2010 - 07:27 AM.
Please use code tags when posting code!


#7
joyo

joyo

    Newbie

  • Members
  • PipPip
  • 17 posts
you should know how to get the date from the submit, and then , know how to insert into the mysql database .
just like upper reply.

#8
kailas

kailas

    Newbie

  • Members
  • PipPip
  • 17 posts
I think that there is nothing difficult in form contact with the database. There are many correct answers, and primary information can take on PHP form tutorials.

#9
webcodez

webcodez

    Programmer

  • Members
  • PipPipPipPip
  • 149 posts
As from your descriptions I assume you're using POST methods to send data ( by form input fields ). So an example would be:


<?php


if($_POST['submit']) { //submit button pressed? -> form data sent?


   mysql_connect("localhost", "root", "password"); //'host','username','password'

   mysql_select_db("database_name"0;


   $add_account = mysql_query("INSERT INTO accounts('username', 'password', 'field3')VALUES('".mysql_real_escape_string($_POST['username'])."', '".mysql_real_escape_string($_POST['password'])."', '".mysql_real_escape_string($_POST['user_input_field_3_name'])."') ")or die(mysql_error()); //replace accounts by the name of your table for register results-member accounts


}else{


// ?> ... show your form, in this example user input fields were named 'username' and 'password' <?php


}

?>


Very basic example. However for a more detailed explanation on this, and examples on creating register systems with forms & login systems as well, I'd advice you to have a look at my tutorial about creating a register system - if I'm allowed to reccomend this to you here ;)

Cheers.

Edited by webcodez, 16 February 2010 - 08:25 AM.