here are is the code.no matter what i did couldnt connect to mysql database in phpadmin in the wampserver all attempts has failed please help to solve
if (isset($_POST['continue'])) {
$j=0;
while ($j < $passengers)
{
$register_data2 = array(
'first_name' => $_POST["fname"][$j],
'last_name' => $_POST["lname"][$j],
'passport' => $_POST["passport"][$j],
'visa' => $_POST["visa"][$j],
'address1' => $_POST["address1"][$j],
'address2' => $_POST["address2"][$j],
'email' => $_POST["email"][$j],
'contact' => $_POST["contact"][$j],
'pin' => $_POST["pin"][$j],
'leaving_from' => $pieces[0],
'going_to' => $pieces[2],
'depart_date' => $pieces[7],
'depart_time' => $pieces[12],
'arrival_time' => $pieces[17],
'grand_fare' => $pieces[22],
'returning_from' => $pieces1[0],
'returning_to' => $pieces1[2],
'returning_date' => $pieces1[7],
'returning_time' => $pieces1[11],
'reaching_time' => $pieces1[16],
'fare' => $pieces1[21]
);
session_start();
$_SESSION['ticket'][] = $_POST["fname"][$j];
$_SESSION['ticket'][] = $_POST["lname"][$j];
$_SESSION['ticket'][] = $_POST["passport"][$j];
$_SESSION['ticket'][] = $_POST["visa"][$j];
$_SESSION['ticket'][] = $_POST["pin"][$j];
register_passenger($register_data2);
$j = $j+1;
}
$_SESSION['ticket1'] = $pieces[0];
$_SESSION['ticket2'] = $pieces[2];
$_SESSION['ticket3'] = $pieces[7];
$_SESSION['ticket4'] = $pieces[12];
$_SESSION['ticket5'] = $pieces[17];
$_SESSION['ticket6'] = $pieces[22];
$_SESSION['ticket11'] = $pieces1[0];
$_SESSION['ticket22'] = $pieces1[2];
$_SESSION['ticket33'] = $pieces1[7];
$_SESSION['ticket44'] = $pieces1[11];
$_SESSION['ticket55'] = $pieces1[16];
$_SESSION['ticket66'] = $pieces1[21];
}
?>
<?php
if (isset($_POST['pay'])){
if ($_POST['cash'] != $grand_total) {
echo "*Pay the given amount!"."<br>";
}
else{
header ('Location: ticket.php');
}
}
?>
<h2> Select payment method </h2>
<form action="payment.php" method="post">
<input type="radio" name="payment" id="cash" checked="checked" value="cash">
<label for="cash">Cash</label>
<input type="number" id="cash" name="cash" size="8"><br><br>
<input type="radio" name="payment" id="card" value="card">
<label for="card">Card</label>
<select>
<option>Debit card</option>
<option>Credit card</option>
</select>
<br>
<img src="Credit.jpg">
<br>
<input type="submit" name="pay" value="Make payment">
</form>
<?php
if(isset($_POST["Continue"])){
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];
$passport = $_POST['passport'];
$visa = $_POST['visa'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$email = $_POST['email'];
$contact = $_POST['contact'];
$pin = $_POST['pin'];
mysql_query( "INSERT INTO passengers (first_name,last_name,passport,visa,address1,address2,email,contact,pin) VALUES('$lastname','$passport','passport','$visa','$address1','$address2','$email','$contact','$pin')");
}
?>
i couldnt connect the data to mysql database in the phpadmin in the wampserver. it shows up nothing. as you can see below one of my many attempt to correct to make it work it up as fail. non of the method that i tried didnt work. please help to sove this problem
It seems you messed up the values list:
mysql_query( "INSERT INTO passengers
(first_name,last_name,passport,visa,address1,address2,email,contact,pin)
VALUES
('$lastname','$passport','passport','$visa','$address1','$address2','$email','$contact','$pin')");
First name is missing, 'passport' should not be there, etc. It should be:
('$firstname','$lastname','$passport','$visa','$address1','$address2','$email','$contact','$pin')");
Related
could someone help me to find the error? only the post_image input is saved the others are not saved in the database what am I doing wrong?
I've checked it several times but only the filename of the post_image field is saved in the database, the other files are not persisting in the database, could someone help me where I'm going wrong?
Every help is welcome.
Thank you very much in advance.
create.blade.php
div class="form-group row">
<label for="post_image" class="col-md-4 col-form-label text-md-right">{{ __('Image') }}</label>
<div class="col-md-6">
<input type="file" name="post_image"/>
#error('post_image')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<br>
<hr>
<label for="post_video" class="col-md-4 col-form-label text-md-right">{{ __('Video') }}</label>
<div class="col-md-6">
<input type="file" name="post_video"/>
#error('post_video')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<br>
<hr>
<label for="post_gif" class="col-md-4 col-form-label text-md-right">{{ __('GIF') }}</label>
<div class="col-md-6">
<input type="file" name="post_gif"/>
#error('post_gif')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<br>
<hr>
</div>
function store in controller -->
public function store(Request $request, Community $community)
{
$user = Auth::user();
$creds = $request->validate([
'post_image' => '|image|mimes:jpeg,jpg,png,svg|max:18048',
'post_video' => 'mimes:mp4,ogx,oga,ogv,ogg,webm|max:180048',
'post_gif' => '|image|mimes:gif|max:18048',
'title' => ['required'],
'post_text' => ['required'],
'post_url' => ['required']
]);
//IMAGE JPG,PNG,SVG
if ($image = $request->file('post_image')) {
$destinationPath = 'media/uploads';
$profileImage = date('YmdHis') . "." . $image->getClientOriginalExtension();
$image->move($destinationPath, $profileImage);
$input['post_image'] = "$profileImage";
}
//END IMAGE JPG,PNG,SVG
//VIDEO MP4
if ($image = $request->file('post_video')) {
$destinationPath = 'media/uploads';
$profileImage = date('YmdHis') . "." . $image->getClientOriginalExtension();
$image->move($destinationPath, $profileImage);
$inputmp4 ['post_video'] = "$profileImage";
}
//END VIDEOS
// GIF IMAGES
if ($image = $request->file('post_gif')) {
$destinationPath = 'media/uploads';
$profileImage = date('YmdHis') . "." . $image->getClientOriginalExtension();
$image->move($destinationPath, $profileImage);
$inputgif ['post_gif'] = "$profileImage";
}
//END GIF IMAGES
$post = $community->posts()->create
(['user_id' => auth()->id(),
'title' => $creds['title'],
'post_text' => $creds['post_text'],
'post_url' => $creds['post_url'],
'post_image' => $input['post_image'] ?? '',
'post_video' => $inputmp4['post_video'] ?? '',
'post_gif' => $inputgif['post_gif'] ?? '',
]);
return redirect()->route('communities.show', $community);
}
Is it possible post_video and post_gif are empty? Php has a max_upload and max post size limit that is defined on the ini file. It is possible that that size is being exceeded. Hence your files are not actually uploading.
Also, your if statements are kinda confusing. Check this out :
//This if statement will always return true. Since you're assigning $image variable to $request->file('post_video').
if ($image = $request->file('post_video')) {
//Code For saving file
//Don't use this
}
// Instead you should use hasFile to check if the file is uploaded. here's how
if ($request->hasFile('post_video')) {
$video = $request->file('post_video');
//Code For saving file
//Use This instead
}
Also, at the last line, where you call create() method, do this:
$post = $community->posts()->create
(['user_id' => auth()->id(),
'title' => $creds['title'],
'post_text' => $creds['post_text'],
'post_url' => $creds['post_url'],
'post_image' => $input['post_image'], // skip the "?? ''" part
'post_video' => $inputmp4['post_video'],
'post_gif' => $inputgif['post_gif'],
]);
Now, if either post_image, post_video or post_gif is empty, you'll get a error and can see if the data is wrong.
Also, on a kinda related note, did you know laravel has a good helper to save files in storage? Check it out
Hello guys I just want to ask in my project there are three tables product, color and product_color.I insert database using insert_batch then it work fine, when i update product_color table using update_batch then face some problems.Here's my sample code:
Database:
product:id,name,sku...
color:id,color_name
product_color:id,pro_id,color_id
Input Form:
<?php foreach($colors as $color): ?>
<input type="checkbox" class="form-check-input" name="color[]" value="<?php echo $color->color_id; ?>" <?php foreach ($productcolor as $key => $value){ $array[] = $value->color_id;} if(in_array($color->color_id,$array)) echo 'checked'; else ''; ?>>
<label class="form-check-label">
<?php echo $color->color_name; ?>
</label>
<?php endforeach; ?>
Actually i want to pass primary id from product_color table.Here i pass color_id.Have any way to pass primary id from input form;
Here Is my Controller:
$colorBatch = array();
foreach ($color as $colorvalue) {
$colorBatch[] = array(
'id'=>$id
'pro_id' =>$pid,
'color_id' => $colorvalue
);
}
$this->db->update_batch('product_color', $colorBatch,'pro_id');
Where $pid contains product_id;
Is it possible to pass product_color table primary id from input form or Have any better solution to solve this.Sorry for bad english.
Thanks
Please check below code as your array structure is wrong;
$colorBatch = array();
foreach ($color as $key => $colorvalue) {
$colorBatch[$key] = array(
'id'=>$id
'pro_id' =>$pid,
'color_id' => $colorvalue
);
}
$this->db->update_batch('product_color', $colorBatch,'pro_id');
I have a two array that I'm going to include them into a checkbox,
echo Html::checkboxList('item', $selectedItem, $dataItem, [
'item' => function($index, $label, $name, $checked, $value) {
return "<label class='col-md-2'>
<input type='checkbox' {$checked} name='{$name}' value='{$value}'>
<span>{$label}</span>
</label>";
}
]);
I see in code in browser like this :
<label class="col-md-2">
<input 1="" name="item[]" value="1" disabled="" type="checkbox">
<span>Login</span>
</label>
The checked render into 1="" .
Please advise.
UPDATE
$dataItem
E:\wamp64\www\yii_tresnamuda\modules\it\views\request\preview.php:128:
array (size=6)
1 => string 'Login' (length=5)
2 => string 'Printer' (length=7)
3 => string 'Monitor' (length=7)
4 => string 'Computer' (length=8)
5 => string 'Network' (length=7)
6 => string 'Lain Lain' (length=9)
$selectedItem
E:\wamp64\www\yii_tresnamuda\modules\it\views\request\preview.php:129:
array (size=2)
2 => int 2
1 => int 1
The problem is in your {$checked} element of your item template. Try this:
echo Html::checkboxList('item', $selectedItem, $dataItem, [
'item' => function($index, $label, $name, $checked, $value) {
return "<label class='col-md-2'>
<input type='checkbox' name='{$name}' value='{$value}' ".($checked ? 'checked' : '').">
<span>{$label}</span>
</label>";
}
]);
Also, I think you have to change $selectedItem specification form [2=>2, 1=>1] to just [2,1]
I dont understand how to exactly insert a row into a MySQL table. If I use my code, I add a new row for every post. Rather than that, I want only one row with all the values.
Here is the code sample.
HTML:
echo form_open('account/update');
echo "<p><label for='gender'>Gender</label>
<input type='text' name='gender' id='gender' value='".$gender."' />
</p>
<p>
<label for='age'>Age</label>
<input type='text' name='age' id='age' value='".$age."' />
</p>
<p>
<label for='bio'>Biografie</label>
<input type='text' name='bio' id='bio' value='".$bio."' />
</p>
<p>
<label for='skills'>Skills</label>
<input type='text' name='skills' id='skills' value='".$skills."' />
</p>
<p><input type='submit' value='Save' /></p>";
echo form_close();
Controller:
function update()
{
$userid = $this->session->userdata("userid");
$datanew = array(
'userid' => $this->session->userdata("userid"),
'gender' => $this->input->post('gender'),
'age' => $this->input->post('age'),
'bio' => $this->input->post('bio') ,
'skills' => $this->input->post('skills')
);
$this->session->set_userdata($data);
$this->load->model('model_account');
$this->load->model("model_user");
$this->model_account->profile_insert($datanew);
$this->load->view("change_avatar");
redirect("account/show/".$this->session->userdata("userid"));
}
Model:
function profile_insert($datanew)
{
$this->db->insert('profile', $datanew);
}
I get 5 rows if I submit the HTML form.
This works for me:
I Set the userid to unique and made a if statement in the controller ti switch between a insert and update function.
Controller:
function update()
{
$datanew = array(
'userid' => $this->session->userdata("userid"),
'gender' => $this->input->post('gender'),
'age' => $this->input->post('age'),
'bio' => $this->input->post('bio') ,
'skills' => $this->input->post('skills')
);
$exists = $this->db->select('profile')->where('userid', $this->session->userdata("userid"));
if($exists)
{
$this->session->set_userdata($datanew);
$this->load->model('model_account');
$this->load->model("model_user");
$this->model_account->profile_update($datanew);
$this->load->view("change_avatar");
redirect("account/show/".$this->session->userdata("userid"));
}
else
{
$this->session->set_userdata($datanew);
$this->load->model('model_account');
$this->load->model("model_user");
$this->model_account->profile_insert($datanew);
$this->load->view("change_avatar");
redirect("account/show/".$this->session->userdata("userid"));
}
}
model:
function profile_insert($datanew)
{
$this->db->insert('profile', $datanew);
}
function profile_update($datanew)
{
$this->db->update('profile', $datanew);
}
Thanks for helping me
I've made an email script that should update as soon as wp_mail has result. For some reason my value won't update. Have I missed something? I am receiving the mail so the wp_mail works.
Cheers!
$email_result = wp_mail( $to, $subject, $message, $headers );
if( $email_result ){//wp_mail() processed the request successfully
global $wpdb;
$table_name = $wpdb->prefix . "wpsc_coupon_codes";
$coupon_id = $ereminder->ID;
$ereminders = $wpdb->query( $wpdb->prepare("
UPDATE *
FROM $table_name
SET reminder = 1
WHERE ID = $coupon_id
") );
}
Try This:
$wpdb->update( $table_name, array( 'reminder' => 1),array('ID'=>$coupon_id));
try this
UPDATE $table_name
SET reminer = 1
WHERE ID = $coupon_id
We could use $wpdb->update, like this:
global $wpdb;
$table_name = $wpdb->prefix.'your_table_name';
$data_update = array('row_name_1' => $row_data_1 ,'row_name_2' => $row_data_2);
$data_where = array('row_name' => $row_data);
$wpdb->update($table_name , $data_update, $data_where);
You may change instead of (UPDATE * FROM)
$ereminders = $wpdb->query($wpdb->prepare("UPDATE $table_name SET reminer='1' WHERE ID=$coupon_id"));
and use no break.
Thank you.
Example of mine that is working:
$result = $wpdb->update(
$wpdb->prefix .'sae_calendar',
array(
'year' => $year,
'quarter' => $quarter,
'start_date' => $start_date,
'end_date' => $end_date,
'reservation_start_date' => $reservation_start_date,
'reservation_end_date' => $reservation_end_date
),
array(
"id" => $id
)
);
<?php
global $wpdb;
if(isset($_POST['progress'])){
$table=t_test;
$data=array('client_development'=>$_POST['Progress']);
$where=array('p_id'=>$_SESSION['id']);
$format=("%d");
$whereFormat=("%d");
$result4=$wpdb->UPDATE($table,$data,$where,$format,$whereFormat);
}
?>
<form method="post">
<input type="text" name="Progress">
<input type="submit" name="progress" value="Prog%">
</form>
<?php
if(isset($_POST['progress'])){
$table=t_test;
$data=array('client_development'=>$_POST['Progress']);
$where=array('p_id'=>$_SESSION['id']);
$format=("%d");
$whereFormat=("%d");
$result4=$wpdb->UPDATE($table,$data,$where,$format,$whereFormat);
}
?>
<form method="post">
<input type="text" name="Progress">
<input type="submit" name="progress" value="Prog%">
</form>