I want to make an edit form , but I have a problem when displaying the data . This is a warning in my code ..
A PHP Error was encountered
Severity: Notice
Message: Undefined index: pakar_username
Filename: m_pakar/edit_pakar.php
Line Number: 20
This is my view:
<form method="post" role="form" action="<?=base_url()?>admin/m_pakar/edit_pakar?>">
<label>Username</label>
<input class="form-control" type="username" name="username" value="<?php echo $coba['pakar_username']?>" ><br>
<label>Password</label>
<input class="form-control" type="text" name="password" value="<?php echo $coba['pakar_password']?>"><br>
<label>Email</label>
<input class="form-control" type="email" name="email" value="<?php echo $coba['pakar_email']?>" ><br>
<button type="submit" class="btn btn-success">Update</button>
</form>
My Controller:
public function edit_pakar($id){
$this->general->set_table('data_pakar');
$this->general->order('pakar_id', 'asc');
$datasend['coba'] = $this->general->get_result_array();
$datasave = array(
'pakar_username' => $this->input->post('username', TRUE),
'pakar_password' => md5($this->input->post('password', TRUE)),
'pakar_email' => $this->input->post('email', TRUE),
);
$this->general->set_table('data_pakar');
$this->general->where($datasave);
$this->general->update($datasave);
$dataview['content'] = $this->load->view('admin/m_pakar/edit_pakar', $datasend, TRUE);
$this->load->view($this->template, $dataview);
}
Is there something wrong with my code ? not only pakar_username , but all existing data on the edit form doesn't show.
Why have you got all this bloated code in your controller? Move the Database stuff to a model...
HTML Form Fix:
<form method="post" role="form" action="<?=base_url()?>admin/m_pakar/edit_pakar">
Secondly, you're not pushing the details in "datasave" to the view, you're only pushing "datasend", so I adjusted for "coba2" incase you need coba...
$datasend['coba'] = $this->general->get_result_array();
$datasave = array(
'pakar_username' => $this->input->post('username', TRUE),
'pakar_password' => md5($this->input->post('password', TRUE)),
'pakar_email' => $this->input->post('email', TRUE),
);
$datasend['coba2'] = $datasave;
Now edit input fields as so:
value="<?php echo $coba2['pakar_username']?>"
Related
I am uploading an image to a folder and saving data to the database. How can I solve this error? The error is in the following line...
$property_features_image->move($destinationPath,$property_features_image);
public function store(Request $request)
{
$this->validate($request, [
'property_feature' => 'required|unique:property_features,property_features_name',
'property_icon' => 'required|image|mimes:jpg,png,jpeg|max:10240',
]);
$property_features_name = $request->property_feature;
$property_features_image = $request->file('property_icon');
$property_features_image = $property_features_image->getClientOriginalExtension();
$destinationPath = public_path('/images');
$property_features_image->move($destinationPath, $property_features_image);
DB::table('property_features')->insert([
'property_features_name' => $property_features_name,
'property_features_image' => $property_features_image,
]);
}
Blade
<form method="post" enctype="multipart/form-data" action="{{url('/admin/property-features')}}">
<div class="form-group">
<input type="hidden" value="{{csrf_token()}}" name="_token"/>
<label for="Property">Add Property Feature</label>
<input type="text" class="form-control" id="property_feature" name="property_feature"
placeholder="Enter Property Feature">
<label for="exampleFormControlFile1">Property Features's Icon</label>
<input type="file" class="form-control-file" id="property_icon" name="property_icon">
<?php echo($errors->first('property_feature', "<li class='ab' style='color:red;'>:message</li>"));?>
<?php echo($errors->first('property_icon', "<li class='ab' style='color:red;'>:message</li>"));?>
</div>
</form>
This line:
$property_features_image = $property_features_image->getClientOriginalExtension();
Assigns $property_features_image variable to a string value.
And strings cannot have any methods (you are trying to call move() method).
So removing the line should help, but then you must ensure everything else is ok. The getClientOriginalExtension() might be required somewhere, but we don't see all the code.
So I'm new to codeigniter and developing a viewing catalogue website. And so far my update function isn't working and I've been at this for 3 hours
so here's my view:
<?php echo validation_errors(); ?>
<?php echo form_open('catalogPages/updateEvent'); ?>
<input type="hidden" name="id" value="<?php echo $events['event_id']; ?>">
<div class="form-group">
<label>Title</label>
<input type="text" class="form-control" name="title" placeholder="Add
Title" value= "<?php echo $events['event_name']; ?>">
</div>
<div class="form-group">
<label>Body</label>
<textarea id="editor1" class="form-control" name="body" placeholder="Add
Body" value = "<?php echo $events['event_desc']; ?>"></textarea>
</div>
<button type="submit" class="btn btn-default">Submit</button>
My Model:
public function editEvent()
{
$data = array(
'event_name' => $this->input->post('event_name'),
'event_desc' => $this->input->post('event_desc'),
'event_id' => $this->input->post('event_id')
);
$this->db->where('event_id', $this->input->post('event_id'));
return $this->db->update('events', $data);
}
Controller:
public function editEvent($id = NULL)
{
$this->load->model('event_model');
$data['events'] = $this->event_model->get_event($id);
$this->load->view('adminEventUpdate', $data);
}
public function updateEvent()
{
$this->load->model('event_model');
//$id = $this->input->posts('event_id');
$this->event_model->editEvent();
}
It works but so far when I try to update the data doesn't seem to be updated but rather doesn't change at all.
When this Html form is submitted, the $_POST array has the keys:
'id', 'title', and 'body'.
There are no inputs named 'event_id', 'event_name', 'event_desc'.
The Html input properties 'name' need to change.
This is my form :
<form method = "POST" action = "<?php echo base_url('Usercontroller/insert') ?>">
<div class="form-group">
<label for="exampleInputEmail1">Apartament</label>
<input type="text" name ="txtApartament" class="form-control" id="txtApartament" placeholder="Apartament">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Status</label>
<select name ="txtStatus" class="form-control">
<?php foreach($getStatus as $value) { ?>
<option value = "<?php echo $value->per_id ?>"><?php echo $value->status_name;?></option>
<?php }?>
</select>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Nume</label>
<input type="text" name ="txtNume" class="form-control" id="txtNume" placeholder="Nume">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Persoane</label>
<input type="text" name ="txtPersoane" class="form-control" id="txtPersoane" placeholder="Personae">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Mp</label>
<input type="text" name ="txtMp" class="form-control" id="txtMp" placeholder="Mp">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Comentariu</label>
<input type="text" name ="txtComentariu" class="form-control" id="txtComentariu" placeholder="Comentariu">
</div>
<button type="submit" class="btn btn-default">Salveaza</button>
</form>
And this is my controller insert function side:
public function insert() {
$datai= $this->input->post();
if(isset($datai)){
$txtApartament = $datai['txtApartament'];
$txtStatus = $datai['txtStatus'];
$txtNume = $datai['txtNume'];
$txtPersoane = $datai['txtPersoane'];
$txtMp = $datai['txtMp'];
$txtComentariu = $datai['txtComentariu'];
$this->Usermodel->insertUser($txtApartament,$txtStatus,$txtNume,$txtPersoane,$txtMp,$txtComentariu);
redirect('');
}
}
Model side:
public function insertUser($apartament, $status, $nume, $persoane, $mp, $comentariu){
$arrayDates = array(
'apartament' => $apartament,
'per_id' => $status,
'nume' => $nume,
'persoane' => $persoane,
'mp' => $mp,
'comentariu' => $comentariu
);
$this->db->insert('membri', $arrayDates);
}
When I will submit on my forum I will get this :
A Database Error Occurred
Error Number: 1048
Column 'apartament' cannot be null
INSERT INTO `membri` (`apartament`, `per_id`, `nume`, `persoane`, `mp`, `comentariu`) VALUES (NULL, NULL, NULL, NULL, NULL, NULL)
Filename: models/Usermodel.php
Line Number: 28
Also this:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: txtApartament
Filename: controllers/Usercontroller.php
Line Number: 18
Backtrace:
File: /var/www/html/adminigniter1/application/controllers/Usercontroller.php
Line: 18
Function: _error_handler
File: /var/www/html/adminigniter1/index.php
Line: 315
Function: require_once
When my controller gets the data, will make it NULL, my form is passing the data correctly(checked the headers), what can be the issue on the controller side ?
And yes, I have set the helper with url and form!
I found the solution, wasn't from my code, it was apache2 ...
in the rewrite.load file in apache, I added the line :
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
And it worked!
I've made a login function in which I render a template after checking the login and password. This's the form that i've made inside a template.
<form action="{{ path("login") }}" method="post" id="formulaire_connexion">
<label class="control-label">Email
<input type="text" name="email" id="email" placeholder="your#email.com" onclick="this.select()"/>
</label>
<label class="control-label">Password</br>
<input type="password" name="password" id="password" placeholder="*********" onclick="this.select()"/>
</label>
<input type="checkbox" id="remember_me" name="remember_me"><label for="remember_me">Remember me </label></br>
<button type="submit" id="connexion" name="connexion">Connexion</button>
</form>
And this's the logging check method :
public function loginAction(Request $request)
{
$mail = $request->get('email');
$pass = $request->get('password');
$oauth = new OAuth($mail, $pass);
$baseUrl = "http://api.localhost/v1/";
$connexion = "{$baseUrl}login/".$mail."/".$pass;
$oauth->fetch($connexion, $_REQUEST, OAUTH_HTTP_METHOD_GET);
$reponseInformations = json_decode($oauth->getLastResponse(), true);
if (!$reponseInformations) {
$data['erreur'] = "Bad credentials";
return $this->render('EspacePointDeVenteBundle:Authentication:authentication.html.twig', array(
'erreur' => $data,
));
}else{
return $this->render('EspacePointDeVenteBundle:Home:index.html.twig', array(
'reseau' => $reseau,
'identifiant' => $key,
'key' => $identifiant,
));
}
}
After a wrong login connexion I render the same login template, but the routing is changed to /login instead of havig /index per example. What I need to know how to keep the same routing even if we called a foreign method.
I am trying to get the login to work in Kohana, but so far it fails to log the user in.
I have been successfully able to create new users, so I have all the tables set up.
My view for the login page is as follows,
<td style="vertical-align:top">
<div id="log_in">
<form class="pure-form pure-form-stacked" action="/kohana-blog/index.php/signup/login" method="post">
<fieldset>
<legend>Log In</legend>
<label for="username">Username</label>
<input id="username" name="username" type="text" placeholder="nonamedude" required>
<label for="password">Password</label>
<input id="password" name="password" type="password" placeholder="Password" required>
<label for="remember" class="pure-checkbox"></label>
<input id="remember" type="checkbox"> Remember me
<br>
<button type="submit" class="pure-button notice">Log In</button>
</fieldset>
</form>
</div>
</td>
My controller is as follows
$this->template->content = View::factory('signup/home')
->bind('message', $message);
if (HTTP_Request::POST == $this->request->method())
{
$remember = array_key_exists('remember', $this->request->post()) ? (bool) $this->request->post('remember') : FALSE;
$remember = FALSE;
$user = Auth::instance()->login($this->request->post('username'), $this->request->post('password'), $remember);
if ($user)
{
Request::current()->redirect('signup/home');
}
else
{
$message = "login failed";
}
}
I can't figure out why it doesn't authenticate the user.
My auth.php is as follows:
'driver' => 'orm',
'hash_method' => 'sha256',
'hash_key' => 'somerandomstring',
'lifetime' => 1209600,
'session_type' => Session::$default,
'session_key' => 'auth_user',
Additionally, the roles_users table have the correct values and the users table has the data from the form.
Is there a way to debug this to find the source of the issue?
First of all make sure your user has login role assigned in roles_users table.
By default you won't be able to login if you don't have this role.
Btw. it's cleaner to write:
$post = $this->request->post();
$user = Auth::instance()->login($post['email'], $post['password'], isset($post, 'remember'));