Div css style load before the error in CodeIgniter - php

I am facing a problem which in my code the error div loads earlier before it shows the error . could someone please help me to fix that
this is my view file
<div class="alert alert-danger mg-b-0" role="alert">
<?php echo form_error('index'); ?>
<?php
if(isset($error)){
echo 'Your Index number is not registered with our system[enter image description here][1]' .
'<br />'.'Click here to Register'.
'<br />';
}else{
'<br />';
}
?>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
here is the screenshot of this

you already printed the alert before the check so if there is no $error it will already show an empty alert, you have to check first then echo your whole divs inside:
<?php if (isset($error)): ?>
<div class="alert alert-danger" role="alert">
<?php echo $error ?> <!-- or write whatever you want -->
</div>
<?php endif ?>

Related

How do I display an alert to the main-page.php, when the data is inserted successfully or not

THIS IS THE THE MAIN-PAGE.PHP upon clicking on the add button a modal will appear
THIS IS THE FORM THAT I PUT IN A BOOTSRAP MODAL, the form has an action="add.php" which is a seperated php file
this is the add.php code, I don't know how to display the $status on main-page.php because it is in the add.php file.
$run_sql = mysqli_query($conn, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($conn), E_USER_ERROR);
if ($run_sql===true){
move_uploaded_file($tmp_profile_img,"upload/$profile_img");
$status = '<div class="alert alert-info alert-dismissible fade show" role="alert">
<strong>The data has been inserted SUCCESSFULLY</strong> You should check in on some of those fields below.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
else{
$status = '<div class="alert alert-warning alert-dismissible fade show" role="alert">
<strong>The data was NOT inserted SUCCESSFULLY</strong> Please try again.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
header("Location:main-page.php");
?>
You can send query to the main-page.php , like this
header("Location:main-page.php?status=success");
in the main-page.php, you can get it, link this
$status = isset($_GET["status"]) ? $_GET["status"] : null
this worked
main-page.php
<?php
if(isset($_GET['status']) AND $_GET['status'] == 'success'){
echo '<div class="alert alert-info alert-dismissible fade show" role="alert">
<strong>Holy guacamole!</strong> You should check in on some of those fields below.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}elseif(isset($_GET['status']) AND $_GET['status'] == 'fail'){
echo '<div class="alert alert-warning alert-dismissible fade show" role="alert">
<strong>Holy guacamole!</strong> You should check in on some of those fields below.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}else{
echo '<div class="alert alert-info alert-dismissible fade show" role="alert">
<strong>Holy guacamole!</strong> You should check in on some of those fields below.
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>';
}
?>
add.php
$run_sql = mysqli_query($conn, $sql) or trigger_error("Query Failed! SQL: $sql - Error: ".mysqli_error($conn), E_USER_ERROR);
if ($run_sql===true){
move_uploaded_file($tmp_profile_img,"upload/$profile_img");
header("Location:main-page.php?status=success");
}
else{
header("Location:main-page.php?status=fail");
}
but I don't know if it's a clean code

Block registration if email already exists in mysqli database

Users can use the same email address for different registration.
Tried using different solutions from developers on Stack Overflow who have experienced the same problems that I have, including making the emailUsers column a UNIQUE KEY in the database table, and implementing some sort of jQuery, but not successful. Think the problem is I am missing an 'else if' block for duplicate email, but all the various ways I tried to implement this, it does not do anything.
<div id="signup">
<div class="container">
<div class="row">
<div class="col-sm-6 offset-sm-1">
<div class="signup-left position-fixed text-center">
<img src="img/200.png">
<br><br><br>
<?php
if(isset($_GET['error']))
{
if($_GET['error'] == 'emptyfields')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Fill In All The Fields
</div>';
}
else if ($_GET['error'] == 'invalidmailuid')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Please enter a valid email and user name
</div>';
}
else if ($_GET['error'] == 'invalidmail')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Please enter a valid email
</div>';
}
else if ($_GET['error'] == 'invaliduid')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Please enter a valid user name
</div>';
}
else if ($_GET['error'] == 'passwordcheck')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Passwords donot match
</div>';
}
else if ($_GET['error'] == 'usertaken')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> This User name is already taken
</div>';
}
else if ($_GET['error'] == 'invalidimagetype')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Invalid image type
</div>';
}
else if ($_GET['error'] == 'imguploaderror')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Image upload error, please try again
</div>';
}
else if ($_GET['error'] == 'imgsizeexceeded')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Image too large
</div>';
}
else if ($_GET['error'] == 'sqlerror')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Website Error: </strong> Contact admin to have the issue fixed
</div>';
}
}
else if (isset($_GET['signup']) == 'success')
{
echo '<div class="alert alert-success" role="alert">
<strong>Signup Successful</strong> Please Login from the login menu
</div>';
}
?>
<form id="signup-form" action="includes/signup.inc.php" method='post' enctype="multipart/form-data">
<input type="submit" class="btn btn-light btn-lg" name="signup-submit" value="Signup">
<br><br>
<a href="login.php">
<i class="fa fa-sign-in fa-2x social-icon" aria-hidden="true"></i>
</a>
<a href="contact.php">
<i class="fa fa-envelope fa-2x social-icon" aria-hidden="true"></i>
</a>
</div>
</div>
I want to be able to block a user from registering with the same email, and to generate an error message when the user tries to do this.
EXTRA INFO: Can post further, detailed methods of me trying to make the emailUsers column a UNIQUE KEY, but when I do this, new users can no longer register, even if they use a different email.

Laravel 4 Redirect with global styling

Does anyone know where and how to style the redirect with global such as:
return Redirect::route('home')
->with('global', 'Your content has been posted!');
I want to use the bootstrap alerts with the global message
I just needed to put the styling after the global
Here is what I did:
return Redirect::route('admin-console-post')
->with('global', '
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
Your content has been posted successfully!
</div>
');
You need to style it in view like this:
#if(Session::has('global'))
<div class="output">
{{ Session::get('global') }}
</div>
#endif
Where output is class in which you put style of your choice.
Hope it helps ^^.

Using Language Class in Controller (CodeIgniter)

First of all, I made research but couldn't find anything about it.
I'm sending flash data to users when they update or add something. My controller file's related part is like this;
function hizmet_ekle()
{
if($this->mhizmetler->hizmet_ekle())
{
$this->session->set_flashdata('ok', 'hizmet sisteme eklendi!');
redirect('panel/hizmetler');
}
else
{
$this->session->set_flashdata('hata', 'Bir hata oluştu. Lütfen tekrar deneyin!');
redirect('panel/hizmetler');
}
}
And my view's related parts are like this;
<?php if($this->session->flashdata('ok')): ?>
<div class="alert alert-success fade in widget-inner">
<button type="button" class="close" data-dismiss="alert">×</button>
<i class="fa fa-check"></i> <?php echo $this->session->flashdata('ok');?>
</div>
<?php endif; if($this->session->flashdata('hata')): ?>
<div class="alert alert-danger fade in widget-inner">
<button type="button" class="close" data-dismiss="alert">×</button>
<i class="fa fa-times"></i> <?php echo $this->session->flashdata('hata');?>
</div>
<?php endif; echo validation_errors('
<div class="alert alert-danger fade in widget-inner">
<button type="button" class="close" data-dismiss="alert">×</button>
<i class="fa fa-times"></i> ', '
</div>'); ?>
My system has a few different languages, it means I have to send different notification messages(session flashdata's) for each language but I can't use lang key in my controller file. How can I handle it?
Thanks in advance.
I found it!
I have to use it like this;
$this->session->set_flashdata('ok', $this->lang->line("greek"));

Twitter bootstrap how to hide error message on initialization?

I have simple alert message which should show up only when there is error. However I don't know how to hide message on initialization. If I manually hide the message then error message stays hidden even when there is error.
<div class="alert alert-error">
<button class="close" data-dismiss="alert" type="button">×</button>
<?php echo $error?>
</div>
Try this
<?php if(isset($error)): ?><div class="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
<?php echo $error; ?>
</div>
<?php endif; ?>
make sure that you include bootstrap.js and jquery.js correctly

Categories