I can't find solution to my problem...
I've created some kind of deck builder and when I choose cards to deck (which is empty on the begining $scope.deck = []) I would like to insert it to database.
I have form like this:
<form name="myform">
<div class="form-group">
<label for="name">Name</label>
<input type="text" id="name" name="name" ng-model="showCrudData.name" class="form-control" />
</div>
<div class="form-group">
<label for="type">Deck Type</label>
<input type="text" id="type" name="type" ng-model="showCrudData.type" class="form-control" />
</div>
<div class="form-group">
<label for="class">Class</label>
<input type="text" id="class" name="class" ng-model="showCrudData.class" class="form-control" />
</div>
<div class="form-group">
<label for="author">Author</label>
<input type="text" id="author" name="author" ng-model="showCrudData.author" class="form-control" />
</div>
<label for="cards">Deck</label>
<p type="value" id="cards" name="cards" ng-model="showCrudData.cards">{{cards}}</p>
Add
<button type="reset" class="btn btn-default">Reset</button>
</form>
Im trying to insert {{cards}} into database as u can see, but its not working.
Here is my testing page where Im trying to solve the problem. The Deck label before choosing cards is looking like this []
And thats part of my PHP file where I insert values into table
case "add":
if(!empty($_POST['data'])){
$sql = "INSERT INTO decks values ('',:nm,:tp,:cl,:au,:cd)";
$insert = $query = $db->prepare($sql);
$query->execute(array(":nm"=>$_POST['data']['name'],":tp"=>$_POST['data']['type'],":cl"=>$_POST['data']['class'],":au"=>$_POST['data']['author'],":cd"=>print_r($_POST['data']['cards'])));
I tried to solve problem adding print_r, but it didnt work because its just adding number "1" into column "deck" in table.
Related
I'm trying to duplicate 4 input text. For example I want to duplicate 'Produk Simpanan Saham', then only 4 input on 'Produk Simpanan Saham' div will be duplicated. I already tried a few methods using jQuery but it seem doesn't work.
<form action="" method="post" class="form-horizontal">
<br><br>
<div class="form-group">
Upload File :
<input type="file" name="file">
</div>
<div class="saham">
<div class="w3-container w3-black">
<h3>
<center>Produk Simpanan Saham</center>
</h3>
</div>
<label for="kp_produk">Kode Produk :</label>
<input type="text" name="kp_produk" class="form-control">
<br>
<label for="produk_saham">Produk :</label>
<input type="text" name="produk_saham" class="form-control">
<br>
<label for="bunga_saham">Bunga :</label>
<input type="text" name="bunga_saham" class="form-control">
<br>
<label for="ket_saham">Keterangan :</label>
<input type="text" name="ket_saham" class="form-control">
</div>
<div class="harian">
<div class="w3-container w3-black">
<h3>
<center>Produk Simpanan Harian</center>
</h3>
</div>
<label for="kp_harian">Kode Produk :</label>
<input type="text" name="kp_harian" class="form-control">
<br>
<label for="produk_harian">Produk :</label>
<input type="text" name="produk_harian" class="form-control">
<br>
<label for="bunga_harian">Bunga :</label>
<input type="text" name="bunga_harian" class="form-control">
<br>
<label for="ket_harian">Keterangan :</label>
<input type="text" name="ket_harian" class="form-control">
</div>
you mush have blueprint of field first like
var blueprint= '<div class="saham">'+
'<div class="w3-container w3-black">'+
'<h3>'+
'<center>Produk Simpanan Saham</center>'+
'</h3>'+
'</div>'+
'<label for="kp_produk">Kode Produk :</label>'+
'<input type="text" name="kp_produk[]" class="form-control">'+
'<br>'+
......
used [] for all name field to get array request when you send form to server
example :
'<input type="text" name="kp_produk[]" class="form-control">'+
and make button add like (jquery) example
<button onclick="$('form').append(blueprint)">add</button>
just use
var dom=$($('.saham')[0]).clone();
//copy dom
$('.form-horizontal').html(dom):
//paste dom
dont forget to add [] on name tag dom input to set data send to array, because if you not set. data with key kp_produk value is last tag name with name kp_produk
if you use [] (kp_product[]) data will set to array
kp_product=['anu1',anu2];
So, I have my SPA at about 98% functional. The app pulls data from a MySQL database and allows the user to edit/delete records. For the page in question, it will edit/delete data of the specified student ID but it will not properly display the data in the text fields.
If you do not input a value it will display the first item in the JSON array but not the one you specify in the search field.
I did not do a very good job at explaining that but here is the HTML page that uses a function to pass data to the controller which then selects the corresponding student by ID and assigns it to the variable $scope.student. I then try to display the student data on the HTML page by using student.first_name (or any property) but it does not work correctly.
<h3>Edit/Delete Student with ID: {{student.student_id}}</h3>
<div class="form-group">
<label for="sid">Student ID:</label>
<input type="text" class="form-control" id="sid" ng-model="sid">
</div>
<p><button type="button" class="btn btn-primary" ng-click="getRecord(sid)">
Get Student Info </button> </p>
<div class='row'>
<div class="col-md-6">
<div class="form-group">
<label for="first_name">First Name:</label>
<input type="text" class="form-control" id="first_name" ng-model="student.first_name">
</div>
<div class="form-group">
<label for="last_name">Last Name:</label>
<input type="text" class="form-control" id="last_name" ng-model="student.last_name">
</div>
<div class="form-group">
<label for="hrs_completed">Hrs Completed:</label>
<input type="text" class="form-control" id="hrs_completed" ng-model= "student.hrs_completed">
</div>
<div class="form-group">
<label for="hrs_attempted">Hrs Attempted:</label>
<input type="text" class="form-control" id="hrs_attempted" ng-model= "student.hrs_attempted">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="gpa_points">GPA Points:</label>
<input type="text" class="form-control" id="gpa_points" ng-model= "student.gpa_points">
</div>
<div class="form-group">
<label for="major">Major:</label>
<input type="text" class="form-control" id="major" ng-model="student.major">
</div>
<div class="form-group">
<label for="advisor_id">Advisor ID:</label>
<input type="text" class="form-control" id="advisor_id" ng-model="student.advisor_id">
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="text" class="form-control" id="email" ng-model="student.email">
</div>
</div>
<button type="button" class="btn btn-primary" ng-click="updateRecord()">Update</button>
<button type="button" class="btn btn-primary" ng-click="deleteRecord()">Delete</button>
And here is my controller on my Javascript page:
app.controller('editCtrl', function($scope, $http) {
$http.get("getStudentData.php")
.then(function (response) {
$scope.students = response.data;
});
$scope.getRecord = function(sid) {
id = sid;
$scope.student = $scope.students.find(s=>s.id == sid);
};
Do I need to make a seperate GET request to the server for this to work properly or do I just need to reference the student object differently?
I think there is mismatch in what you are getting as response.data and what you are trying to .find() and then what you are binding on html.
Check this plunkr.
You are trying to render by searching id property.
$scope.students.find(s=>s.id == sid);
where as you are rendering on UI using student_id property.
{{student.student_id}}
So, surely there is mismatch in what you are getting as response.data and what you are rendering using $scope.student properties. I think my plunkr will show that your function is correct.
In case this answer doesn't work, share your response.data.
I'm trying to save a multiple database records with image name and thumb(for now only text inputs). Every image has also a category/categories (made by multiselect and pivot table between image and categories with many to many relation). The question is: how to sync/attach those categories? I do not want to use foreach ::create, because it will generate unnecessary database requests. For now I have something like this:
my blade file (part in form)
<form action="/panel/images" method="POST">
{{ csrf_field() }}
<div class="form-group">
<label for="row[1][title]">Image title</label>
<input type="text" name="row[1][title]" class="form-control" />
</div>
<div class="form-group">
<label for="row[1][thumb]">Thumb</label>
<input type="text" name="row[1][thumb]" class="form-control" />
</div>
<!-- date because insert methode don't create timestamps autimatically-->
<input type="hidden" name="row[1][created_at]" value="{{ $date }}" />
<input type="hidden" name="row[1][updated_at]" value="{{ $date }}" />
<div class="form-group">
<label for="multi[0][]">Categories</label>
<select name="multi[0][]" multiple>
#include('layouts.images_categories_select')
</select>
</div>
<div class="form-group">
<label for="row[2][title]">Image title</label>
<input type="text" name="row[2][title]" class="form-control" />
</div>
<div class="form-group">
<label for="row[2][thumb]">Thumb</label>
<input type="text" name="row[2][thumb]" class="form-control" />
</div>
<div class="form-group">
<label for="multi[1][]">Categories</label>
<select name="multi[1][]" multiple>
#include('layouts.images_categories_select')
</select>
</div>
<input type="text" name="row[2][created_at]" value="{{ $date }}" />
<input type="text" name="row[2][updated_at]" value="{{ $date }}" />
<div class="form-group">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
And the controller
public function store(Request $request)
{
$image = new Image;
$inputs = Input::get('row');
$multiSelect = Input::get('multi');
$image::insert($inputs);
$image->images_catetories()->sync($multiSelect);
return redirect()->route('newImage')->with('status', 'images added');
}
EDIT:
Right now it throws an error "SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list' (SQL: insert into image_images_category (0, image_id, images_category_id, 1) values (18, , 1, 19))"
where "image_images_category" is my pivot table and values 18, 1, 19 are from multiselect.
I'm currently working on Laravel 5.2 and I'm finding difficult to fetch value from textarea inside controller.
I've tried $request->input just like we used to fetch values from inputs but it's not working in my case. I have done this far.
managecategories.blade.php
<form action="/addcategories" method="post" id="addcategory_form" name="addcategory_form">
<div>
<label>Insert Category</label>
<input type="text" name="category" data-validation="required" data-validation="custom" data-validation-regexp="^[a-zA-Z ]{2,30}$">
</div>
<div>
<label>Insert Category</label>
<textarea name="category" data-validation="required" data-validation="custom" data-validation-regexp="^[a-zA-Z ]{2,30}$" row="5" col="200"></textarea>
</div>
<input type="submit" value="Add Category" id="category_btn">
</form>
AdminAjaxController
public function addcategory(Request $request)
{
$category=$request->input('category');
$category_description=$request->input('description');
$insertcategory= DB::insert('insert into categories(category_name,description) values(?, ?)',[$category,$category_description]);
$fetch_category= DB::select('select category_name,category_id from categories');
return response()->json(array('add_category' => $category),200);
}
Oops Pity me! Both fields are named category. I need to change the name on the textarea to description caught by Aynber.
here is the edited and correct code
<form action="/addcategories" method="post" id="addcategory_form" name="addcategory_form">
<div>
<label>Insert Category</label>
<input type="text" name="category" data-validation="required" data-validation="custom" data-validation-regexp="^[a-zA-Z ]{2,30}$">
</div>
<div>
<label>Insert Category</label>
<textarea name="description" data-validation="required" data-validation="custom" data-validation-regexp="^[a-zA-Z ]{2,30}$" row="5" col="200"></textarea>
</div>
<input type="submit" value="Add Category" id="category_btn">
thanks mate! :)
I have several question and I hope there is answer that makes it true!
I'm very beginner in PHP but I like challenging with codes! I created a form like below in "test.html" file:
<form method="post" action="process.php">
<div class="col-lg-6 col-lg-push-6">
<div class="form-group">
<label>name</label>
<input class="form-control" type="text" name="name">
</div>
<div class="form-group">
<label>family</label>
<input class="form-control" type="text" name="family">
</div>
</div>
<div class="col-lg-6 col-lg-pull-6">
<div class="form-group">
<label>email</label>
<input class="form-control" type="email" name="email">
</div>
<div class="form-group">
<label>phone</label>
<input class="form-control" type="phone" name="phone">
</div>
<div class="radio">
<label>choose one of the options</label>
<label>
<input type="radio" name="order" value="box1"> box1
<input type="radio" name="order" value="box2"> box2
<input type="radio" name="order" value="box3" checked> box3
</label>
</div>
</div>
<div class="col-lg-12">
<input class="btn btn-primary btn-xs btn-block" value="send" style="color:#fff;" type="submit" name="submit" />
</div>
</form>
and then I created a PHP code to give data from users and send it to database like below:
<?php
$connect=mysqli_connect('server_name','database_username','password','database_name');
if(mysqli_connect_errno($connect))
{echo 'Failed to connect';}
$name = $_POST['name'];
$family = $_POST['family'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$order = $_POST['order'];
mysqli_query($connect,"INSERT INTO table_name(name,family,email,phone,order)
values('$name','$family','$email','$phone','$order')");
if(mysqli_affected_rows($connect)>0)
{echo '<p>sent!</p>'echo 'GO BACK';}
else
{echo 'it's failed.';echo 'mysqli_error($connect)';} ?>
And my table that I created is :
create a table with id => int unsigned auto-increment primary and name,
family and email => varchar(50) latin1_swedinsh_ci and
phone => int(20) and
order => varchar(20) latin1_swedinsh_ci
My questions are :
is my ip address equal to ip:2082 ? or domain:2082? or it's wrong!?
my username and password of database that i set in my php code is quite easy to hacked! is any way to solve this? i guess that my pirivilage is my answer!
I set ip:2082 and filled out my form and click submit button and either say "sent" nor "it's failed!"... I think it's connected but didn't insert my data into table!
2082 is not related to your ip address, is the web server port. By default is 80, and you can just ignore, but sometime is different and this is why you need to specify on the url.
Password are stored on php file because php files are stored on your server and user cannot have access to them.