Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I built a database with the attached tables using MySQL, Now I need to be able to use Javascript to connect to the server to insert and pull data. For example, when I'm creating a user account, after the information has been inputted in the HTML and collected using Javascript, I need to able to store the user information, and later when I need to display orders, I need to be able to pull all orders with a specific OrderStatus to show in a table.

I need to first be able to show how to do this locally, which should be the easier task, and then over online if possible.

I built the data with my MySQL workbench 6.3, but I don't know how to connect it to the web pages that I already have, I'm also wondering if SQL Server will work better than MySQL? In addition, What is the best server that I could in my case which will allow me to use the server from any laptop or workstation instead of having it locally?

Please I need some feedback on this so I could be directed in the right way and save some time to work on finishing this web page.

Below is the code for creating an account, and I need to test this code on a database and make sure that it is connecting right.

What I have tried:

<!DOCTYPE html>
<html>

<head>
<title>Create an user account</title>
<link rel="stylesheet" href="create_user_account.css">
</head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">


<!--bootstrap installation-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>



<body>


<!--title bar-->
<div class="jumbotron jumbotron-fluid bg-warning text-white" style="background: #aaa;">
	<div class="container">
		<h1 class="display-3">ZEN Restaurant</h1>
		<p class="lead">For your breakfast, lunch and dinner</p>
	</div>
</div>
    
            
<!--entry fields-->
<div class="container-fluid">

<div class="row">

    <div class="col-12">
        <div class="card">
            <div class="card-body">
                  <div class="border-bottom font-size-menuCat">Create an user account</div>
                <br><br/>
                
				<div class="row">
                    <div class="col-sm-3 col-md-2">
                        <p class="font-card-info">Username</p>
                    </div>
                    <div class="col-sm-3 col-md-4">
                        <input type="text" class="form-control" style="height:50px" id="account_username"/>
						<p><small class="form-text text-muted">Username must have more than 6 characters, less than 30 characters, and contain both letters and numbers.</small></p>
                    </div>
					
					<div class="col-sm-3 col-md-2">
                        <p class="font-card-info">Password</p>
                    </div>
                    <div class="col-sm-3 col-md-4">
                        <input type="text" class="form-control" style="height:50px" id="account_password"/>
						<p><small class="form-text text-muted">Password must have more than 6 characters, less than 20 characters, and contain both uppercase letters, lowercase letters, and numbers.</small></p>
                    </div>
                </div>
					
                <div class="row">
                    <div class="col-sm-3 col-md-2">
                        <p class="font-card-info">First Name</p>
                    </div>
                    <div class="col-sm-3 col-md-4">
                        <input type="text" class="form-control" style="height:50px" id="account_firstName"/>
                    </div>
         
                    <div class="col-sm-3 col-md-2">
                        <p class="font-card-info">Last Name</p>
                    </div>
                    <div class="col-sm-3 col-md-4">
                        <input type="text" class="form-control" style="height:50px" id="account_lastName"/>
                    </div>
                </div>
                
                
                <div class="row">
                    <div class="col-sm-3 col-md-2">
                        <p class="font-card-info">Address</p>
                    </div>
                    <div class="col-sm-3 col-md-4">
                        <input type="text" class="form-control" style="height:50px" id="account_deliveryAddress"/>
                    </div>
					
                    <div class="col-sm-3 col-md-2">
                        <p class="font-card-info">City</p>
                    </div>
                    <div class="col-sm-3 col-md-4">
                        <input type="text" class="form-control" style="height:50px" id="account_city"/>
                    </div>
                </div>
				
				
				 <div class="row">
                    <div class="col-sm-3 col-md-2">
                        <p class="font-card-info">State</p>
                    </div>
                    <div class="col-sm-3 col-md-4">
                        <input type="text" class="form-control" style="height:50px" id="account_state"/>
                    </div>

                    <div class="col-sm-3 col-md-2">
                        <p class="font-card-info">Zip Code</p>
                    </div>
                    <div class="col-sm-3 col-md-4">
                        <input type="text" class="form-control" style="height:50px" id="account_zipCode"/>
                    </div>
                </div>
				
                
                 <div class="row">
                    <div class="col-sm-3 col-md-2">
                        <p class="font-card-info">Phone Number</p>
                    </div>
                    <div class="col-sm-3 col-md-4">
                        <input type="text" class="form-control" style="height:50px" id="account_phoneNumber"/>
                    </div>

                    <div class="col-sm-3 col-md-2">
                        <p class="font-card-info">Email</p>
                    </div>
                    <div class="col-sm-3 col-md-4">
                        <input type="text" class="form-control" style="height:50px" id="account_email"/>
                    </div>
                </div>
                
            </div>
        </div>
    </div>
    
    
    
</div>
    
</div>  
    
    
<div class="container-fluid">    
    <div class="row">
        <div class="col-md-6 col-sm-3"></div>
		<div class="col-md-2 col-sm-3" align="right"><button type="button" class="btn btn-info" onclick="createAccount()">Create Account</button></div>
        
    </div>
</div>
    

  
<!--bottom bar-->
<div class="alert sticky-bottom alert-dark text-center" role="alert">
  	<p><small>®2018. All Rights Reserved.</small></p>
</div>



<!--call js script-->

<script type="text/javascript" src="create_user_account.js"></script> 






</body>
</html>
Posted
Updated 26-Nov-18 1:59am
Comments
F-ES Sitecore 14-Nov-18 4:46am    
Client-side javascript (js that runs in the browser) can't connect to databases. You'll need some kind of server to connect to, so a web server like IIS or Apache etc. That will stop your app working standalone on a machine, but if you want a standalone app then html is the wrong tech to use. Also databases tend to be server-based and non-distributable also.

1 solution

If you can use Firebase for storing data, you can store and retrieve data without PHP. If you still want to use MYSQL, it is not possible with whatever you have tried. Try with node.js.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900