php - How to setup database for iOS app? -


i'm working on making ios app user have either login og create account (and afterwards login). need somehow connect database. database of type sql , created phpmyadmin in xampp. consist of 1 table called 'user' the attributes 'id', 'email' , 'password'. i've created 2 php script called signin.php , signup.php , placed in c:\xampp\htdoc directory can load script through localhost. here script signup:

<?php  $email = $_get['email']; $password1 = $_get['password1'];  $con=mysqli_connect("localhost","root","<mypassword>","app_db");  if (mysqli_connect_errno()) {   echo "failed connect mysql: " . mysqli_connect_error(); }  $sql = "insert user (email, password) values ('$email', '$password')";  if ($con->query($sql) === true) {     echo "new record created successfully"; } else {     echo "error: " . $sql . "<br>" . $conn->error; }  mysqli_close($con);  ?> 

to create new account write following browser: http://localhost/signup.php?email=youremail@something.com.dk&password=123456

my question is, if proper way it? i'm having hard time google right thing because dont know search for. appreciate , tell me if listed information isn't sufficient.

well, first of all:

you "have" use https not http or customers passwords fly through internet without protection.

also: user can sql injections on server. use code:

if($stmt = $mysqli->prepare("insert user (email, password) values (?, ?)")) {     $stmt->bind_param('ss',$email,$password); // variables of type string->s , ordered in way questionmarks in query!     $stmt->execute();     $affected_rows = $stmt->affected_rows;     $stmt->close();      if($affected_rows == 1)     {         echo "new record created successfully";     } } 

also shouldn't echo response out in 'plain test' return machine readable json app can display usefull results user.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -