Updated Problem: I'm trying to use PHP to add information into a SQL table if there is no errors, but I am not sure how to get it to fully working so that it'll show the errors and such. Where do I put the PHP code? Also where what language would I use to display the errors?
Updated HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TheQuantumBros</title>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="MainStyles.css" />
<link rel="shortcut icon" href="favicon.ico" />
<style type="text/css">
.style2 {
font-size: xx-large;
color: white;
}
.style3 {
font-size: xx-large;
color: #008000;
}
</style>
</head>
<body style=";background-image:url('bg_wallpaper_black.jpg');margin:0;padding-top:0;">
<div id="topBar" class="topBar">
<h1 id="title" class="title">
<img src="TheQuantumBros3.png" alt="" style="padding-right:5px" />
TheQuantumBros
<img src="TheQuantumBros3.png" alt="" style="padding-left:5px"/>
</h1>
</div>
<div id="topDiv" class="topDiv" style="height:200px">
<div id="topDivFrame" class="topDivFrame" style="background-image:url('TheQuantumBros2.png');height:200px"></div>
</div>
<div id="menuBar" class="menuBar">
<button name="homeButton" class="menuButton1" onclick="javascript:window.location.href='http://www.tqbtest.comlu.com/'">Home</button>
<button name="forumsButton" class="menuButton2">Forums</button>
<button name="bfButton" class="menuButton2">BF P4F</button>
<button name="mcButton" class="menuButton2">Minecraft</button>
<button name="applyButton" class="menuButton2">Applications</button>
<button name="infoButton" class="menuButton2">About Us</button>
</div>
<div style="width:100%;height:150px;margin-top: 5px;margin-left:auto;margin-right:auto;text-align:center">
<div style="width:75%;height:100%;text-align:center">
<span style="width:75%;height:10%;margin-right:15%;margin-left:45%;text-align:center" class="style2">TheQuantumBros Registration</span>
<form method="post" action="register.php" style="height:100%;width:100%;text-align:center">
<span class="registrationText">First Name:</span>
<input name="firstname" type="text" class="registrationInput"/>
<span class="registrationText">Last Name:</span>
<input name="lastname" type="text" class="registrationInput"/>
<span class="registrationText">Username:</span>
<input name="username" type="text" class="registrationInput"/>
<span class="registrationText">Email</span>
<input name="email" type="text" class="registrationInput"/>
<span class="registrationText">Password</span>
<input name="password" type="password" class="registrationInput"/>
<span class="registrationText">Retype Password:</span>
<input name="password2" type="password" class="registrationInput"/>
<span class="registrationText">Region</span>
<select name="region" class="registrationInput">
<option>North America</option>
<option>South America</option>
<option>Europe</option>
<option>Asia</option>
<option>Africa</option>
<option>Australia</option>
</select>
<span style="width:25%"></span>
<input name="Submit1" type="submit" value="Submit" class="registrationSubmit"/>
<span class="notFilled" id="notFilled">*Please fill in all the fields.</span>
</form>
</div>
</div>
Updated PHP:
$sql="SELECT username, email FROM Profiles";
$result=mysqli_query($con,$sql);
if($result === false){
echo mysqli_error($con);
}else{
while($row = mysqli_fetch_array($result)){
$rows[] = $row;
foreach ($rows as $row) {
if($row['username'] == $_POST['username'] || $row['email'] == $_POST['email']){
//Error: "Username or Email already in use"
}else {
if($_POST['password'] == $_POST['password2']){
if (strpos($_POST['email'],'@') !== false) {
//INSERT INTO code?
}else{
//Error: "Please enter a valid email."
}
}else{
//Error: "Passwords do not match."
}
}
}
mysqli_close($con);
}
}
}else{
//Error code: "Please fill in all fields"
}
?>
Your code is structured very strangely, and I suspect you're confused about what you should use to do what. Why are you sticking your PHP at the bottom of the page, after all the HTML? That, and the way you talk about your PHP code "getting triggered" in the comments makes me wonder if you understand what exactly PHP does. PHP is a server-side tool for building HTML dynamically. By the time your user sees the page, all your PHP has finished running and can't do anything more until they load the next page. I don't know exactly what you're trying to do here, but putting PHP after all your HTML is never the right solution.
If you're putting data into a form, and then reloading the same page with the form data, what you should do is put the bulk of your PHP at the top of the page, and then put little bits of PHP interspersed throughout your HTML wherever you want something dynamic. Javascript shouldn't be needed unless you're doing something fancy.
You are closing the html
tag. So the page is ignoring the stuff afterward. Move the </body>
and </html>
tags to after your script. Also you don't need to echo the the scripts. Unless you are doing some php logic in your script that you are not showing.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head />
<body>
//All my HTML code...
//Related HTML code
<div>
<span class="notFilled" id="notFilled">*Please fill in all the fields.</span>
</div>
<?php
//All my PHP code...
//Related PHP/JQuery code
echo '<script type="text/javascript">'
, '$("#notFilled").css("visibility","visible")'
, '</script>';
?>
</body>
</html>
your <script>
is outside the <html>
tag.. it should be placed before the closing </body>
tag
Anyway, this is a really dirty code.. Mixin Html, JS and PHP?.. you need to completly separate them. It will save you some headaches
Hope this helps
first of all ..
1) load the jquery.js script in your head....
2) i don,t understand why are you using when you can use <script></script>
and ways... put the <body> and
3)use document.ready function
updated code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
//load jquery script here
</head>
<body>
//All my HTML code...
//Related HTML code
<div>
<span class="notFilled" id="notFilled">*Please fill in all the fields.</span>
</div>
<?php
//all your php code
?>
<script type="text/javascript">
$(function(){
$('#buttonID').click(function(){ //<--updated here
$("#notFilled").css("visibility","visible");
});
});
</script>;
</body>
Instead if trying to edit the css, it may be a good idea to use the .hide() and .show() methods. You can even use transitions to make it look nicer (.fadeIn()...)
In any case, I wouldn't recommend the involving php to load javascript, but at the end of the day, I'm not sure of the context of the script.
jQuery might not be loaded yet when you are calling the jQuery.css()
function.
Make sure that the jQuery js file is being loaded before (make sure it appears above) any jQuery function calls.