Can't access the admin dashboard of my locally hosted site [closed] - php

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last month.
Improve this question
I bought a code from someone and hosted it locally and it was working very wonderful but my problem is. I opened the admin table in phpmyadmin and got the admin email and encrypted password. But because I don't know what the password was, I tried adding another admin account via the phpmyadmin (still using local host) but I'm still unable to login to the admin dashboard.
Any solution?
<?php require("../includes/config.php");
require_once(ROOT_PATH . "core/class.admin.php");
$login = new ADMIN();
if($login->
is_loggedin() != ""){
$login->
redirect(BASE_URL.'administrator');
}
if(isset($_POST['loginBtn'])){
$username = strip_tags($_POST['userID']);
$password = strip_tags($_POST['password']);
if($login->
doLogin($username, $password)){
$login->
redirect(BASE_URL.'administrator');
}
else{
$error = "Email Address or Password does not match, please try again!";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>
Naija Helper</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="" />
<meta name="author" content="http://creativeweb.com.ng" />
<!-- css -->
<link href="<?php echo BASE_URL;
?>
css/bootstrap.min.css" rel="stylesheet" />
<link href="<?php echo BASE_URL;
?>
css/fancybox/jquery.fancybox.css" rel="stylesheet">
<link href="<?php echo BASE_URL;
?>
css/jcarousel.css" rel="stylesheet" />
<link href="<?php echo BASE_URL;
?>
css/flexslider.css" rel="stylesheet" />
<link href="<?php echo BASE_URL;
?>
js/owl-carousel/owl.carousel.css" rel="stylesheet">
<link href="<?php echo BASE_URL;
?>
css/style.css" rel="stylesheet" />
<style type="text/css">
.formWrapper {
width: 40%;
margin: auto;
}
#media (max-width: 767px) {
.formWrapper {
width: 70%;
margin: auto;
}
}
#media (max-width: 480px) {
.formWrapper {
width: 90%;
margin: auto;
}
}
</style>
</head>
<div class="featured_content" style="margin: 0px;
">
<div class="formWrapper">
<div align="center" style="margin-bottom: 20px;
">
<a style="padding-bottom: 20px;
" href="<?php echo BASE_URL;
?>
">
<img src="<?php echo BASE_URL;
?>
img/logo.png" alt="logo"/>
</a>
</div>
<div align="center" style="margin-bottom: 10px;
">
<span style="font-size: 28px;
">
Adminstrators only</span>
<br>
<span>
Secure admin access</span>
</div>
<div style="background: #FFF;
padding: 50px 20px 20px;
border-radius: 5px;
">
<?php if(isset($error)) {
?>
<div class="alert alert-danger">
<i class="fa fa-exclamation-triangle">
</i>
<?php echo $error;
?>
! </div>
<?php }
?>
<form id="contact-form" method="post" action="" role="form" novalidate>
<div class="form-group has-feedback">
<label for="email">
Email Address*</label>
<input type="text" class="form-control" id="userID" name="userID" required placeholder="Enter your Email Or Username">
<i class="fa fa-envelope form-control-feedback">
</i>
</div>
<div class="form-group has-feedback">
<label for="password">
Password*</label>
<input type="password" class="form-control" id="password" name="password" required placeholder="Password">
<i class="fa fa-lock form-control-feedback">
</i>
</div>
<br>
<input type="submit" style="width: 100%;
padding: 20px;
border-radius: 5px;
" value="Login" name="loginBtn" class="btn btn-default">
</form>
</div>
<div class="row">
<div class="col-md-6">
<span style="font-size: 12px;
padding-left: 10px;
">
<a style="color: #666;
" href="register">
<i class="fa fa-lock">
</i>
Register</a>
</span>
</div>
<div class="col-md-6" align="right">
<span style="font-size: 12px;
padding-right: 10px;
">
<a style="color: #666;
" href="#">
<i class="fa fa-lock">
</i>
Forgot Password</a>
</span>
</div>
</div>
</div>
</div>
<?php include(ROOT_PATH."includes/footer.php");
?>

Here is the code of a php page named create_hash.php. It contains a function createHash() to create a new password hash and an example for using it.
Steps to follow:
Place the file create_hash.php somewhere in your project. BUT BE AWARE: Remove the file from your project after you create a new password! You can save it - for later use - somewhere else in your file system if you wish, where it can not be run as such;
Read the comments in the file, they are important;
Complete your own password in the example bellow;
Change the createHash() arguments as you wish;
Let the file run. A new password hash will be displayed on the screen;
Place the new created hash in the admin table;
Try to login in the admin dashboard again;
REMOVE THE FILE create_hash.php FROM YOUR PROJECT!
The create_hash.php:
<?php
/**
* Create a password hash.<br/>
*
* The two digit cost parameter is the base-2 logarithm of the iteration count for<br/>
* the underlying Blowfish-based hashing algorithmeter and must be in range 04-31.
*
* #param string $password Password to be hashed.
* #param integer $algo [optional] PASSWORD_DEFAULT|PASSWORD_BCRYPT. Used algorithm.
* #param integer $cost [optional] Default: 10. Base-2 logarithm of the iteration count. Range 04-31.
* return string Hashed password (min. 60 characters long).
*/
function createHash($password, $algo = PASSWORD_BCRYPT, $cost = PASSWORD_BCRYPT_DEFAULT_COST) {
try {
if ($algo != PASSWORD_BCRYPT || $algo != PASSWORD_DEFAULT) {
throw new Exception('Incorrect hashing algorithm!');
}
if ($cost < 4 || $cost > 31) {
throw new Exception(' The hashing cost must be in range 04-31!');
}
} catch (Exception $exc) {
echo $exc->getMessage();
exit();
}
$options = array(
'cost' => $cost,
);
return password_hash($password, $algo, $options);
}
//----------------------------------------------------
// Example of using the hashing function createHash().
// Give a password with at least 8 characters,
// including ciphers, letters - lowercase and
// uppercase, alpha characters (#, $, #, etc).
//----------------------------------------------------
$password = "Lorem#20Ipsum17";
$hash = createHash($password, PASSWORD_BCRYPT, 12);
echo $hash;
//----------------------------------------------------

You have not written anything in action attribute of form element. Submit your form on some page and check the credentials entered by the user with the database.

Related

How to order divs side by side and centered when get datas from database in php and css

How to order divs side by side and centered when get datas from database in php and css ?
php and html codes
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="css/normalize.css">
</head>
<body>
<?php include ("connect.php");
$data = $db->query("select * from videos order by id desc");
$data ->execute();
while ($row=$data->fetch(PDO::FETCH_ASSOC)) {?>
<div class="cards">
<div class="card">
<img src="<?php echo $row['thumbnail'];?>" class="card-img" />
<div class="card-title">
<h3><?php echo $row['v_name'];?></h3>
<p><?php echo $row['v_models'];?></p>
</div>
</div>
</div>
<?php }?>
</body>
</html>
css style codes
body {
background-color:#282828;
}
a{
text-decoration: none;
}
.cards{
text-align: center;
font-size: 0;
}
.card{
margin: 0 10px;
width: 250px;
text-align: left;
display: inline-block;
font-size: medium;
}
.card-img{
width: 250px;
margin-bottom: -5px;
}
.card-title{
background-color: #FFFCF5;
width: 240px;
padding:5px;
margin-bottom: 15px;
color: #282828;
}
.card-title>p>a{
color: #00BFA5;
}
my page looks like this:
but I want to those pictures order side by side
I couldn't that. How could I do?
Thank you
You got .cards inside you while loop, take it out:
<body>
<div class="cards">
<?php include ("connect.php");
$data = $db->query("select * from videos order by id desc");
$data ->execute();
while ($row=$data->fetch(PDO::FETCH_ASSOC)) {?>
<div class="card">
<img src="<?php echo $row['thumbnail'];?>" class="card-img" />
<div class="card-title">
<h3><?php echo $row['v_name'];?></h3>
<p><?php echo $row['v_models'];?></p>
</div>
</div>
<?php }?>
</div>
</body>
The reason your code doesnt work, is because .card is inline-block which will place multiple card nexto eachother, but because you look the .cards (note the S) as well, you wrap each item in a div. A div is a block element, which means it'll take up one whole row, the next element will fall below it.
For each row from database you parse, you will have this following output:
`
<div class="cards">
<div class="card">
<img src="<?php echo $row['thumbnail'];?>" class="card-img" />
<div class="card-title">
<h3><?php echo $row['v_name'];?></h3>
<p><?php echo $row['v_models'];?></p>
</div>
</div>
</div>
`
So, all you have to do is to have the cotainer outside the while loop, like this:
`
<div class="cards">
<?php include ("connect.php");
$data = $db->query("select * from videos order by id desc");
$data ->execute();
while ($row=$data->fetch(PDO::FETCH_ASSOC)) {?>
<div class="card">
<img src="<?php echo $row['thumbnail'];?>" class="card-img" />
<div class="card-title">
<h3><?php echo $row['v_name'];?></h3>
<p><?php echo $row['v_models'];?></p>
</div>
</div>
<?php }?>
</div>
`
I know it's not exactly what you want, but try :
cards { display : flex ; flex-direction : row ; justify-content : space-between }
/ ! \ Doesn't work on IE8 and previous

PHP didn't see hard setup value for input when it is disabled

But... One problem is still appear. When I set up value for hard in HTML:
<div class="flex">
<div class="field">
<input name="subject_field" id="subject_field" placeholder="Temat" value="Testing" disabled>
<label class="icon" for="subject_field">
<i class="fa fa-star fa-fw" aria-hidden="true"></i>
</label>
</div>
</div>
My PHP code didn't see that in this field is something inside.
I want to have input for subject/topic and selection for subject/topic. I will be comment one of them if I don't need them. But also I want to have third variant - input for subject/topic with hard setup setup value. But this not working as I except.
Now that is the main problem. Why? And how to resolve this one. It is very important for me. Please advice.
UNDER IS THE MAIN QUESTION - one problem was solved by me.
Ok, I have to edit my question because I see that nobody can not understand me.
Well, so again:
I have very low knowledge about PHP, but even so I created simply contact form only in PHP. It works very well but I would like to upgrade it and I don't know how.
That contact form looks that:
It is in Polish because I from Poland. I am asking here because we do not have in Poland place like this for asking help.
Now, what I would like to change? You can see field named "Temat" (well it is not name, but placeholder)? It means Topic. Now everybody can topic message as they want. I want to change it and set up "hard" topics. Then everybody will only can choice my topics. So what is the problem?
Even if I now setup hard "topic" via "value=something" (in HTML) then PHP thinks that this field is empty and of course return error. I have to setup variable in PHP code.
I suppose if I now create new field for list choice then PHP still will be think that field is empty. And I don't want to create variables for each topic. I would like to setup PHP for reading what is in field and setup variable by self.
Now here I don't know what to do and how. Because I am newbie. Don't tell me go back to book and learn whole PHP. Please advice.
Here is code of PHP: https://github.com/IdolwSzutrab7/Contact-Form/blob/master/submit.php It is little long and I don't know to paste it here or not?
<?php
function died($error) {
echo '<p><h2>Wystąpił problem z działaniem skryptu.</h2></p>';
echo '<p>Wykryto następujące błędy:<ul>'.$error.'</ul></p>';
echo '<p>Wiadomośc nie została wysłana.</p>';
echo '<p>Kliknij tutaj, aby wrócić i spróbować ponownie.</p>';
//echo '<p>Kliknij tutaj, aby zamknąć kartę i spróbuj ponownie..</p>';
die();
};
function done() {
echo '<p><h1>Wiadomość została wysłana.</h1></p>';
}
if ( isset($_POST) ) {
// Adresat
$do = 'XXX'; // Adres e-Mail na który ma zostać wysłany formularz
// Dane formularza
$imie = $_POST['name_field'];
$email = $_POST['address_field'];
$telefon = $_POST['phone_field'];
$firma = $_POST['company_field'];
$temat = $_POST['subject_field'];
$wiadomosc = $_POST['message_field'];
$captcha = $_POST['g-recaptcha-response'];
// Nagłówek wiadomości e-Mail
$headers = array('From: "'.$imie.'" <'.$email.'>',
'Reply-To: '.$email,
'X-Mailer: PHP/' . PHP_VERSION);
$headers = implode("\r\n", $headers);
// ReCaptcha NoCaptcha
$secret = "XXX";
if (!$captcha) {
died('<li>Proszę wypełnić formularz reCAPTCHA.</li>');
exit;
}
$response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secret."&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
// Wytyczne do sprawdzenia danych
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
$imie_exp = "/^[A-Za-z ęóąśłżźćńĘÓĄŚŁŻŹĆŃ]+$/";
$telefon_exp = "/^[0-9 ]+$/";
// Sprawdzanie formularza w poszukiwaniu błędów
if ($response['success'] == false) { // Tutaj sprawdza, czy reCAPtCHa zwraca success
died('<li>Walidacja reCAPTCHA nie przeszła poprawnie!<br />Twoje działanie zostało zarejestrowane, a dane przesłane do administratora.</li>');
exit;
} else if ( !isset($_POST['name_field']) ||
!isset($_POST['address_field']) ||
!isset($_POST['message_field']) ) { // Tutaj jest bloczek, który sprawdza czy dane pola są uzupełnione
died('<li>Nie wszystkie wymagane pola zostały wypełnione.</li>');
} else if ( !preg_match($email_exp,$email) ) { // Tutaj sprawdza, czy e-Mail jest poprawnie uzupełniony
died('<li>Adres e-Mail nie wygląda na autentyczny.</li>');
} else if ( !preg_match($imie_exp,$imie) ) { // Tutaj sprawdza, czy Imię lub Nick nie zawiera jakichś dziwnych znaków
died('<li>Imię lub Nick zawiera nienaturalne znaki.</li>');
} else if ( !preg_match($telefon_exp,$telefon) && !$telefon == null ) { // Tutaj sprawdza, czy telefon zawiera cyfry tylko wtedy, gdy jest coś wpisane [inaczej widzi pole ktore jest ukryte i trkatuje je jako blad]
died('<li>Numer telefonu powinien zawierać wyłącznie cyfry.');
} else if ( strlen($wiadomosc) < 10 || strlen($wiadomosc)>1000 ) { // Tutaj sprawdza długość wiadomości
died('<li>Wiadomość jest zbyt krótka lub zbyt długa.');
} else if ( strlen($imie)>50 ||
strlen($email)>50 ||
strlen($telefon)>50 ||
strlen($firma)>50 ||
strlen($temat)>100 ) { // Tutaj jest bloczek, który sprawdza długość poszczególnych pól
died('<li>Przekroczono maksymalną ilość znaków w niektórych polach.</li>');
} else { done(); mail($do, $temat, $wiadomosc, $headers); };
} else {
died('<li>Nastąpiło nieoczekiwane zatrzymanie skryptu!</li>');
};
?>
And here is code of form in HTML: https://github.com/IdolwSzutrab7/Contact-Form/blob/master/index.php It is also little long.
<html>
<head>
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" />
<script type="text/javascript" src="//code.jquery.com/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="//www.google.com/recaptcha/api.js"></script>
</head>
<body>
<style>
body, html {margin:0;padding:0;}
#contact_form {
width: 600px;;
padding: 50px;
margin: 25px auto;
background: white;
background: url('https://zotabox.com/media/core/image/gallery/simplepopup/1d.jpg');
background-size: cover;
box-shadow: 0px 0px 30px -5px rgba(0,0,0,0.5);
} #contact_form div.flex {
display: flex;
width: 100%;
} #contact_form div.field {
position: relative;
width: 100%;
margin: 5px;
} #contact_form div.field input, #contact_form div.field textarea {
width: 100%;
box-sizing: border-box;
padding: 10px;
padding-left: 30px;
outline: none;
border: 1px solid rgba(0,0,0,0.2);
border-radius: 4px;
background: white;
font-family: Arial;
color: black;
} #contact_form div.field input:hover, #contact_form div.field input:focus,
#contact_form div.field textarea:hover, #contact_form div.field textarea:focus {
border: 1px solid rgba(0,0,0,0.4);
} #contact_form div.field #submit_button {
width: auto;
} #contact_form div.field #submit_button:hover {
cursor: pointer;
} #contact_form div.field .icon {
position: absolute;
top: 9px;
left: 7px;
color: rgba(0,0,0,0.5);
cursor: text;
} #contact_form div.field input:hover + .icon, #contact_form div.field input:focus + .icon,
#contact_form div.field textarea:hover + .icon, #contact_form div.field textarea:focus + .icon {
color: rgba(0,0,0,0.7);
}
</style>
<form id="contact_form" method="post" action="submit.php">
<div class="flex">
<div class="field">
<input name="name_field" id="name_field" placeholder="Twój nick lub imię">
<label class="icon" for="name_field">
<i class="fa fa-user fa-fw" aria-hidden="true"></i>
</label>
</div>
<div class="field">
<input name="address_field" id="address_field" placeholder="Twój adres e-Mail">
<label class="icon" for="address_field">
<i class="fa fa-envelope fa-fw" aria-hidden="true"></i>
</label>
</div>
</div>
<div class="flex">
<div class="field" style="display: none;">
<input name="phone_field" id="phone_field" placeholder="Twój numer telefonu">
<label class="icon" for="phone_field">
<i class="fa fa-phone fa-fw" aria-hidden="true"></i>
</label>
</div>
<div class="field" style="display: none;">
<input name="company_field" id="company_field" placeholder="Firma">
<label class="icon" for="company_field">
<i class="fa fa-briefcase fa-fw" aria-hidden="true"></i>
</label>
</div>
</div>
<div class="flex">
<div class="field">
<input name="subject_field" id="subject_field" placeholder="Temat">
<label class="icon" for="subject_field">
<i class="fa fa-star fa-fw" aria-hidden="true"></i>
</label>
</div>
</div>
<div class="flex">
<div class="field">
<textarea name="message_field" id="message_field" placeholder="Tutaj wpisz treść swojej wiadomości..." rows="7" maxlength="1000" spellcheck="true"></textarea>
<label class="icon" for="message_field">
<i class="fa fa-pencil fa-fw" aria-hidden="true"></i>
</label>
</div>
</div>
<div class="flex">
<div class="field">
<div class="g-recaptcha" data-sitekey="6LfnGigTAAAAAGsECHWJRKpajpJI0SYt24XFy8S-"></div>
</div>
<div class="field" style="text-align: right;"><div style="display: inline-block; position: relative;">
<input id="submit_button" type="submit" value="Wyślij">
<label class="icon" for="submit_button" style="cursor: pointer;">
<i class="fa fa-paper-plane fa-fw" aria-hidden="true"></i>
</label>
</div></div>
</div>
</form>
</body>
</html>
Well... When I setup value for "hard" like this:
Then I have to setup variable for "hard" in PHP, like this:
Otherwise PHP return error while send form.
I am sure at 90% that same situation will be when I add selection field in the form - I mean PHP will not recognize choice from selection. That is the problem.
Hmm... I think I found what is wrong. My PHP code only check if the value of specified fields are set. Not if they contains something. Even if value is empty for PHP it means it is set. Please look at this section:
if ( !isset($_POST['name_field']) ||
!isset($_POST['address_field']) ||
!isset($_POST['message_field']) )
So now the main question is how to rebuild it for checking if these values contains something not checking if they are set.
This code:
<input name="subject_field" id="subject_field" placeholder="Temat" value="Testing" disabled>
should be:
<input name="subject_field" id="subject_field" placeholder="Temat" value="Testing" readonly>
The disabled function in your code won't post the input value of "subject_field" to the PHP file.
If you want to make a selection so you just add a select tag in your html forms, just a simple as that. Also make sure that your value in selection correspond to your selection list.Below is the code
<select>
<option value="topic1">Topic 1</option>
<option value="topic2">Topic 2</option>
<option value="topic3">Topic 3</option>
</select>
Well... I think I resolve my problem (and appear another, please read to the end), but please check me and confirm.
I also give you test link but please don't spam too much - http://ts.isvn.pl/contactform/
The problem was from beginning with PHP code (I supposed that) but I didn't know where. I star thinking about that and I found:
} else if ( !isset($_POST['name_field']) ||
!isset($_POST['address_field']) ||
!isset($_POST['subject_field']) ||
!isset($_POST['message_field'])) { // Tutaj jest bloczek, który sprawdza czy dane pola są uzupełnione
died('<li>Nie wszystkie wymagane pola zostały wypełnione.</li>');
}
I read a few interesting questions here at stackoverflow (i.e. "php is null or empty?") and understand that what I had was wrong. Again I started thinking about that and start changing. I found working solution:
} else if ( $imie == NULL ||
$email == NULL ||
$temat == NULL ||
$wiadomosc == NULL ) { // Tutaj jest bloczek, który sprawdza czy dane pola są uzupełnione
died('<li>Nie wszystkie wymagane pola zostały wypełnione.</li>');
}
But that was not finish. I told you that I want my form modular. Some of fields I would like to turn on and turn off. I used just display: none in HTML:
<div class="flex" style="display: none;">
<div class="field">
<input name="subject_field" id="subject_field" placeholder="Temat" value="Testing" disabled>
<label class="icon" for="subject_field">
<i class="fa fa-star fa-fw" aria-hidden="true"></i>
</label>
</div>
</div>
But... For people like me this is hidden. But not for PHP code. I had to comment these lines. Otherwise PHP code still saw this code.
<!--
<div class="flex" style="display: none;">
<div class="field">
<input name="subject_field" id="subject_field" placeholder="Temat" value="Testing" disabled>
<label class="icon" for="subject_field">
<i class="fa fa-star fa-fw" aria-hidden="true"></i>
</label>
</div>
</div>
-->
So bad but I can handle this.
But... One problem is still appear. When I set up value for hard in HTML:
<div class="flex">
<div class="field">
<input name="subject_field" id="subject_field" placeholder="Temat" value="Testing" disabled>
<label class="icon" for="subject_field">
<i class="fa fa-star fa-fw" aria-hidden="true"></i>
</label>
</div>
</div>
My PHP code didn't see that in this field is something inside.
I want to have input for subject/topic and selection for subject/topic. I will be comment one of them if I don't need them. But also I want to have third variant - input for subject/topic with hard setup setup value. But this not working as I except.
Now that is the main problem. Why? And how to resolve this one. It is very important for me. Please advice.
I am post it as a answer because I resolve some of my problems and this message is too long for put it in the main question.
I am wondering why you have to make it like these
$imie == NULL ||
$email == NULL ||
$temat == NULL ||
$wiadomosc == NULL

PHP registration form: Make the inputs with red borders if there is an error [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm making a registration form with PHP and I'd like to do something: if user has not completed the form correctly, I want, in addition to the error message, make the inputs (where there is an error) with red borders.
My registration form (HTML part):
<?php if(!empty($errors)): ?>
<div class="flash-message error">
<h3>You have not completed the form correctly. The error(s) come(s) from the following thing(s):</h3>
<ol>
<?php foreach($errors as $error): ?>
<li>
<p><?= $error; ?></p>
</li>
<?php endforeach; ?>
</ol>
</div>
<?php endif; ?>
<h1 class="page-heading"><?php echo $title; ?></h1>
<form action="" method="post">
<ul>
<li>
<label for="nickname">Nickname:</label> <input id="nickname" name="nickname" type="text">
<p class="input-description">Your nickname will be as an identity on the site; it will be displayed wherever you will post, etc.</p>
</li>
<li>
<label for="email">Email:</label> <input id="email" name="email" type="text" placeholder="your#email.com">
<p class="input-description">Enter a valid email to receive the confirmation link to validate your account.</p>
</li>
<li>
<label for="password">Password:</label> <input id="password" name="password" type="password">
<p class="input-description">Enter a password to sign in to your account. Try to put a difficult password to make it more complicated to find.</p>
</li>
<li>
<label for="password-confirmation">Password Confirmation:</label> <input id="password-confirmation" name="password-confirmation" type="password">
<p class="input-description">Confirm the password that you have put in the field above.</p>
</li>
</ul>
<button type="submit" class="button primary">Sign Up</button>
</form>
Current result: http://prntscr.com/86h5r2
PHP code:
<?php
if(!empty($_POST))
{
/* Nickname */
if(empty($_POST["nickname"]))
{
$errors["nickname"] = "You have not completed the nickname field.";
}
elseif(!preg_match("/^[a-zA-Z0-9 _]+$/", $_POST["nickname"]))
{
$errors["nickname"] = "Your nickname is not valid.";
}
/* E-mail */
if(empty($_POST["email"]))
{
$errors["email"] = "You have not completed the email field.";
}
elseif(!filter_var($_POST["email"], FILTER_VALIDATE_EMAIL))
{
$errors["email"] = "Your email is not valid.";
}
/* Password */
if(empty($_POST["password"]))
{
$errors["password"] = "You have not completed the two password fields.";
}
elseif($_POST["password"] != $_POST["password-confirmation"])
{
$errors["password"] = "The passwords did not match. Please enter the same password in both fields.";
}
}
?>
to add a border to the input with error you would want to embed a php if statement like this in the class attributes. just define classname in your css
<input type="text" class="<?= isset($error['name']) ? 'has-error' : '' ?>" value="" >
Adding a style to the <li> is one way
<ol>
<?php foreach($errors as $error): ?>
<li style="border:red solid 1px">
<p><?= $error; ?></p>
</li>
<?php endforeach; ?>
</ol>
A better way would be to create some css and then just add a class to your <li>
<style>
.an-error-msg {
border:red solid 1px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px; /* future proofing */
-khtml-border-radius: 10px; /* for old Konqueror browsers */
}
</style>
<ol>
<?php foreach($errors as $error): ?>
<li class="an-error-msg">
<p><?= $error; ?></p>
</li>
<?php endforeach; ?>
</ol>
Why not just make it client side with the required attribute like this: https://jsfiddle.net/kn7qjg6c/
HTML
<form method="post">
<input type="text" placeholder="name" required/>
<input type="submit" />
</form>
CSS
input:required:focus {
border: 1px solid red;
outline: none;
}

Redirect if page is blank

I'm working on some sort of search engine that adds on to a URL to complete the request. using header(Location:http://www.WEBSITENAME.com/'. $search); Although sometimes this will send me to a blank page. Was wondering if there's any sort of code that will redirect me to another page if that error happens. I want the else to be what it redirects to if the page is blank. Thanks.
My code:
search.php
<?php
$search = $_POST["search"];
if(isset($_POST['search'])){
header('Location:http://cydia.saurik.com/package/'.$search);
}else{
?>
<?php
echo "
<head>
<style>
#header{
color:black;
}
.header{
color:black;
font-size:25px;
}
#header_minor{
margin-top:20px;
}
.header_minor{
font-size:18px;
}
a[class='header_minor']{
color:black;
}
body{
text-align:center;
margin-top:14%;
}
#idea{
margin-top:20px;
}
.hidden{
display:none;
visibility:hidden;
}
</style>
</head>
";
?>
<div id="header">
<span class="header">
Sorry, this tweak was not found...
</span>
</div>
<div id="header_minor">
<span class="header_minor">
Would you like to suggest it? or Return home
</span>
</div>
<div id="idea">
<form method="POST" action="idea.php" name="idea">
<input type="text" name="idea" value="<?php echo $_POST['search']; ?>"/>
<input type="text" name="hidden" class="hidden"/>
<input type="submit" value="Submit"/>
</form>
</div>
<?php
exit();
}
?>
It could have been better if you can call an api on that site so that you can interact easier with the external site.
I would do something like this:
PHP:
<?php
if(isset($_POST['search'])) {
$search_text = $_POST['search_field'];
$location_url = "http://cydia.saurik.com/package/{$search_text}/";
$content = #file_get_contents($location_url); // use this function to query on site
if($content) {
// redirect if it has a result
header("Location: {$location_url}");
} else {
// will go here if query on external site is empty (blank)
// create your own empty result page that says your search yielded no results (your own page, redirect the user)
// sample
header("Location: http://www.yoursite.com/index.php?noresults=1");
}
}
?>
HTML:
<form method="POST" action="index.php">
<input type="text" name="search_field" class="" id="" /><br/>
<input type="submit" name="search" class="" id="" value="Search" />
</form>
<?php if(isset($_GET['noresults'])): ?>
<div class="yourdesign" style="display: block; width: 300px; border: 1px solid black;";>
<h1>No results found</h1>
</div>
<?php endif; ?>

Codeigniter -> Undefined Variable

I am unsure as too why I am getting the following errors when trying to pass data through to my html email template -> The PHP errors are coming from the view.
Undefined variable: companyName -> line 9
Undefined variable: firstName -> line 12
Controller:
function _userRegEmail($activateCode,$email,$firstname,$lastname){
$data['companyName'] = $this->core_model->companyDetails()->coreCompanyName;
$data['companyEmail'] = $this->core_model->companyDetails()->coreContactEmail;
$data['companyContact'] = $this->core_model->companyDetails()->coreContactName;
$data['firstName'] = $firstname;
$data['lastName'] = $lastname;
$data['email'] = $email;
$data['activateCode'] = $activateCode;
$this->email->from($this->core_model->companyDetails()->coreContactEmail, $this->core_model->companyDetails()->coreCompanyName);
$this->email->to($email);
$this->email->subject($this->core_model->companyDetails()->coreCompanyName 'User Registration Confirmation');
$messageContent= $this->load->view('email_templates/userReg','', TRUE);
$this->email->message($messageContent);
$this->email->send();
echo $this->email->print_debugger();
}
View:
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<title/>
</head>
<body>
<div class="container" style="width: 600px;height: 100%;margin: 0 auto;font-family: Arial, "MS Trebuchet", sans-serif">
<div class="header" style="width: 100%">
<h1 style="text-align: center;color: #00afd8"><?php echo $companyName; ?></h1>
</div>
<div class="content">
<h2 style="font-size: 15px">Hello <?php echo $firstName; ?></h2>
<p style="margin-left: 15px">Thank you for signing up to Farm Ads.</p>
<p style="margin-left: 15px">Could you please click <a href="<?php base_url(); ?>users/confirm/"<?php $activateCode; ?>>here</a> to activate your account.</p>
<div class="from">
<p class="bold" style="margin-left: 15px;font-weight: bold;font-size: 12px">Regards,</p>
<p style="margin-left: 15px;font-weight: bold;font-size: 12px"><?php $companyContact; ?></p>
</div>
</div>
</div>
</body>
</html>
If you want to use the variables you have set in $data in the view you shouldn't do:
$messageContent= $this->load->view('email_templates/userReg','', TRUE);
But:
$messageContent= $this->load->view('email_templates/userReg', $data, TRUE);
This makes sure you send the variables to the view so they can be used in there like you are trying already.

Categories