In order to start with phpmysql, you need to reserve your hosting by signing up here
Second you need to create database using database wizard.
Thirdly, you need to create mysql table using this sql command:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET AUTOCOMMIT = 0; START TRANSACTION; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `hasanapi-313039c571` -- -- -------------------------------------------------------- -- -- Table structure for table `signup` -- CREATE TABLE `signup` ( `name` text NOT NULL, `email` text NOT NULL, `password` varchar(255) NOT NULL, `id` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Indexes for table `signup` -- ALTER TABLE `signup` ADD PRIMARY KEY (`id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `signup` -- ALTER TABLE `signup` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=38; COMMIT; |
Then you can create a php script by pasting the following script and modify the connection info:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
<?php session_start(); $link=mysqli_connect("shareddb-o.hosting.stackcp.net","api-313039c571","api276","api-313039c571"); if ($_POST['submit']=="Sign up") { if (!$_POST['email']){ $error.="<br />Please enter your email";} else if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){ $error.="<br />Please enter a valid email"; } if (!$_POST['password']){ $error.="<br />Please enter your password";} else { if (strlen($_POST['password'])<8){ $error.="<br />Please enter at least 8 characters";} if(!preg_match('/[A-Z]/', $_POST['password'])){ $error.= "<br />Please include min 1 capital letter";} } if ($error){ $error = "There were error(s) in your sign up details:".$error;} else { $query= "SELECT * FROM `signup` WHERE email ='".mysqli_real_escape_string($link, $_POST['email'])."'"; $result = mysqli_query($link, $query); $results = mysqli_num_rows($result); if ($results) $error = "That email is already registered. Do you want to log in?"; else { $query = "INSERT INTO `signup` (`email`, `password`) VALUES ('".mysqli_real_escape_string($link, $_POST['email'])."', '".md5(md5($_POST['email']).$_POST['password'])."')"; mysqli_query($link, $query); $success="You've been signed up!"; $_SESSION['id']= mysqli_insert_id($link); } } } if ($_POST['submit'] == "Log In") { $query = "SELECT * FROM `signup` WHERE email='".mysqli_real_escape_string($link, $_POST['loginemail'])."' AND password='" .md5(md5($_POST['loginemail']) .$_POST['loginpassword'])."' LIMIT 1"; $result = mysqli_query($link, $query); $row = mysqli_fetch_array($result); if($row){ $_SESSION['id']=$row['id']; echo "user logged in Session ID".$_SESSION['id']; } else { $error = "We could not find a user with that email and password. Please try again."; } } echo $error; ?> <form method="post"> <input type="email" name="email" id="email" value="<?php echo addslashes($_POST['email']); ?>" /> <input type="password" name="password" value="<?php echo addslashes($_POST['password']); ?>"/> <input type="submit" name="submit" value="Sign up"/> </form> <form method="post"> <input type="email" name="loginemail" id="loginemail" /> <input type="password" name="loginpassword" /> <input type="submit" name="submit" value="Log In"/> </form> |