0

Hi everyone im learning phpmyadmin along with some php scripting. I need some help making the correct tables for the "phonebook" database of mine.

Here is the code for the members:

mysql_select_db ("phonebook"); 

$username=$_POST['username'];
$password=$_POST['password'];
$sqlQuery="insert into members  values(null,'$username' ,'$password' )" ;
$result=mysql_query($sqlQuery);  

include('index.php');

My question is how do i go about building the table and what fields do i create for it? thank you so much :D

Ivan
  • 2,463
  • 1
  • 20
  • 28
  • If you're starting to learn PHP, please **don't** learn the `mysql_*` functions. They are deprecated and shouldn't be used. Instead invest your time learning PDO. Please read [Why shouldn't I use mysql_* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) for more information. – Matt Raines May 24 '16 at 08:06
  • Go to phpmyadmin.Under 'phonebook' database create a table members which has 3 columns ie. id,username,password. id wil have data type of int and username,password will have datatype of varchar. Then go for the below insert query : "INSERT INTO `members `(`id`,`username`,`password`) VALUES (' ','".$username,'".$password."')"; – Suman Kalyan May 24 '16 at 08:18

1 Answers1

0

First you need to have a table in your database to store the information

You can use this query. First go to phpmyadmin -> select your database and you have a tab that says SQL, open this tab and paste this query

CREATE TABLE `phonebook` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `phone` varchar(250) DEFAULT NULL,
  `username` varchar(250) DEFAULT NULL,
  `password` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
);

Next you will need to make a connection to your database is your script. As a begginer you can do this like this.

$dbCon = mysqli_connect("localhost","root","password","database");

after the connection you will need a form. Do it this way.

<form action='' method='post'>
    Phone:<input type='text' name='phone'><br>
    Username:<input type='text' name='username'><br>
    Password:<input type='password' name='password'><br>
    <input type='submit' name='submit' value='save'>
</form>

after the form is submited you will need to take the data and insert to the DB

if(isset($_POST['submit'])){
    $phone = mysqli_real_escape_string($dbCon, $_POST['phone']);
    $username = mysqli_real_escape_string($dbCon, $_POST['username']);
    $password = mysqli_real_escape_string($dbCon, $_POST['password']);

    $sqlQuery = "insert into members (phone, username, password) values('$phone','$username','$password')" ;
    $result  =  mysqli_query($sqlQuery);
    if(!$result){
        echo mysqli_error();
    }

}

You have many many examples online just read them :)

Rafael Shkembi
  • 786
  • 6
  • 16
  • is it possible to remove the registration all together and set only 1 or 2 users to be able to login? like pre defined username and password because we wont be adding anymore users anyway. – Jürgen Walter Hof May 24 '16 at 10:37
  • To access this form you have to login to a system or it is available to all? – Rafael Shkembi May 24 '16 at 10:39
  • i would like to remove the registration form and leave the login form that i have already i just want to set only 2 people to be able to login and no option to add more. i can send you my files if you wish to have alook sir. – Jürgen Walter Hof May 24 '16 at 11:29
  • you can use many solutions for }this. The best way is to use a session to track every user, Lets say if($_SESSION['rafael']){ then allow this form}, or you use multiple computers you can track the with the ip address if the ip is 192.168.1.1 then allow the form – Rafael Shkembi May 24 '16 at 11:32
  • Just send me a link of your code and i will check it – Rafael Shkembi May 24 '16 at 11:45