Apologies if there is another feed with this same problem, I have tried different suggested solutions but I still get an error, and I cant see why!
I want to update a row in my table using a html form. I have populated the form with the existing values, and want to be able to edit those and update them when the form is submitted, but I am getting this error:
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined'
in
/Applications/XAMPP/xamppfiles/htdocs/love-deals/admin/update_offer.php:46
Stack trace: #0
/Applications/XAMPP/xamppfiles/htdocs/love-deals/admin/update_offer.php(46):
PDOStatement->execute(Array) #1 {main} thrown in
/Applications/XAMPP/xamppfiles/htdocs/love-deals/admin/update_offer.php
on line 46
Here is the php / sql code:
if(isset($_POST['update'])) {
$updateTitle = trim($_POST['title']);
$updateDesc = trim($_POST['desc']);
$updateRedeem = trim($_POST['redeem']);
$updateStart = trim($_POST['start']);
$updateExpiry = trim($_POST['expiry']);
$updateCode = trim($_POST['code']);
$updateTerms = trim($_POST['terms']);
$updateImage = trim($_POST['image']);
$updateUrl = trim($_POST['url']);
$updateSql = 'UPDATE codes SET (title,description,redemption,start,expiry,textcode,terms,image,url) = (:title,:description,:redeem,:start,:exp,:code,:terms,:image,:url) WHERE id=:offerid';
$update = $db->prepare($updateSql);
$update->execute(array(':title'=>$updateTitle,':description'=>$updateDesc,':redeem'=>$updateRedeem,':start'=>$updateStart,':exp'=>$updateExpiry,':code'=>$updateCode,':terms'=>$updateTerms,':image'=>$updateImage,':url'=>$updateUrl,':id'=>$offerID));
}
and the html form:
<form id="update_offer" class="col-md-6 col-md-offset-3" method="post" action="update_offer.php?id=<?php echo $offerID; ?>">
<div class="form-group col-md-12">
<label class="col-md-12" for="title">Title</label>
<input id="title" class="form-control col-md-12" type="text" name="title" placeholder="Offer Title" value="<?php echo $title; ?>" required>
</div>
<div class="form-group col-md-12">
<label class="col-md-12" for="desc">Description</label>
<textarea id="desc" class="form-control col-md-12" name="desc" placeholder="Description" value="<?php echo $desc; ?>"></textarea>
</div>
<div class="form-group col-md-12">
<label class="col-md-12" for="redeem">Redemption</label>
<input id="redeem" class="form-control col-md-12" type="text" name="redeem" placeholder="Where to redeem" value="<?php echo $redeem; ?>" required>
</div>
<div class="form-group col-md-12">
<label class="col-md-12" for="start">Start Date</label>
<input id="start" class="form-control col-md-12" type="date" name="start" value="<?php echo $startDate->format('Y-m-d'); ?>" min="<?php echo date('Y-m-d') ?>" max="2021-12-31" required>
</div>
<div class="form-group col-md-12">
<label class="col-md-12" for="expiry">Expiry Date</label>
<input id="expiry" class="form-control col-md-12" type="date" name="expiry" value="<?php echo $expDate->format('Y-m-d'); ?>" min="<?php echo date('Y-m-d') ?>" max="2021-12-31" required>
</div>
<div class="form-group col-md-12">
<label class="col-md-12" for="code">Code</label>
<input id="code" class="form-control col-md-12" type="text" name="code" placeholder="Code (if applicable)" value="<?php echo $code; ?>">
</div>
<div class="form-group col-md-12">
<label class="col-md-12" for="terms">Terms</label>
<textarea id="terms" class="form-control col-md-12" name="terms" placeholder="Terms & Conditions" value="<?php echo $terms; ?>" required></textarea>
</div>
<div class="form-group col-md-12">
<label class="col-md-12" for="url">Offer URL</label>
<input id="url" class="form-control col-md-12" type="text" name="url" placeholder="Offer URL (if applicable)" value="<?php echo $url; ?>">
</div>
<div class="form-group col-md-12">
<label class="col-md-8" for="image">Image <img src="../images/offers/<?php echo $image; ?>" alt="" style="width: 200px;" /></label>
<input id="image" class="form-control col-md-4" type="file" name="image">
</div>
<div class="form-group col-md-12 pull-right">
<button id="update" type="submit" name="update" class="btn btn-primary"><i class="glyphicon glyphicon-refresh"></i> Update</button>
</div>
</form>
what am i doing wrong?! Im still learning php etc, so please be gentle, any help is much appreciated.
First, you have wrong syntax for update statement, as other guys mentioned already, change:
UPDATE codes SET (title,description,redemption,start,expiry,textcode,terms,image,url) = (:title,:description,:redeem,:start,:exp,:code,:terms,:image,:url) WHERE id=:offerid
Into
UPDATE `codes`
SET `title` = :title,
`description` = :description,
`redemption` = :redeem,
`start` = :start
`expiry` = :expiry
`textcode` = :code
`terms` = :terms
`image` = :image
`url` = :url
WHERE `id` = :offerid
Learn more about the SQL Update syntax here.
Then, one thing more you have a mistake in execute(). Change your :id into :offerid like below:
$update->execute(array(
':title' => $updateTitle,
':description' => $updateDesc,
':redeem' => $updateRedeem,
':start' => $updateStart,
':exp' => $updateExpiry,
':code' => $updateCode,
':terms' => $updateTerms,
':image' => $updateImage,
':url' => $updateUrl,
':offerid' => $offerID
));
You are using wrong syntax of Update
It would be
$updateSql = "UPDATE codes SET title =:title,
description =:description,
redemption =:redeem,
start =:start,
expiry =:exp,
textcode =:code,
terms :=terms,image =:image,
url =:url
WHERE id=:id";// write id instead of offset because you are binding ':id'=>$offerID
Check http://dev.mysql.com/doc/refman/5.7/en/update.html
thanks for your replies. My original update syntax was actually as you mentioned, I had changed it when looking through some other solutions, and not changed it back, but either way, even with correct syntax, I still got the same error.
Looking through your replies, I can see that I have ':id'=> $offerID but have used :offerid in the sql code, which obviously needs to be updated, so thanks for pointing that out! Hopefully that will fix the problem...
Related
So, I cannot find the solution to the problem I'm having. I'm really new to coding but learned how to start coding using basic HTML, PHP, PDO, and AJAX. So my problem comes from a form that retrieves dates from a calendar using the type=date from the form. The code of the form is down below.
<div class="col-lg-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title text-center"><i class="fa fa-bar-chart fa-fw"></i> Ingreso de reporte</h3>
</div>
<div id="alert_success" class="panel-body">
<br>
<form method="post" class="form-horizontal" role="form" action="ajax_form_post.php" id="insertreport">
<div class="form-group">
<label class="control-label col-sm-2" for="video" style="color:#777;">ID de video</label>
<div class="col-sm-10">
<input type="text" name="video" class="form-control" id="video" placeholder="Ingresa id del video" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="date_i" style="color:#777;">Fecha de arriendo</label>
<div class="col-sm-10">
<input type="date" name="date_i" class="form-control" id="date_i" placeholder="" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="date_f" style="color:#777;">Fecha de devoluciĆ³n</label>
<div class="col-sm-10">
<input type="date" name="date_f" class="form-control" id="date_f" placeholder="" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<input type="hidden" name="c_id" class="form-control" id="user_id" value="<?php echo $id ?>" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="submit" class="btn btn-primary" name="update_customer" value="Enviar" id="submitdata">
</div>
</div>
</form>
<div class="text-right">
<i class="fa fa-arrow-circle-right"></i>
</div>
</div>
</div>
</div>
Now the problem starts with this Ajax form I built. BTW the script is working fine, the problem is inside this set of code.
<?php
/****************Get customer info to ajax *******************/
//require database class files
require("includes/pdocon.php");
//instatiating our database objects
$db = new Pdocon ;
if(isset($_POST['c_id'])){
$id = $_POST['c_id'];
$date_i = date("Y-m-d", strtotime($_POST['date_i']));
$date_f = date("Y-m-d", strtotime($_POST['date_f']));
$raw_v_id = clean_data($_POST['video']);
$v_id = val_int($raw_v_id);
$db->query('SELECT * FROM videos WHERE v_id = :v_id');
$db->bindvalue(':v_id', $v_id, PDO::PARAM_INT);
$row = $db->fetchSingle();
$db->query('INSERT INTO arriendo (transaccion, c_id, v_id, f_arriendo, f_devolucion)
VALUES (NULL, :c_id, :v_id :f_arriendo, :f_devolucion)');
$db->bindvalue(':f_arriendo', $date_i, PDO::PARAM_STR);
$db->bindvalue(':f_devolucion', $date_f, PDO::PARAM_STR);
$db->bindvalue(':c_id', $id, PDO::PARAM_INT);
$db->bindvalue(':v_id', $v_id, PDO::PARAM_INT);
$run = $db->execute();
}
if($run){
echo "<p class='bg-success text-center' style='font-weight:bold;'>Valor actualizado </p>";
}
?>
I get the following error:
Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''2021-08-05', '2021-08-06')' at line 2
Any help or a little guidance would be greatly appreciated. Thanks in advance.
I have data that already exists in the database server and I want to change it based on the id table. I want to update one time so that the 3 data tables are updated as well because the table id is in another table too. I tried it but I can't. Please help me
I have joined from several tables.
I've also searched on :link!
:link!
This is my Controller
public function updateservicenew(){
$id= $this->uri->segment(3);
$data['vendor']= $this->model_vendor->show_data_all();
$data['vendor2']= $this->model_vendor->show_data_vendor2();
$data['service']= $this->Madmin2->getservicenew($id)->row_array();
$this->template->viewadmin2('admin2/transaks/updateservicenew',$data);
}
public function saveservicenew(){
$this->Madmin2->saveservicenew($this->input->post());
redirect(base_url('admin2/transaksidone'));
}
This is my Model
public function getservicenew($id){ $this->db->select('kontak_sis.*,vendor.*,vendor2.*,service_sis.*,sumber_info.*,provinsi.*,kota.*,mst_service.*,service.*');
$this->db->from('service_sis');
$this->db->join('vendor', 'service_sis.id_vendor=vendor.id_vendor', 'left');
$this->db->join('vendor2', 'service_sis.id_vendor2=vendor2.id_vendor2', 'left');
$this->db->join('mst_service', 'service_sis.id_mst_service=mst_service.id_mst_service', 'left');
$this->db->join('kontak_sis', 'service_sis.id_kontak=kontak_sis.id_kontak', 'left');
$this->db->join('sumber_info', 'service_sis.id_sumber=sumber_info.id_sumber', 'left');
$this->db->join('provinsi', 'service_sis.id_provinsi=provinsi.id_provinsi', 'left');
$this->db->join('kota', 'service_sis.id_kota=kota.id_kota', 'left');
$this->db->join('service', 'service_sis.id_service=service.id_service', 'left');
$param = array('service_sis.id_service'=>$id);
return $this->db->get_where('',$param);
}
public function simpanservicenew(){
$data_pelanggan['cid']= $this->input->post('cid');
$data_pelanggan['nama_perusahaan']= $this->input->post('nama_perusahaan');
$data_pelanggan['destination']= $this->input->post('destination');
$data_pelanggan['alamat_perusahaan']= $this->input->post('alamat_perusahaan');
$data_pelanggan['pic_perusahaan']= $this->input->post('pic_perusahaan');
$data_pelanggan['telepon_pic']= $this->input->post('telepon_pic');
$data_pelanggan['fax']= $this->input->post('fax');
$data_pelanggan['hp']= $this->input->post('hp');
$data_pelanggan['email_pic']= $this->input->post('email_pic');
$this->db->where('id_kontak',$this->input->post('id_kontak'));
$this->db->update('kontak_sis',$data_pelanggan);
$data_vendor['pic_vendor']= $this->input->post('pic_vendor');
$data_vendor['media_vendor']= $this->input->post('media_vendor');
$data_vendor['kapasitas_vendor']= $this->input->post('kapasitas_vendor');
$data_vendor['telepon_vendor']= $this->input->post('telepon_vendor');
$data_vendor['email_vendor']= $this->input->post('email_vendor');
$this->db->where('id_vendor',$this->input->post('id_vendor'));
$this->db->update('vendor',$data_vendor);
$data_vendor2['pic_vendor2']= $this->input->post('pic_vendor2');
$data_vendor2['media_vendor2']= $this->input->post('media_vendor2');
$data_vendor2['kapasitas_vendor2']= $this->input->post('kapasitas_vendor2');
$data_vendor2['telepon_vendor2']= $this->input->post('telepon_vendor2');
$data_vendor2['email_vendor2']= $this->input->post('email_vendor2');
$this->db->where('id_vendor2',$this->input->post('id_vendor2'));
$this->db->update('vendor2',$data_vendor2);
This is my View
<div class="row">
<div class="box box-primary">
<div class="box-header with-border">
<div id='progress'><div id='progress-complete'></div></div>
<h2 class="box-title"><b>Set Ewo</b></h2>
</div>
<div class="box-body">
<form method="post" action="<?php echo base_url('admin2/simpanservicebaru/'.$this->uri->segment(3)); ?>" enctype="multipart/form-data" id="myForm">
<input type="hidden" name="id_service" value="<?php echo $service['id_service']; ?>">
<input type="hidden" name="id_kontak" value="<?php echo $service['id_kontak']; ?>">
<input type="hidden" name="id_mst_service" value="<?php echo $service['id_mst_service']; ?>">
<input type="hidden" name="id_vendor" value="<?php echo $service['id_vendor']; ?>">
<input type="hidden" name="id_vendor2" value="<?php echo $service['id_vendor2']; ?>">
<fieldset>
<div class="form-group">
<label for="">Registration Form ID</label>
<input type="text" name="cid" class="form-control" placeholder="" value="<?php echo $service['cid'] ?>" readonly>
</div>
<div class="form-group">
<label for="">Customer</label>
<b><input type="text" name="nama_perusahaan" class="form-control" value="<?php echo $service['nama_perusahaan']; ?>"required></b>
</div>
<div class="form-group">
<label for="">Destination</label>
<b><input type="text" name="destination" class="form-control" placeholder="destination"
value="<?php echo $service['destination']; ?>"required></b>
</div>
<div class="form-group">
<label for="">Address</label>
<b><input type="text" name="alamat_perusahaan" class="form-control" placeholder="alamat"
value="<?php echo $service['alamat_perusahaan']; ?>"required></b>
</div>
<div class="form-group">
<label for="">PIC(Engineering)</label>
<input type="text" name="pic_perusahaan" class="form-control" placeholder="pic"
value="<?php echo $service['pic_perusahaan']; ?>">
</div>
<div class="form-group">
<label for="">Phone Number</label>
<input type="text" name="telepon_pic" class="form-control" placeholder="phone number"
value="<?php echo $service['telepon_pic']; ?>">
</div>
<div class="form-group">
<label for="">Fax</label>
<input type="text" name="fax" class="form-control" placeholder="fax"
value="<?php echo $service['fax']; ?>">
</div>
<div class="form-group">
<label for="">HP</label>
<input type="text" name="hp" class="form-control" placeholder="hp"
value="<?php echo $service['hp']; ?>">
</div>
<div class="form-group">
<label for="">Email</label>
<input type="text" name="email_pic" class="form-control" placeholder="email pic"
value="<?php echo $service['email_pic']; ?>">
</div>
</fieldset>
<fieldset>
<div class="form-group">
<label for="">Vendor1</label>
<select name="id_vendor" class="form-control">
<option value="0">Non Vendor</option>
<?php
foreach ($vendor as $c)
{ ?>
<?php $sel = ($c->id_vendor==$service['id_vendor']) ? 'selected' :''; ?>
<option value="<?php echo $c->id_vendor;?>" <?php echo $sel;?>><?php echo $c->nama_vendor;?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label for="">PIC</label>
<input type="text" name="pic_vendor" class="form-control" placeholder="pic vendor"
value="<?php echo $service['pic_vendor']; ?>">
</div>
<div class="form-group">
<label for="">Media</label>
<input type="text" name="media_vendor" class="form-control" placeholder="media"
value="<?php echo $service['media_vendor']; ?>">
</div>
<div class="form-group">
<label for="">Capacity</label>
<input type="text" name="kapasitas_vendor" class="form-control" placeholder="kapasitas vendor"
value="<?php echo $service['kapasitas_vendor']; ?>">
</div>
<div class="form-group">
<label for="">Phone</label>
<input type="text" name="telepon_vendor" class="form-control" placeholder="telepon vendor"
value="<?php echo $service['telepon_vendor']; ?>">
</div>
<div class="form-group">
<label for="">Email</label>
<input type="text" name="email_vendor" class="form-control" placeholder="email vendor"
value="<?php echo $service['email_vendor']; ?>">
</div>
<hr></hr>
<div class="form-group">
<label for="">Vendor2</label>
<select name="id_vendor2" class="form-control">
<option value="0">Non Vendor</option>
<?php
foreach ($vendor2 as $c)
{ ?>
<?php $sel = ($c->id_vendor2==$service['id_vendor2']) ? 'selected' :''; ?>
<option value="<?php echo $c->id_vendor2;?>" <?php echo $sel;?>><?php echo $c->nama_vendor2;?></option>
<?php } ?>
</select>
</div>
<div class="form-group">
<label for="">PIC</label>
<input type="text" name="pic_vendor2" class="form-control" placeholder="pic vendor"
value="<?php echo $service['pic_vendor2']; ?>">
</div>
<div class="form-group">
<label for="">Media</label>
<input type="text" name="media_vendor2" class="form-control" placeholder="media"
value="<?php echo $service['media_vendor2']; ?>">
</div>
<div class="form-group">
<label for="">Capacity</label>
<input type="text" name="kapasitas_vendor2" class="form-control" placeholder="kapasitas vendor"
value="<?php echo $service['kapasitas_vendor2']; ?>">
</div>
<div class="form-group">
<label for="">Phone</label>
<input type="text" name="telepon_vendor2" class="form-control" placeholder="telepon vendor"
value="<?php echo $service['telepon_vendor2']; ?>">
</div>
<div class="form-group">
<label for="">Email</label>
<input type="text" name="email_vendor2" class="form-control" placeholder="email vendor"
value="<?php echo $service['email_vendor2']; ?>">
</div>
</fieldset>
<fieldset>
<br>
<p>*Pastikan semua form sudah terisi dengan benar</p>
<button id="submit" class="btn btn-success">Update Service</button>
</fieldset>
</div>
</div>
</div>
</div>
<script>
$( function() {
var $signupForm = $( '#myForm' );
$signupForm.validate({errorElement: 'em'});
$signupForm.formToWizard({
submitButton: 'submit',
nextBtnName: 'Selanjutnya',
prevBtnName: 'Sebelumnya',
nextBtnClass: 'btn btn-primary btn-flat next',
prevBtnClass: 'btn btn-default btn-flat prev',
buttonTag: 'button',
validateBeforeNext: function(form, step) {
var stepIsValid = true;
var validator = form.validate();
$(':input', step).each( function(index) {
var xy = validator.element(this);
stepIsValid = stepIsValid && (typeof xy == 'undefined' || xy);
});
return stepIsValid;
},
progress: function (i, count) {
$('#progress-complete').width(''+(i/count*100)+'%');
}
});
});
</script>
Tables:
This is my **Table contact**
# Name type
1 id_kontak int(11)
2 cid varchar(10)
3 nama_perusahaan varchar(150)
4 destination varchar(30)
5 alamat_perusahaan varchar(200)
6 pic_perusahaan varchar(200)
7 telepon_pic varchar(30)
8 fax int(15)
9 hp int(15)
10 email_pic (15)
This my **table vendor**
# Name type
1 id_vendor int(11)
2 pic_vendor varchar(200)
3 telepon_vendor varchar(100)
4 media_vendor varchar(200)
5 kapasitas_vendor varchar(200)
6 email_vendor varchar(200)
This my **table vendor2**
# Name type
1 id_vendor2 int(11)
2 pic_vendor2 varchar(200)
3 telepon_vendor2 varchar(100)
4 media_vendor2 varchar(200)
5 kapasitas_vendor2 varchar(200)
6 email_vendor2 varchar(200)
I want to update one time so that the 3 data tables are updated as well because the table id is in another table too.Thank you for the help
What i understand from your code is that you want to update 3 tables using single query. In that case you can use following code.
$this->db->set('a.cid', $this->input->post('cid'));
$this->db->set('a.nama_perusahaan', $this->input->post('nama_perusahaan'));
$this->db->set('b.pic_vendor', $this->input->post('pic_vendor'));
$this->db->set('b.media_vendor', $this->input->post('media_vendor'));
$this->db->set('c.pic_vendor2', $this->input->post('pic_vendor2'));
$this->db->set('c.companyaddress', $this->input->post('pic_vendor2'));
$this->db->where('a.id', 1);
$this->db->where('a.id = b.id');
$this->db->where('a.id = c.id');
$this->db->update('table as a, table2 as b',table3 as c);
But in na More Professional way you should use Codeigniter Transactions. If any of the query fails the other one gets rolled back.
$this->db->trans_start();
$this->db->query('AN SQL QUERY...');
$this->db->query('ANOTHER QUERY...');
$this->db->query('AND YET ANOTHER QUERY...');
$this->db->trans_complete();
I have an update form that has three inputs. Now, I want to retrieve values from database in the inputs and update them after I click update and it works fine. But, the problem is that I must refresh after pressing the update button to see the changes (the automatic refresh and manual refresh). I need the value to change instantly after pressing the update button. How to do this? This is my code:
<?php
require_once 'core/init.php';
$result = $db->query("SELECT * FROM customers WHERE id = '$customer_id'");
while($res = mysqli_fetch_assoc($result)) {
$first_name = $res['first_name'];
$last_name = $res['last_name'];
$mobile_number = $res['mobile_number'];
}
if(isset($_POST['submit_0'])) {
$first_Name = ((isset($_POST['First_Name']))?sanitize($_POST['First_Name']):'');
$last_Name = ((isset($_POST['Last_Name']))?sanitize($_POST['Last_Name']):'');
$db->query("UPDATE customers SET first_name = '{$first_Name}', last_Name = '{$last_Name}' WHERE id = '{$customer_id}'");
}
?>
<form action="personal_details.php" method="post" id="personal_details">
<div class="row">
<div class="form-group col-lg-12">
<label for="First_Name" style="font-weight: bold; cursor:text;"><span style="color:red;">* </span>First Name</label>
<input type="text" name="First_Name" id="First_Name" class="form-control form-control-lg"
value="<?=$first_name;?>" style="width:770px; background-color:#EEEEEE;">
</div>
</div>
<div class="row">
<div class="form-group col-lg-12">
<label for="Last_Name" style="font-weight: bold; cursor:text;"><span style="color:red;">* </span>Last Name</label>
<input type="text" name="Last_Name" id="Last_Name" class="form-control form-control-lg"
value="<?=$last_name;?>" style="width:770px; background-color:#EEEEEE;">
</div>
</div>
<div class="row">
<div class="form-group col-lg-7">
<label for="mobile_number" style="font-weight: bold;"><span style="color:red;">* </span>Mobile Phone Number</label>
<input type="tel" name="mobile_number" id="monu" class="form-control form-control-lg"
value="<?=$mobile_number;?>" style="background-color:#EEEEEE; cursor:default;" readonly>
</div>
</div>
I want only 4 columns from database in below
I have to get only 4 column from database for displaying in textfield please give suggestion for that. The table is shown below thank you
$sql_getnm = "SELECT * FROM util WHERE util_head IN ('wc_email', 'wc_contact_us', 'wc_mobile', 'wc_google_map');";
$result_getnm = $connect->query($sql_getnm);
while($row_getnm = $result_getnm->fetch_array())
$util_value_email_data=?
$util_value_mobile_data=?;
$util_value_map_data=?;
$util_value_data=?;
html form
<form id="submitForm" method="post" role="form" name="hl_form" method="post" enctype="multipart/form-data">
<div class="box-body">
<div class="form-group">
<label for="mobile_number">Email*</label>
<input class="form-control" id="util_value_email" name="util_value_email" value="<?Php echo $util_value_email_data; ?>" maxlength="250" placeholder="Enter Email Address" type="text">
</div>
<div class="form-group">
<label for="mobile_number">Mobile*</label>
<input class="form-control" id="util_value_mobile" name="util_value_mobile" value="<?Php echo $util_value_mobile_data; ?>" maxlength="250" placeholder="Enter Mobile Number" type="text">
</div>
<div class="form-group">
<label for="mobile_number">Map*</label>
<input class="form-control" id="util_value_map" name="util_value_map" value="<?Php echo $util_value_map_data; ?>" maxlength="250" placeholder="Enter Map Address" type="text">
</div>
<div class="form-group">
<label for="description" class="required">Description*</label>
<textarea class="form-control" style="resize: none;" id="util_value" name="util_value" rows="3" placeholder="Enter Description"><?Php echo $util_value_data; ?></textarea>
</div>
<div class="box-footer">
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</div>
</form>
Below is the code from which you can get all the four data that you want.
$sql_getnm = "SELECT * FROM util WHERE util_head IN ('wc_email', 'wc_contact_us', 'wc_mobile', 'wc_google_map');";
$result_getnm = $connect->query($sql_getnm);
while($row_getnm = $result_getnm->fetch_array()) {
if($row_getnm['util_head'] == 'wc_email'){
$util_value_email_data = $row_getnm['util_value'];
}
if($row_getnm['util_head'] == 'wc_contact_us'){
$util_value_contact_data = $row_getnm['util_value'];
}
if($row_getnm['util_head'] == 'wc_mobile'){
$util_value_mobile_data = $row_getnm['util_value'];
}
if($row_getnm['util_head'] == 'wc_google_map'){
$util_value_map_data = $row_getnm['util_value'];
}
}
You need to replace * with columns name with comma separation.
$sql_getnm = "SELECT Columname1,Columname2,Columname3,Columname4 FROM util WHERE util_head IN ('wc_email', 'wc_contact_us', 'wc_mobile', 'wc_google_map');";
$result_getnm = $connect->query($sql_getnm);
while($row = mysql_fetch_array($result_getnm, MYSQL_ASSOC)
$util_value_email_data= $row['Columname1'];
$util_value_mobile_data= $row['Columname2'];
$util_value_map_data= $row['Columname3'];
$util_value_data= $row['Columname4'];
I issue i am having is that, I created two forms, it is A PROFILE PAGE one is for uploading user image to the database, while the other is for updating user basic information, like name, email etc. The issue i am having is that only one of the form is working, the other form stops working. here is my code.
<?php if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "pic_form") &&(($_POST['check'])=== 1)) {
$id=$_POST['monitorimg'];
move_uploaded_file($_FILES['pic']['tmp_name'],"imageupload/".$id);
$updateSQL = sprintf("UPDATE administrator SET pix=%s WHERE adminid=%s",
GetSQLValueString($_POST['monitorimg'], "text"),
GetSQLValueString($_POST['ids'], "int"));
mysqli_select_db($myconn,$database_myconn);
$Result1 = mysqli_query($myconn,$updateSQL) or die(mysqli_connect_error());
}
?>
<div class="box box-primary">
<div class="box-body box-profile">
<img class="profile-user-img img-responsive img-circle" width="68" height="68" src="imageupload/<?php echo $row_rslinks['adminid']; ?>"."" alt="profile picture">
<form action="<?php echo $editFormAction; ?>" name="pic_form" enctype="multipart/form-data" method="POST">
<input type="file" name="pic" class="btn-facebook" required>
<input type="submit" class="btn-dropbox" name="sub" id="sub" value="Upload">
<input type="hidden" name="ids" id="ids" value="<?php echo $row_rslinks['adminid'];?>">
<input type="hidden" name="monitorimg" id="monitorimg" value="<?php echo $row_rslinks['adminid'];?>">
<input type="hidden" name="MM_update" value="pic_form">
<input type="hidden" name="check" id="check" value="1">
</form>
<h3 class="profile-username text-center"></h3>
<p class="text-muted text-center"></p>
<!-----------This is the second Table code-------------->
<?php if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1") &&(($_POST['check'])=== 1)) {
$updateSQL = sprintf("UPDATE administrator SET password=%s, adminname=%s, email_id=%s, contactno=%s WHERE adminid=%s",
GetSQLValueString($_POST['pwd'], "text"),
GetSQLValueString($_POST['inputName'], "text"),
GetSQLValueString($_POST['inputEmail'], "text"),
GetSQLValueString($_POST['num'], "text"),
GetSQLValueString($_POST['stuid'], "int"));
mysql_select_db($database_myconn, $myconn);
$Result1 = mysql_query($updateSQL, $myconn) or die(mysql_error());
}
?>
<div class="tab-content">
<div class="active tab-pane" id="settings">
<form action=<?php echo $editFormAction; ?>"" name=form11" method=POSTT" enctype="application/x-www-form-urlencoded" class="form-horizontal" id="form1">
<div class="form-group" id="stuid">
<label for="stuid" class="col-sm-2 control-label">User ID</label>
<div class="col-sm-10">
<input name="stuid" type="text" class="form-control" id="stuid"
value="<?php echo $row_rslinks['adminid']; ?>" readonly>
</div>
</div>
<div class="form-group" id="inputeName">
<label for="inputName" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="inputName" id="inputName"
value="<?php echo $row_rslinks['adminname']; ?>">
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-sm-2 control-label" >Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" name="inputEmail" id="inputEmail"
value="<?php echo $row_rslinks['email_id']; ?>">
</div>
</div>
<div class="form-group">
<label for="pwd" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="pwd" name="pwd" value="">
</div>
</div>
<div class="form-group">
<label for="rpwd" class="col-sm-2 control-label">Re-Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="rpwd" name="rpwd" value="">
</div>
</div>
<div class="form-group">
<label for="num" class="col-sm-2 control-label">Mobile</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="num" name="num" value="<?php echo $row_rslinks['contactno']; ?>">
</div>
</div><input type="hidden" name="check" id="check" value="2">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
Sorry guys for my long code....will appreciate your contribution. the second Table is not updating to my database..when the update button is pressed nothing happens. no error message is shown.
The problem and solution:
The main issue I see here is that your second form uses method="POSTT". Of course, there is no such method as POSTT so it will default to using the GET method instead. Remove the extra 'T' and it should fix the issue.
How to debug step by step:
I also recommend applying some common debugging techniques to trace through any future errors you may encounter.
Step 1: Check your PHP error logs and make sure they are reporting errors.
Step 2: Look at your resulting source code in the browser and run it through a validator such as https://validator.w3.org/
Step 3: If no errors were encountered above use lots of echo statements at various places throughout your program or at least in the problem areas. For example, if you had placed an echo statement such as:
echo "Second if block";
(I often go a bit overboard placing echo statements in my program just in case I am overlooking something. If this is the case, I'll usually just use number such as ...echo 7;...echo 8..., etc. before, after, and inside of each block of code)
inside of your second if block you would have noticed that it did not run. That would have clued you in to the fact that your if statement containing your $_POST variables evaluated to false. As you know it should have evaluated to true you know this is the source of your problem. You could then display the contents of your form variables as follows:
echo "<pre>";
echo "GET:";
print_r($_GET);
echo "POST:";
print_r($_POST);
echo "</pre>";
This would have shown you that the data is in your $_GET variable rather than your $_POST variable as you had expected.
Step 4: If your error is not detected in any of the previous steps, your last step is to verify that your SQL statement is correct. Try running it outside of PHP directly in your SQL environment and see if you get any errors. Also, set your PHP script to display SQL errors.
Before your site goes live make sure that any errors get sent only to the log file and not to the browser.