php showing logout button only if logged in - javascript

I am writing the code for a simple website where users log in and out and some other basic functions. I would like it to be so when anyone logs in, a logout button is shown on all the pages they visit, and hidden if they are not logged it. I am still new and cannot figure out what is wrong. The logout button appears as soon as i initially click the login button, but when i navigate to other pages the button disappears from my menu.
menu.php
$currentfile = basename($_SERVER['PHP_SELF']);
if($currentfile = basename($_SERVER['PHP_SELF'])){
if (isset($_SESSION['ID'])) {
echo "Home
See Reviews
Write a Review
Search
<a href='logoutconfirmation.php'>Logout</a>
<hr />";
}else{
echo "Home
See Reviews
Write a Review
Search
<hr />";
}
} ?>
index.php
<?php
include "header.inc.php";
$pagetitle= "Login Form";
$showform =1;
$errormsg =0;
$errorusername = $errorpassword = "";
$inputdate = time();
//FIRST CHECK TO SEE IF THE USER IS LOGGED IN
if(isset($_SESSION['ID']))
{
echo "<p class='error'> You are already logged in. </p>";
include_once "footer.inc.php";
exit();
}
if(isset ($_POST['submit'])) {
/*************************************************************
* ALL FIELDS- STORE USER DATA; SANITIZE USER-ENTERED DATA
*************************************************************/
$formfield['username'] = trim($_POST['username']);
$formfield['password'] = trim($_POST['password']);
if (empty($formfield['username'])) {
$errorusername = "The username is required.";
$errormsg = 1;
}
if (empty($formfield['password'])) {
$errorpassword = "The password is required.";
$errormsg = 1;
}
if ($errormsg != 0) {
echo "<p class='error'> THERE ARE ERRORS!</p>";
} else {
//get the user data from the database
try {
$user = "SELECT * FROM Users WHERE username =:username";
$stmt = $pdo->prepare($user);
$stmt->bindValue(':username', $formfield['username']);
$stmt->execute();
$row = $stmt->fetch();
$countuser = $stmt->rowCount();
// if query okay, see if there is a result
if ($countuser < 1) {
echo "<p class='error'> *This user cannot be found in the
database* </p>";
} else {
if (password_verify($formfield['password'], $row['password'])) {
$_SESSION['ID'] = $row['ID'];
$showform = 0;
header("LocationL confirm.php?state=2");
echo "<p> Thank you for logging in! </p>";
} else {
echo "<p class='error'> The username and password
combinations you entered are not correct. Please try again! </p>";
}
}//username exists
} catch (PDOException $e) {
echo 'ERROR fetching users: ' . $e->getMessage();
exit();
}
}
}
if($showform == 1) {
?>
<p class="homemsg">Welcome to the Movie Review Hub! Feel free to look
around or sign in to write your own review.</p>
<form name="login" id="login" method="post" action="index.php">
<table class="center">
<tr>
<th><label for="username">Username: </label></th>
<td><input name="username" id="username" type="text" placeholder="Required Username"
}?><span class="error" <?php if (isset($errorusername)) {
echo $errorusername;
} ?></span></td>
</tr>
<tr>
<th><label for="password">Password: </label></th>
<td><input name="password" id="password" type="password" placeholder="Required Password"
}?><span class="error"> <?php if (isset($errorpassword)) {
echo $errorpassword;
} ?></span></td>
<tr>
<th><label for="submit">Submit: </label></th>
<td><input type="submit" name="submit" id="submit" value="submit"/></td>
</tr>
</table>
<p><a href=index.php>Register.</a></p>
<?php
include_once "footer.inc.php";
}
?>
Like I said i would like the logout button to be show on all of the pages if someone logs in from the index page, the menu is included in all of my files
The logout button initially shows when i press the login button, but when i refresh the page or navigate to another page it goes away.

Like #CBroe mention, try add session_start at start of every page.
Better create config file, put it there and include everywhere.

Related

My registration form was working perfectly on localhost but now that it is on a c-panel server it doesn't work

This is my code, I really don't know whats wrong does anyone else know? Currently the error that comes up is Oops! Something went wrong. Please try again later. I know that the issue is not a connection issue and is not a permissions issue. I'm really confused about what I've done wrong and have even contacted customer support multiple times and they didn't know what the issue is.
<?php
include ('config.php');
// Define variables and initialize with empty values
$username = $password = $confirm_password = "";
$username_err = $password_err = $confirm_password_err = "";
// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
// Validate username
if(empty(trim($_POST["username"]))){
$username_err = "Please enter a username.";
} else{
// Prepare a select statement
$sql = "SELECT username FROM users WHERE username = ?";
if($stmt = mysqli_prepare($conn, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_username);
// Set parameters
$param_username = trim($_POST["username"]);
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
/* store result */
mysqli_stmt_store_result($stmt);
if(mysqli_stmt_num_rows($stmt) == 1){
$username_err = "This username is already taken.";
} else{
$username = trim($_POST["username"]);
}
} else{
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close statement
mysqli_stmt_close($stmt);
}
// Validate password
if(empty(trim($_POST["password"]))){
$password_err = "Please enter a password.";
} elseif(strlen(trim($_POST["password"])) < 6){
$password_err = "Password must have atleast 6 characters.";
} else{
$password = trim($_POST["password"]);
}
// Validate confirm password
if(empty(trim($_POST["confirm_password"]))){
$confirm_password_err = "Please confirm password.";
} else{
$confirm_password = trim($_POST["confirm_password"]);
if(empty($password_err) && ($password != $confirm_password)){
$confirm_password_err = "Password did not match.";
}
}
// Check input errors before inserting in database
if(empty($username_err) && empty($password_err) && empty($confirm_password_err)){
// Prepare an insert statement
$sql = "INSERT INTO users (username, password) VALUES (?, ?)";
if($stmt = mysqli_prepare($conn, $sql)){
// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "ss", $param_username, $param_password);
// Set parameters
$param_username = $username;
$param_password = password_hash($password, PASSWORD_DEFAULT); // Creates a password hash
// Attempt to execute the prepared statement
if(mysqli_stmt_execute($stmt)){
// Redirect to login page
header("location:Login.php");
} else{
echo "Something went wrong. Please try again later.";
}
}
// Close statement
mysqli_stmt_close($stmt);
}
// Close connection
mysqli_close($conn);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sign Up</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
<style type="text/css">
body{ font: 14px sans-serif; }
.wrapper{ width: 350px; padding: 20px; }
</style>
</head>
<body>
<div class="wrapper">
<h2>Sign Up</h2>
<p>Please fill this form to create an account.</p>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group <?php echo (!empty($username_err)) ? 'has-error' : ''; ?>">
<label>Username</label>
<input type="text" name="username" class="form-control" value="<?php echo $username; ?>">
<span class="help-block"><?php echo $username_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($password_err)) ? 'has-error' : ''; ?>">
<label>Password</label>
<input type="password" name="password" class="form-control" value="<?php echo $password; ?>">
<span class="help-block"><?php echo $password_err; ?></span>
</div>
<div class="form-group <?php echo (!empty($confirm_password_err)) ? 'has-error' : ''; ?>">
<label>Confirm Password</label>
<input type="password" name="confirm_password" class="form-control" value="<?php echo $confirm_password; ?>">
<span class="help-block"><?php echo $confirm_password_err; ?></span>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Submit">
<input type="reset" class="btn btn-default" value="Reset">
</div>
<p>Already have an account? Login here.</p>
</form>
</div>
</body>
</html>

Game Login and Database [duplicate]

I am trying to create website with login form with some PHP code, were user will try to login with username and password and page will then show "welcome....". AT the moment when user try to put username and password website that shows up is blank, nothing is on it. Also i already have created mysql database with username and password.
this login form on my main page index.html:
<form id="form" method="post" action="login.php">
<label for="username">Username:</label>
<input type="text" name="username" size="15" required="required" />
<label for="password">Password:</label>
<input type="password" name="password" size="15" required="required" />
<input id="loginButton" type="submit" name="submit" value="LOGIN" />
</form>
and this is my php page login.php:
<?php
session_start();
$host = "localhost";
$username = "*******";
$password = "*******";
$db_name = "********";
$tbl_name = "users";
$conn = mysql_connect("$host", "$username", "$password") or die("Cannot connect");
mysql_select_db("$db_name", $conn) or die("Cannot connect");
$myusername = $_POST['username'];
$mypassword = $_POST['password'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql = "SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
if ($count == 1) {
session_register("username");
session_register("password");
header("location:page1.html");
} else {
echo "Wrong Username or Password";
}
?>
and on my welcome page - page1.html i have included some php code:
<?php
session_start();
if(!session_is_registered(username)){
header("location:index.html");
}
?>
First off...dont store the password in the session. Thats just asking for trouble.
session_register("password");
Secondly....session_register() is a deprecated function and shouldn't be used anymore.
Instead do...
$_SESSION['username'] = $myusername;
Third....
header("location:page1.html");
Should be a PHP file if you want sessions to work across pages..
header("location:page1.php");
Then in that PHP page do...
session_start();
if(!isset($_SESSION['username'])){
header("location:index.php");
} else {
// Display stuff to logged in user
}

Javascript and php copy button

I am trying to create a Button so the user can copy the $filename the code works for the first one but not for the rest I understand that this is because I would probably need to array the js-copyfilename and js-copyfilenamebtn classes so each one is different but then I know very little about JavaScript so wouldn't know where to start
Thanks in advance
<p>Current Images Inside Gallery
<br />
<?php foreach($rows as $row): ?>
<div class="t">
<table class="table2">
<tr>
<td class="table2"><?php echo $row["id"]; ?></td>
</tr>
<tr>
<td><img src="images/<?php echo $row["photo"] ; ?>" alt="" width="130" height="130" /></td>
</tr>
<tr>
<td><textarea class="js-copyfilename" readonly="readonly" ><?php echo $row["photo"];?></textarea>
<button class="js-copyfilenamebtn">Copy Filname</button>
</td>
</tr>
</table>
</div>
<?php endforeach;?>
</div>
<script type="text/javascript">
var copyfilenameBtn = document.querySelector('.js-copyfilenamebtn');
copyfilenameBtn.addEventListener('click', function(event) {
var copyfilename = document.querySelector('.js-copyfilename');
copyfilename.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
});
</script>​
For anybody trying to do something similar I done it like so... This code selects all rows in db, puts them into table, and then creates a copy filename button for each of them and copies the one you click into the filename field once you enter the id and click submit the delete form it will delete that image from the database and directory + a few other validation checks
function ClipBoard(obj) {
var filename = document.getElementById("filename");
filename.innerText = obj.innerText;
Copied = filename.createTextRange();
Copied.execCommand("Copy");
}
#charset "utf-8";
/* CSS Document */
#wrap
{
height:800px;
text-align:center;
}
.table1 {
text-align:center;
font-weight: bold;
width: 130px;
font-size:14px;
}
.table2 {
float:left;
text-align:center;
font-weight: bold;
width: 130px;
border: 1px solid #000;
font-size:14px;
}
.t {
width:140px;
display:inline-block;
margin:0 auto;
}
.js-copyfilename {
text-align:center;
font-weight: bold;
width: 128px;
height:16px;
border:1px solid #000;
font-size:14px;
overflow:hidden;
}
<?php
// Include Databse
include "common.php";
// validation errors
$error = array();
// Check if form has been submitted
if (isset ($_POST['delete']))
{
// get the filename & id. See php.net/basename for more info
$filename = basename($_POST['filename']);
$id =($_POST['id']);
// get file extension, see php.net/pathinfo for more info
$ext = pathinfo($_POST['filename'], PATHINFO_EXTENSION);
// allowed file extensions
$allowedExtensions = array('jpeg','jpg','gif','png','bmp');
// Check filename is not empty
if(empty($filename))
{
$error[] = "Please enter a Filename";
}
// Check valid file extension used
else if(!in_array($ext, $allowedExtensions))
{
$error[] = "Please check Filename";
}
// Check ID is not empty
if(empty($_POST['id']))
{
$error[] = "Please enter a ID";
}
else if(is_numeric($id))
{
// Check ID exists in database
$query = "SELECT id FROM `test` WHERE `id` = :id" ;
$stmt = $db->prepare($query);
$stmt->bindParam(":id", $id);
$stmt->execute();
if(!$stmt->rowCount() == 1)
{
$error[] = "Please check ID";
}
}
else {
$error[] = "ID is not numeric";
}
// delete file from database if there are no errors
if (empty($error))
{
// path to the image
$file_to_delete = 'images/' . $filename;
// Checks the file exists and that is a valid image
if(file_exists($file_to_delete) && getimagesize($file_to_delete))
{
// Delete File From Directory
unlink($file_to_delete);
}
else
{
$error[] = "File not found please check Filename";
}
if (empty($error))
{
// Run Query To Delete File Information From Database
try
{
$query = "DELETE FROM `test` WHERE `id` = :id";
$stmt = $db->prepare($query);
$stmt->execute(array('id' => intval($_POST['id'])));
}
catch(PDOException $ex)
{
die("Failed to run query: Please report issue to admin");
}
$status = "File Deleted";
}
}
}
// Run Query To Show The Current Data In Database
try
{
$query = "SELECT id,photo FROM test ORDER BY id";
$stmt = $db->prepare($query);
$stmt->execute();
}
catch(PDOException $ex)
{
die("Failed to run query: Please report issue to admin");
}
$rows = $stmt->fetchAll();
?>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Delete Image</title>
<link href="css/delete.css" rel="stylesheet" type="text/css" />
<script src="copy.js"></script>
</head>
<body>
<div id="wrap">
<form action="delete.php" method="post" enctype="multipart/form-data">
Please enter the Filename and ID of the image you wish to delete
<table width="284" align="center">
<tr>
<td width="144" class="table1">Filename</td>
<td width="128" class="table1">ID </td>
</tr>
<tr>
<td class="table1"><input name="filename" id="filename" type="text" value="<?php echo $filename; ?>" /></td>
<td class="table1"><input name="id" type="text" id="id" value="<?php echo $id; ?>" size="3" maxlength="4" /></td>
</tr>
</table>
<p>
<?php
// Show validation errros here
if(!empty($error)):
echo implode('<br />', $error);
echo $status;
endif;
?>
<br />
<input type="submit" value="Delete Selected Image" name="delete" />
</p>
</form>
<p>Current Images Inside Gallery
<br />
<?php
foreach($rows as $row):
$i = $row["photo"];
?>
<div class="t">
<table class="table2">
<tr>
<td class="table2"><?php echo $row["id"]; ?></td>
</tr>
<tr>
<td><img src="images/<?php echo $row["photo"] ; ?>" alt="" width="130" height="130" /></td>
</tr>
<tr>
<td><?php print '<textarea class="js-copyfilename" name="copytext'.$i.'" id="copytext'.$i.'">'.$i.'</textarea>
<input type="button" onclick="ClipBoard(document.getElementById(\'copytext'.$i.'\'));" value="Copy Filename">
'; ?>
</td>
</tr>
</table>
</div>
<?php endforeach;?>
</div>
</body>
</html>
COMMON.PHP
<?php
// These variables define the connection information for your MySQL database
$username = "";
$password = "";
$host = "";
$dbname = "";
// UTF-8 is a character encoding scheme that allows you to conveniently store
// a wide varienty of special characters, like ¢ or €, in your database.
// By passing the following $options array to the database connection code we
// are telling the MySQL server that we want to communicate with it using UTF-8
// See Wikipedia for more information on UTF-8:
// http://en.wikipedia.org/wiki/UTF-8
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
// A try/catch statement is a common method of error handling in object oriented code.
// First, PHP executes the code within the try block. If at any time it encounters an
// error while executing that code, it stops immediately and jumps down to the
// catch block. For more detailed information on exceptions and try/catch blocks:
// http://us2.php.net/manual/en/language.exceptions.php
try
{
// This statement opens a connection to your database using the PDO library
// PDO is designed to provide a flexible interface between PHP and many
// different types of database servers. For more information on PDO:
// http://us2.php.net/manual/en/class.pdo.php
$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
}
catch(PDOException $ex)
{
// If an error occurs while opening a connection to your database, it will
// be trapped here. The script will output an error and stop executing.
// Note: On a production website, you should not output $ex->getMessage().
// It may provide an attacker with helpful information about your code
// (like your database username and password).
die("Failed to connect to the database: " . $ex->getMessage());
}
// This statement configures PDO to throw an exception when it encounters
// an error. This allows us to use try/catch blocks to trap database errors.
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// This statement configures PDO to return database rows from your database using an associative
// array. This means the array will have string indexes, where the string value
// represents the name of the column in your database.
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
// This block of code is used to undo magic quotes. Magic quotes are a terrible
// feature that was removed from PHP as of PHP 5.4. However, older installations
// of PHP may still have magic quotes enabled and this code is necessary to
// prevent them from causing problems. For more information on magic quotes:
// http://php.net/manual/en/security.magicquotes.php
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
{
function undo_magic_quotes_gpc(&$array)
{
foreach($array as &$value)
{
if(is_array($value))
{
undo_magic_quotes_gpc($value);
}
else
{
$value = stripslashes($value);
}
}
}
undo_magic_quotes_gpc($_POST);
undo_magic_quotes_gpc($_GET);
undo_magic_quotes_gpc($_COOKIE);
}
// This tells the web browser that your content is encoded using UTF-8
// and that it should submit content back to you using UTF-8
header('Content-Type: text/html; charset=utf-8');
// This initializes a session. Sessions are used to store information about
// a visitor from one web page visit to the next. Unlike a cookie, the information is
// stored on the server-side and cannot be modified by the visitor. However,
// note that in most cases sessions do still use cookies and require the visitor
// to have cookies enabled. For more information about sessions:
// http://us.php.net/manual/en/book.session.php
session_start();
// Note that it is a good practice to NOT end your PHP files with a closing PHP tag.
// This prevents trailing newlines on the file from being included in your output,
// which can cause problems with redirecting users.

I cannot somehow POST files on my database

Im trying to make my school project and would like to make a login system and registration system...my login queries are fine but my registration is taking its time...ivev been here for 3-4 hours trying to figure this out im crying right now.... ive done everything....so in my desperate need i asked this community... please provide immediate answers i desperately need it... the problem is... i cannot seem to haul in the data that i type into my form...tahts it...i dont know whats the reason behind
if($_POST['registerbtn'])
{
$getuser = $_POST['user'];
$getemail = $_POST['email'];
$getpass = $_POST['pass'];
$getconfirmation = $_POST['confirmation'];
if($getemail){
if($getuser){
if($getpass){
if($getconfirmation){
if( $getpass === $getconfirmation ){
if( (strlen($getemail) >= 7) && (strstr($getemail, "#")) && (strstr($getemail, "."))) {
require("./Connect.php");
$query = mysql_query("SELECT * FROM users WHERE username='$getuser'");
$numrows = mysql_num_rows($query);
if($numrows == 0){
$query = mysql_query("SELECT * FROM users WHERE email='$getemail'");
$numrows = mysql_num_rows($query);
if($numrows == 0){
$date = date("F d, Y");
$code = rand();
mysql_query("INSERT INTO users VALUES('', '$getuser', '$getemail', '$getpass', '$date' )");
mysql_query("SELECT * FROM users WHERE username='$getuser'");
$numrows = mysql_num_rows($query);
if($numrows == 1){
}else
$errormsg = "An Error Has Occurred. Account Not Processed";
}else
$errormsg ="There is already a user with that email.";
}else
$errormsg ="There is already a user with that username.";
mysql_close();
}else
$errormsg = "You must enter a valid email address";
}else
$errormsg = "Your passwords did not match";
}else
$errormsg = "Confirm your password";
}else
$errormsg = "You must enter your password";
}else
$errormsg = "You must enter your username";
}else
$errormsg = "You must enter your email address";
}
$form = "<form action='./register.php' method='post'>
<table>
<tr>
<td></td>
<td><font color='red'>$errormsg</font></td>
</tr>
</table>
<fieldset>
<legend>Account</legend>
<input type='text' name='user' size='15' value='$getuser'/>:Username<br/>
<input type='text' name='email' size='15'value='$getemail'>:Email<br/>
<input type='password' name='pass' size='15' value=''/>:Passcode<br/>
<input type='password' name='confirmation' size='15' value=''/>:Confirmation<br/>
<br/>
<input type='submit' name='registerbtn' value='EAT ME'/>
</fieldset>
</form>";
echo "$form";
?>
if you are submitting form at same page.
$form = "<form action='' method='post'>
try this..
if(isset($_POST['registerbtn']))
instead of
if($_POST['registerbtn'])
and
if your Connect.php and registration is in same folder then use require("Connect.php"); if outside the folder then give proper path
First of all, you need to check if the variables are set if not set them to "" except for registerbtn.
Like this:
<?php
if(isset($_POST['registerbtn']))
{
...
} else {
$getuser = $getemail = $errormsg = "";
}
$form = "<form action='./register.php' method='post'>
<table>
<tr>
<td></td>
<td><font color='red'>$errormsg</font></td>
</tr>
</table>
<fieldset>
<legend>Account</legend>
<input type='text' name='user' size='15' value='$getuser'/>:Username<br/>
<input type='text' name='email' size='15'value='$getemail'>:Email<br/>
<input type='password' name='pass' size='15' value=''/>:Passcode<br/>
<input type='password' name='confirmation' size='15' value=''/>:Confirmation<br/>
<br/>
<input type='submit' name='registerbtn' value='EAT ME'/>
</fieldset>
</form>";
echo "$form";
It should work provided there isn't any problem with the db part.
In the one of the if-conditionals viz:
if($numrows == 1){
}else
$errormsg = "An Error Has Occurred. Account Not Processed";
This is not needed because the else of if($numrows == 0 ) takes care of it.
change <form action='./register.php' method='post'> to <form action='' method='post'> or <form action='#' method='post'>

Cheking if form of submited email is correct

I've created this script to check form of email user will enter into textbox
function checkEmail() {
var mail = document.getElementById('mail');
var filter = /^([a-zA-Z0-9_\.\-])+\#(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; /* regex koda najdena na codeproject.com*/
if (!filter.test(mail.value))
{
alert('enter valid email');
mail.focus;
return false;
}
It's used to check form in this script and suposed to show you alert, before you are able to continue
<?php
$flag = 0;
if(isset($_POST['submit']))
{
$con = mysql_connect("localhost","root","");
if (!$con){
die("cannot connect: " . mysql_error());
}
mysql_select_db("strek", $con);
$nar_db="SELECT * FROM narocniki;";
$result = mysql_query($nar_db, $con);
while($row=mysql_fetch_array($result))
{
if($_POST['mail']==$row['mail'])
$flag = 1;
}
if($flag==0)
{
$sql = "INSERT INTO narocniki (mail) VALUE ('$_POST[mail]')";
mysql_query($sql, $con);
mysql_close($con);
?>
<p align="center" class="vsebina" >
Tvoj mail je bil uspešno sprejet!</p>
<p align="center"><input type="button" name="return" value="nazaj"></p>
<?php
}
else
{
echo '<p align="center" class="vsebina">Naveden mail je že v bazi naročnikov!</p>';
?>
<p align="center"><input type="button" name="return" value="nazaj"></p>
<?php
}
}
else
{
include("vsebina/tabdog.html");
?>
<p align="center" class="vsebina" id="mail">
naroči se na najnovejše novice</p>
<form action="dogodki.php" method="post">
<p align="center" class="vsebina">vnesi svoj e-naslov: <input type="text" name="mail" id="mail" required>
<input type="submit" name="submit" value="potrdi" onClick="return checkEmail()">
</p>
</form>
<?php
}
?>
It's probably just something missing
Should I rather just include script inside the code, and where would be the best to place it-weather directly in head or rather somewhere in between
Is this even possible in my code, because it already checks if mail exists in database, and would then also need to check the form of email
Instead of doing it in the onclick attribute of the submit button, try doing it in the onsubmit attribute of the form:
<form action="dogodki.php" method="post" onsubmit="return checkEmail()">

Categories