HTML Form sends values to wrong PHP page - php

I just started learning PHP. I have this form that I have set the action to "dashboard.php". But, when I click the submit button, it send the user and variables to a file called newaccount.php. I don't know why this is happening and I have looked over my code. Any suggestions on how I can fix this problem?
Note: The HTML file is called newaccount.html, if that has anything to do with the problem.
HTML:
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="index.html"> Know Music</a>
</div>
<ul class="nav navbar-nav hidden-xs">
<li>Guitar</li>
<li>Bass</li>
<li>Drums</li>
<li>Piano</li>
</ul>
<ul class="nav navbar-nav navbar-right hidden-xs">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-user"></span></a>
<ul class="dropdown-menu">
<li>Log In</li>
<li>Create New Account</li>
</ul>
</li>
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-menu-hamburger"></span></a>
<ul class="dropdown-menu">
<li>About</li>
<li>Contact</li>
</ul>
</li>
</ul>
</div>
</nav>
<div class="container">
<div id="buffer">
</div>
<div id="text">
<h8>Create A New Account</h8>
</div>
<div class="form">
<form action="php/dashboard.php" method="post">
<input type="text" class="w3-round-large in" name="email" value="E-Mail"><br>
<br>
<input type="password" class="w3-round-large in" name="wsp" value="Password"><br>
<br>
<input type="submit" class="submit w3-round-large" value="Register">
</form>
</div>
<div class="log">
<p>Already have an account? <a class="link" href="#">Log In Here!</a></p>
</div>
</div>
</body>
PHP (dashboard.php):
<html>
<body>
<?php
$user = $_POST["username"];
$pass = $_POST["wsp"];
echo $user;
echo $pass;
?>
</body>
</html>

Related

Bootstrap 5 - form multi step wizard - validation one page at a time

I have a problem with my multi step form. Whenever I click the "next" button, instead of just the current tab being validated, it validates all the tabs on the form. How can I do to just validate only the current TAB?
If I have a form in each TAB, the validation will work as I want, but then I can't submit all forms at once.
index.php
<div id="rootwizard">
<ul class="nav nav-pills form-wizard-header mb-3">
<li class="nav-item" data-target-form="#one">
<a href="#basic" data-bs-toggle="tab" data-toggle="tab" class="nav-link rounded-0 pt-2 pb-2">
<span>Info</span>
</a>
</li>
<li class="nav-item" data-target-form="#two">
<a href="#first" data-bs-toggle="tab" data-toggle="tab" class="nav-link rounded-0 pt-2 pb-2">
<span>Device</span>
</a>
</li>
</ul>
<div>
<div id="basic">
<form id="one" method="post" action="" class="form-horizontal">
<div class="row mb-3">
<label for="Client_Emp">Cliente/Empresa</label>
<div>
<input type="text" name="Client_Emp" id="Client_Emp" required />
</div>
</div>
</form>
</div>
<div class="tab-pane" id="first">
<form id="two" method="post" action="" class="form-horizontal">
<div class="row mb-3">
<label for="cpu">CPU</label>
<div>
<input type="text" name="cpu" id="Client_Emp" required />
<option></option>
</select>
</div>
</div>
</form>
</div>
<ul class="list-inline wizard mb-0">
<li class="previous list-inline-item">Previous
</li>
<li class="next list-inline-item float-end">Next</li>
</ul>
</div> <!-- tab-content -->
</div> <!-- end #rootwizard-->
Thanks. I managed to solve it with this javascript.
$("#global").submit(function(e) {
var $ch1 = $("#form_info").children();
var $ch2 = $("#form_first").children();
var $ch3 = $("#form_second").children();
var $ch4 = $("#form_third").children();
var $ch5 = $("#form_fourth").children();
var $ch6 = $("#form_fifth").children();
$(this).append($ch1).append($ch2).append($ch3).append($ch4).append($ch5).append($ch6);
$("#global").submit();
});

How to load a controller before connecting to DB or even when MySQL turned off

I wonder if someone can help me to load a "maintanence" controller before the framwork connects to DB.
that will load tpl file.
For example, when the app is under construction and I want to turn the MySQL database off, but I want to show the people who get my web a page (tpl file that is loaded by controller) "we are under construction" page and all this by loading tpl files and not requiring PHP file.
OpenCart core makes the DB connection before any controller is loaded. So if you plan to turn to maintenance mode, before anything is displayed to the user, the DB connection is already established.
It is practically impossible to separate the DB from the core since it is so tightly coupled.
The only solution would be to create a index.html file as a copy of your maintenance mode html like Paul Feakins replied in comments.
here is a clean html you can use. should work for anyone.
in your root directory create index.html and paste this code:
<!DOCTYPE html>
<!--[if IE]><![endif]-->
<!--[if IE 8 ]><html dir="ltr" lang="en" class="ie8"><![endif]-->
<!--[if IE 9 ]><html dir="ltr" lang="en" class="ie9"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<html dir="ltr" lang="en">
<!--<![endif]-->
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Maintenance</title>
<script src="catalog/view/javascript/jquery/jquery-2.1.1.min.js" type="text/javascript"></script>
<link href="catalog/view/javascript/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen" />
<script src="catalog/view/javascript/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<link href="catalog/view/javascript/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,400i,300,700" rel="stylesheet" type="text/css" />
<link href="catalog/view/theme/default/stylesheet/stylesheet.css" rel="stylesheet">
<script src="catalog/view/javascript/common.js" type="text/javascript"></script>
<link href="/image/catalog/cart.png" rel="icon" />
</head>
<body>
<nav id="top">
<div class="container"><div class="pull-left">
<form action="/index.html" method="post" enctype="multipart/form-data" id="form-currency">
<div class="btn-group">
<button class="btn btn-link dropdown-toggle" data-toggle="dropdown"> <strong>$</strong> <span class="hidden-xs hidden-sm hidden-md">Currency</span> <i class="fa fa-caret-down"></i></button>
<ul class="dropdown-menu">
<li>
<button class="currency-select btn btn-link btn-block" type="button" name="EUR">€ Euro</button>
</li>
<li>
<button class="currency-select btn btn-link btn-block" type="button" name="GBP">£ Pound Sterling</button>
</li>
<li>
<button class="currency-select btn btn-link btn-block" type="button" name="USD">$ US Dollar</button>
</li>
</ul>
</div>
<input type="hidden" name="code" value="" />
<input type="hidden" name="redirect" value="/index.html" />
</form>
</div>
<div id="top-links" class="nav pull-right">
<ul class="list-inline">
<li><i class="fa fa-phone"></i> <span class="hidden-xs hidden-sm hidden-md">123456789</span></li>
<li class="dropdown"><i class="fa fa-user"></i> <span class="hidden-xs hidden-sm hidden-md">My Account</span> <span class="caret"></span>
<ul class="dropdown-menu dropdown-menu-right">
<li>Register</li>
<li>Login</li>
</ul>
</li>
<li><i class="fa fa-heart"></i> <span class="hidden-xs hidden-sm hidden-md">Wish List (0)</span></li>
<li><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md">Shopping Cart</span></li>
<li><i class="fa fa-share"></i> <span class="hidden-xs hidden-sm hidden-md">Checkout</span></li>
</ul>
</div>
</div>
</nav>
<header>
<div class="container">
<div class="row">
<div class="col-sm-4">
<div id="logo"> <h1>Your Store</h1>
</div>
</div>
<div class="col-sm-5"><div id="search" class="input-group">
<input type="text" name="search" value="" placeholder="Search" class="form-control input-lg" />
<span class="input-group-btn">
<button type="button" class="btn btn-default btn-lg"><i class="fa fa-search"></i></button>
</span>
</div></div>
<div class="col-sm-3"><div id="cart" class="btn-group btn-block">
<button type="button" data-toggle="dropdown" data-loading-text="Loading..." class="btn btn-inverse btn-block btn-lg dropdown-toggle"><i class="fa fa-shopping-cart"></i> <span id="cart-total">0 item(s) - $0.00</span></button>
<ul class="dropdown-menu pull-right">
<li>
<p class="text-center">Your shopping cart is empty!</p>
</li>
</ul>
</div>
</div>
</div>
</div>
</header>
<div class="container">
<nav id="menu" class="navbar">
<div class="navbar-header"><span id="category" class="visible-xs">Categories</span>
<button type="button" class="btn btn-navbar navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse"><i class="fa fa-bars"></i></button>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li class="dropdown">Desktops
</li>
<li class="dropdown">Laptops & Notebooks
</li>
<li class="dropdown">Components
</li>
<li>Tablets</li>
<li>Software</li>
<li>Phones & PDAs</li>
<li>Cameras</li>
</ul>
</div>
</nav>
</div>
<div id="common-maintenance" class="container">
<div class="row">
<div class="col-12"><h1 style="text-align:center;">We are currently performing some scheduled maintenance. <br/>We will be back as soon as possible. Please check back soon.</h1></div>
</div>
</div>
<footer>
<div class="container">
<div class="row">
<div class="col-sm-3">
<h5>Information</h5>
<ul class="list-unstyled">
<li>About Us</li>
<li>Delivery Information</li>
<li>Privacy Policy</li>
<li>Terms & Conditions</li>
</ul>
</div>
<div class="col-sm-3">
<h5>Customer Service</h5>
<ul class="list-unstyled">
<li>Contact Us</li>
<li>Returns</li>
<li>Site Map</li>
</ul>
</div>
<div class="col-sm-3">
<h5>Extras</h5>
<ul class="list-unstyled">
<li>Brands</li>
<li>Gift Certificates</li>
<li>Affiliate</li>
<li>Specials</li>
</ul>
</div>
<div class="col-sm-3">
<h5>My Account</h5>
<ul class="list-unstyled">
<li>My Account</li>
<li>Order History</li>
<li>Wish List</li>
<li>Newsletter</li>
</ul>
</div>
</div>
<hr>
<p>Powered By OpenCart<br /> Your Store © 2019</p>
</div>
</footer>
<!--
OpenCart is open source software and you are free to remove the powered by OpenCart if you want, but its generally accepted practise to make a small donation.
Please donate via PayPal to donate#opencart.com
//-->
</body></html>

Navbar Breaks PHP redirect

I have a navbar from bootstrap3.3. I also have various forms on this page which redirects with header location when a form is submitted. Whenever I add any sort of additional form or dropdown to my navbar(as opposed to the page body), the header location stops redirecting (the query still runs in the db as normal).
They should be completely independant of each other so I'm confused if this is a bug with bs 3.3? Or is my code flawed/have I made a stupid mistake?
form query works perfectly, but header location only if my navbar is relatively simple..
$result = $this->db_query($query);
if($result){
header("Location: https://somepage.com?message=submitted");
}
still works with this:
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="https://somepage.com">Brand</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li >Home</li>
<li>About</li>
<li>Contact</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>Order</li>
<li>Collections</li>
<li>Summary</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
but won't work with this (tried form search and dropdown separately and together)
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="https://somepage.com">Brand</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li >Home</li>
<li>About</li>
<li>Contact</li>
<li class="dropdown">
Filter<span class="caret"></span>
<ul class="dropdown-menu" role="menu">
<li>test1</li>
<li>test2</li>
<li>test3</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><form class="form-inline" method="POST" action="">
<div class="form-group">
<input type="text" class="form-control" id="search" name="search" placeholder="Search">
</div>
<button type="submit" name="search" class="btn btn-secondary mb-2">Search</button>
</form></li>
<li>Order</li>
<li>Collections</li>
<li>Summary</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>

Universal NavBar Links

So I get that that is a silly beginner question, but I can't figure it out. Its two parts:
THE SETUP
So I want to have a universal navbar on my site. I created a navigation.php file and I am using include on every page.
THE PROBLEM
On my index page, it is working great. However all of my other pages are within a contentFiles folder. When I navigate from the index page, back to the index page the contentPages, the sub-directory stays in the URL.
To see exactly what it is doing:
1. Go to http://www.newshongumpto.org
2. Click on News/Calendar > Calendar
3. Click on Home
Any suggestions? My next questions is how to make this dynamic from my dB, but I think I will attempt that first before coming back.
<nav class="navbar navbar-default navbar-fixed-top navbar-left" role="navigation">
<div class="nav-container container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs3-navbar-collapse"><span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span></button>
<img src="/images/ShongumSkyhawkBird_Green_Brand.png" alt="Shongum Elementary School" class="skyhawk_navimage" width="45" height="56"></div>
<div class="collapse navbar-collapse" id="bs3-navbar-collapse">
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About Us</li>
<li class="dropdown"> Membership <b class="caret"></b>
<ul class="dropdown-menu">
<li>Benefits of Membership</li>
<li class="divider"></li>
<li>Parent Membership Application</li>
<li>Teacher Membership Application</li>
</ul>
</li>
<li class="dropdown"> Programs <b class="caret"></b>
<ul class="dropdown-menu">
<li>Get Involved!</li>
<li class="divider"></li>
<li>Family Portraits</li>
<li>Room Parents</li>
<li>Skyhawk Enrichment</li>
</ul>
</li>
<li class="dropdown"> Classes <b class="caret"></b>
<ul class="dropdown-menu">
<li>Kindergarden</li>
<li>1st Grade</li>
<li>2nd Grade</li>
<li>3rd Grade</li>
<li>4th Grade</li>
<li>5th Grade</li>
</ul>
</li>
<li>Store</li>
<li class="dropdown"> News/Calendar <b class="caret"></b>
<ul class="dropdown-menu">
<li>News</li>
<li>Calendar</li>
</ul>
</li>
<li class="dropdown"> RSD<b class="caret"></b>
<ul class="dropdown-menu">
<li>RAM Alerts</li>
<li>District Calendar</li>
<li>Lunch Menu (Shongum Only)</li>
</ul>
</li>
<li><form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="749L2346K28NW">
<input type="submit" value="Donate Now »" name="submit" title="Donate to your Shongum PTO Today!" class="paypal_btn">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form> </li>
</ul>
<a class="btn btn-default navbar-btn" href="../contentPages/membership/membership.php">Membership Sign-Up</button>
</a> </div>
</div>
</nav>
Change href="index.php" to href="/index.php"
Similarly add slash to all your urls . This way, all your urls will be routed from your website's base url
Relative links did the tricks... duh... (ugh)...

How to make a simple navigator - content menu

Attached is the code snippet of my navigator
<!-- Navigator -->
<div style="position:abolute;top:50px" class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<ul id="yw0" class="nav">
<li class="active">Company</li>
<li><a style="color:black" href="#"><i class="fa fa-lightbulb-o"></i>&nbspFAQs</a></li>
<li><a style="color:black" href="#"><i class="fa fa-question-circle"></i>&nbspHelp Center</a></li>
<li><a style="color:black" href="#"><i class="fa fa-newspaper-o"></i>&nbspPress</a></li>
<li><a style="color:black" href="#">Careers</a></li>
<li><a style="color:black" href="#"><i class="fa fa-envelope-o"></i>&nbspContact Us</a></li>
</ul>
</div>
</div>
</div>
<!-- Content -->
I am actually trying to put a logic that whenever I click on a link , it should renderPartial the appropriate file and also highlight the menu below the navigator.. I tried doing the following <a href="<?php $this->renderPartial("company",false); ?>"
But I guess it is not the right way.. dunno how can I achieve it?
This will go into your view file
<!-- Navigator -->
<div style="position:abolute;top:50px" class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<ul id="yw0" class="nav">
<li class="active">Company</li>
<li><a onclick="showData('user')" style="color:black" href="#"><i class="fa fa-lightbulb-o"></i>&nbspFAQs</a></li>
<li><a style="color:black" href="#"><i class="fa fa-question-circle"></i>&nbspHelp Center</a></li>
<li><a style="color:black" href="#"><i class="fa fa-newspaper-o"></i>&nbspPress</a></li>
<li><a style="color:black" href="#">Careers</a></li>
<li><a style="color:black" href="#"><i class="fa fa-envelope-o"></i>&nbspContact Us</a></li>
</ul>
</div>
</div>
</div>
<div class="main-content">
<div id="company" class="renderContent">
<?php $this->renderPartial("company",false); ?>
</div>
<div id="user" class="renderContent">
<?php $this->renderPartial("user",false); ?>
</div>
<!--- for every menu item there should be a view rendered here--->
</div>
<!-- Content -->
this will go into your js
function showData(id) {
$('.renderContent').hide();
$('.nav li').removeClass('active');
$(this).addClass('active');
$('#'+id).show();
}
$('.renderContent').hide();

Categories