Database not connected

After 14 day’s of suspend of my account I have learnt bit about forum and really I was per day check my account to access but…

In 14 day’s I tried to connect form submission with php database but it was not successful.

I am not master piece of this path. I means in developing but it my dream to create a simple login and signUp page.

Currently I am using FTP to upload my website where my hosting provider is 000webhost with free domain.

I watch too many youtube video for how to connect database but time I get unsuccessful.

Hope you all developer might you will help me.

Why I create this account? Because as you Know I am not Developer and I have not much money to hire a developer.

Here I thinks you all my teacher who help me as like student. You have all sea of knowledge about this code world and where I can create a login page in days you can do this in 15 minutes. Right…?

Let’s in topic…

I am not able to add form submission to my database.

Where I write down this code from youtube.

 

<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Template</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<style type="text/css">
</style>
<script>
// script needed before the DOM is loaded here
</script>
</head>
<body>
<form method="post" action="">

<table border="02" bgcolor="lightyellow">

<tr><td>Name:</td><td><input type="text" name="Name" ></td></tr>


<tr><td>DOB:</td><td><input type="text" name="DOB" ></td></tr>

<tr><td>Mobile Number:</td><td><input type="text" name="Mobile_Number" ></td></tr>

<tr><td>Email Address:</td><td><input type="text" name="Email_ID" ></td></tr>

<tr><td align="center" colspan="2"><input type="submit" name="Submit" value="Submit" ></td></tr>
</table>
</form>
<script>
// script that needs the DOM to be loaded here
</script>
</body>
</html>

<?php define('DB_HOST', 'localhost'); define('DB_NAME', 'id4915357_registration'); define('DB_USER','id4915357_registration'); define('DB_PASSWORD','Demo@123'); $con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error()); $db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error()); function NewUser() { $Name = $_POST['name']; $DOB = $_POST['DOB']; $Email_ID = $_POST['Email_ID']; $Mobile_Number = $_POST['Mobile_Number']; $query = "INSERT INTO websiteusers (Name,DOB,Email_ID,Mobile_Number) VALUES ('$Name','$DOB','$Email_ID','$Mobile_Number')"; $data = mysql_query ($query)or die(mysql_error()); if($data) { echo "YOUR REGISTRATION IS COMPLETED..."; } } function SignUp() { if(!empty($_POST['Mobile_Number'])) //checking the 'Mobile_Number' name which is from Sign-Up.html, is it empty or have some text { $query = mysql_query("SELECT * FROM websiteusers WHERE userName = '$_POST[Mobile_Number]' AND Email_ID = '$_POST[Email_ID]'") or die(mysql_error()); if(!$row = mysql_fetch_array($query) or die(mysql_error())) { newuser(); } else { echo "SORRY...YOU ARE ALREADY REGISTERED USER..."; } } } if(isset($_POST['submit'])) { SignUp(); } ?>

Where is my mistake…

Permitting to access this url https://databases.000webhost.com with UserID and password mention in code.

Demo url: https://mysoftweb2sms.000webhostapp.com/SIGNUP.PHP

No error show also.**

I can see a couple problems straight away. The HTML is not valid. The PHP is using the obsolete mysql_ functions. The table has no index.

I can only offer how I go about working something up. First I put a lot of thought into what the requirements are. I know things will change as I go along, but the more details I can anticipate ahead of time the better. For example

  • Web page displays form
    • Name input
    • DOB input
    • Mobile # input
    • Email address input
  • Submit sends HTTP request to server
  • Server validates and sanitizes user supplied values
  • Server inserts values into database table(s)
  • Todo ???

So far, this is a form that only collects and records values. If it is meant to do more than that, eg. register an account, create a log in session, etc. that remains to be worked out.

After I get an idea of the requirements, I put together valid HTML. Initially I do not worry about writing any CSS, JavaScript, or server-side code but concenrate on getting the HTML right. I start with a bare-bones template to keep things as simple as possible so I can focus on what I’m working on, putting my new HTML beneath the <h1>. eg.

<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Template</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<style type="text/css">
</style>
<script>
// script needed before the DOM is loaded here
</script>
</head>
<body>
<h1>Template</h1>
<script>
// script that needs the DOM to be loaded here
</script>
</body>
</html>

Then I paste it into the validator to make sure its all good.

My php is correct ?
Behalf of image?

The PHP is not correct and has a few problems.

I do not know what you mean by “behalf of image”.

The point is, I start with putting valid HTML together first. I am more than happy to walk you through the steps as I would do them. Please post your valid bare bones HTML code and not jump ahead to what needs to be done after what needs to be done first is done.

1 Like

I mean my Attachment images.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.