**I want to edit data in my table using modal but i can only call ID=1 i cant edit the others and also i need to refresh my web before i can see the changes?
// my update code
<?php
$id= "1";
$mysqli = new mysqli('127.0.0.1','root','','books');
$query = $mysqli->query("select * from bookrecords where ID='$id' ");
$row = $query->fetch_assoc();
if(isset($_POST['update'])) {
$id = $_POST['id'];
$nm = $_POST['nm'];
$is = $_POST['is'];
$pb = $_POST['pb'];
$au = $_POST['au'];
$result = $mysqli->query("UPDATE bookrecords set BookName='$nm', ISBN='$is', Publisher='$pb', Author='$au' where ID='$id'");
if($result){
?>
<div class="alert-success" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="close"><span aria-hidden="true">×</span></button>
<strong>Success!</strong> your data has been updated.
</div>
<?php
} else{
?>
<div class="alert-failed" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="close"><span aria-hidden="true">×</span></button>
<strong>Failed!</strong> Error updating. Try Again!
</div>
<?php
}
}
?>
** and this is my Modal form....
<div class="form-group">
<label for="id">ID:</label>
<input type="text" class="form-control" id="id" name="id" value="<?php echo $row['ID']?>" readonly>
</div>
<div class="form-group">
<label for="nm">BookName:</label>
<input type="text" class="form-control" id="nm" name="nm" value="<?php echo $row['BookName']?>">
</div>
<div class="form-group">
<label for="is">ISBN:</label>
<input type="text" class="form-control" id="is" name="is" value="<?php echo $row['ISBN']?>">
</div>
<div class="form-group">
<label for="pb">Publisher:</label>
<input type="text" class="form-control" id="pb" name="pb" value="<?php echo $row['Publisher']?>">
</div>
<div class="form-group">
<label for="au">Author:</label>
<input type="text" class="form-control" id="au" name="au" value="<?php echo $row['Author']?>">
</div>
<button type="submit" name="update" class="btn-primary">Update</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</form>
</div>
<div class="modal-footer">
</div>
</div>
**so how can i call any of my item/data in table? Please help me.
Your HTML form must have a hidden field with the id of book record, which will be send to the PHP script when pressing the "Update" button. The hidden field should look like this:
<input type="hidden" name="bookrecordId" value="ID_OF_BOOKRECORD_HERE" />
You can access the value of the transfered id with $_POST['bookrecordId'] in your receiving PHP script. Use it to build one or two prepared statements which will check if the row exists and then run an UPDATE query to update the values.
Related
I have a form A in index.php which I need to pass the value of 'notebook_id' to formB in create_new_note.php. I used POST method to do this but it is not working.
form A in index.php
<!-- Modal -->
<div class="modal" id="newNotebookModal" tabindex="-1" aria-labelledby="newNotebookModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<center><h5 class="modal-title" id="newNotebookModalLabel">Create a New Notebook</h5></center>
</div>
<div class="modal-body">
<form class="forms-sample" method="post">
<div class="form-group">
<label for="notebook_name_label">Notebook Name</label>
<input type="text" class="form-control" name="notebook_name" id="notebook_name" placeholder="Notebook Name">
</div>
</div>
<div class="modal-footer">
<button class="btn btn-outline-secondary btn-fw">Cancel</button>
<input type="submit" class="btn btn-primary" name="submit" value="Create"/>
</div>
</form>
</div>
</div>
</div>
</div>
Form B
<form class="forms-sample" method="post">
<div class="form-group">
<label for="note_title_label">Title</label>
<input type="hidden" name="notebook_id" value="<?php echo $notebook_id; ?>">
<input type="text" class="form-control" name="note_title" id="note_title" placeholder="Title">
</div>
<div class="form-group">
<textarea class="form-control" name ="note_content"id="note_content" rows="40"></textarea>
</div>
<button class="btn btn-outline-secondary btn-fw">Cancel</button>
<input type="submit" class="btn btn-primary" name="submit" value="Create"/>
</form>
I used MVC framework, hence this is my Controller code and Model code
// Controller
function addNotebook($std_id) {
$notebook = new ManageNotesModel();
$notebook->std_id = $std_id;
$notebook->notebook_name = $_POST['notebook_name'];
if($notebook->addNotebook() > 0) {
$message = "Your notebook has been created!";
echo "<script type='text/javascript'>alert('$message');
window.location = '../ManageNotesView/create_new_note.php'</script>";
}
}
// Model
function addNotebook(){
$sql = "insert into notebook(std_id, notebook_name)values(:std_id, :notebook_name)";
$args = [':std_id'=> $this->std_id, ':notebook_name'=>$this->notebook_name];
$stmt = DB::run($sql, $args);
$count = $stmt->rowCount();
return $count;
}
Please help me, I'm new to this I tried to make way through it, but cant seem to figure out whats wrong
As I see your code is creating a new row in the database. After saving row into database you want to know the last inserted id of the entity called Notebooks. Reuse that value and pass it into your template of creating titles. If your MVC framework does not know the last inserted id, you should customize it and add functionality to do that.
Check last_inserted_id
using for each loop I have to retrieve data however when adding new record data-repeater-create is taking default value as the last record of data even the element id is different.
<div data-repeater-list="car">
<?php foreach ($user_portfolio as $p_details) {
$p_title = $p_details['portfolio_title'];
$p_desc=$p_details['portfolio_desc'];
$p_expert = $p_details['portfolio_expert_id'];
$p_id = $p_details['portfolio_id'];
?>
<div data-repeater-item>
<div class="form row">
<div class="form-group mb-1 col-sm-12 col-md-12">
<label for="email-addr">Title</label>
<br>
<input type="text" name="port_id" value="<?php if(!empty($p_id)) {echo $p_id; } else { echo "";}?>">
<input type="text" class="form-control" id="portfolio_title<?php echo $p_id;?>" placeholder="Title " name="portfolio_title" value="<?php if(!empty($p_title)) {echo $p_title;} else {echo ""; }?>">
</div>```
below using data-repeater-create i am adding empty field however its taking last record as default value and I able to see in view source
``` <?php } //end of foreach?>
</div>
<div class="form-group overflow-hidden">
<div class="col-12">
<button data-repeater-create class="btn btn-theme" type="button">
<i class="ft-plus"></i> Add
</button>
<button type="submit" class="btn btn-theme">
<i class="la la-check-square-o"></i> Save
</button>
</div>
</div>
</form>```
This is the html code for the change password page. When I click change password from the user registration table, it bring me here and it works perfectly but when you use the option of the user change password which leads you directly to this place, saving it doesn't work. I believe it's got to deal with the User ID as key since from the table is selected via ID. But when i use setting - user change password, it doesn't do anything after saving password change, it doesn't reflect anything
<div class="col-lg-6">
<div class="col-sm-12">
<br/>
<h3 class="page-title">Change Password</h3>
</div>
<div class="card-box">
<div class="form-group">
<label for="userName">User Name</label>
<input type="text" name="uname" parsley-trigger="change" required placeholder="Enter user name" class="form-control" id="uname" name="uname" value="<?php echo $actordetails->ACT_USERNAME;?>" readonly >
</div>
<div class="form-group">
<label for="pass1">New Password<span style="color:#F00">*</span></label>
<input id="pass1" type="password" placeholder="Password" name="inputpassword" required class="form-control">
</div>
<div class="form-group">
<label for="passWord2">Confirm New Password <span style="color:#F00">*</span></label>
<input data-parsley-equalto="#pass1" type="password" required placeholder="Password" class="form-control" id="password2">
</div>
<div class="form-group text-right m-b-0">
<button class="btn btn-success waves-effect waves-light" type="submit" onclick="document.getElementById('viewpage').value='savepwd';document.getElementById('view').value='';document.getElementById('fdsearch').value='';document.myform.submit()">
Save
</button>
<button class="btn btn-default waves-effect waves-light m-l-5" onclick="document.getElementById('view').value='';document.getElementById('viewpage').value='';document.myform.submit()">
Cancel
</button>
</div>
</div>
</div>
</form >
and this is the controller code to process the information. The encryption uses username and password with salt for your information.. Any help would be appreciated
<?php
$crypt = new cryptCls();
switch(strtolower($viewpage)) {
case "changepwd":
print_r($_POST);
$stmt = $sql->Execute($sql->Prepare("
SELECT ACT_USERNAME,ACT_ID
FROM gm_actors
WHERE ACT_ID=".$sql->Param('a')),array($keys));
print $sql->ErrorMsg();
if($stmt->RecordCount()>0){
$editobj = $stmt->FetchNextObject();
$uname = $actordetails->ACT_USERNAME;
}
break;
case "savepwd":
print_r($_POST);
$duplicatekeeper = $session->get("post_key");
if($action_key != $duplicatekeeper){
$session->set("post_key",$action_key);
if(!empty($inputpassword) && !empty($keys) ) {
$inputpassword = $crypt->loginPassword($uname,$inputpassword);
$stmt = $sql->Execute($sql->Prepare("
UPDATE gm_actors
SET ACT_USERPASSWORD=".$sql->Param('b')."
WHERE ACT_ID=".$sql->Param('d')." "),
array($inputpassword,$actordetails->ACT_ID));
$msg = "Password has been changed successfully.";
$status = "success";
// $activity = ' Agent'.$keys.' password changed .';
// $engine->setEventLog("032",$activity);
}else if($inputpassword!==$confirmpassword){
$msgs="Sorry! Passwords Do not Match.";
$target ='changepwd';
} else {
$msg = "Unsuccessfully: All fields are required.";
$status = "error";
$view ="changepwd";
}
}
break;
}
$stmtusers = $sql->Execute($sql->Prepare("
SELECT ACT_SURNAME,ACT_ID,ACT_OTHERNAMES,
ACT_USERNAME,ACT_STATUS,ACT_EMAIL,ACT_PHONE,
ACT_ACCESS_LEVEL,ACL_NAME
FROM gm_actors
left join gm_actors_level on ACT_ACCESS_LEVEL=ACL_NUMBER
WHERE ACT_ACCESS_LEVEL !='1'
AND ACT_STATUS !='4'
ORDER BY ACT_SURNAME "));
print $sql->ErrorMsg();
include("model/js.php");
include('public/alertmessage/message.php');
?>
I'm having a submit form where the form includes the following text fields
First name
Last name
Email
Password
When user enters the general password of "DEFAULTDOC" it will automatically download the file. But if not then it will show an alert box that says "Sorry your password is incorrect".
My codes is working fine. But the alert box in
"You are now verified the file will automatically download."
Doesn't show but the downloading of file is working also the inserting of data is working too. Except of showing the alert box. What could be the reason why the alert box doesn't show up?
here's my code: (dlform.php)
<?php
$database = 'db';
$host = 'localhost';
$username = 'username';
$password = 'password';
$e = $_POST['e'];
$p = $_POST['p'];
$f = $_POST['f'];
$l = $_POST['l'];
if($_POST['p'] == "DEFAULTDOC"){
try
{
$connect = new PDO("mysql:host=$host;dbname=$database", $username, $password);
$connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = "INSERT INTO dlform VALUES('','$p','$f','$l','$e')";
$data = $connect->query($query);
header('Content-type: application/vnd.ms-word');
header('Content-disposition: attachment; filename=InformationSheet.docm');
?>
<script>
alert('You are now verified the file will automatically download.');
window.location.href='downloadform.php';
</script>
<?php
}
catch(PDOException $error)
{
$error->getMessage();
}
}else{
?>
<script>
alert('Sorry your password is incorrect.');
window.location.href='downloadform.php';
</script>
<?php
}
?>
Here's my html code:(downloadform.php)
<div class="container" style="margin: 0 auto; width: 600px;margin-top: 10%;">
<center>
<img src="images/menu_bar_logo.png" alt ="" style="width: 300px;"/></center>
<br>
<div class="row">
<b>Note:</b>Fill up the following fields to get your form<br>
<form method="post" action="dlform.php">
<br>
<div class="input-group">
<span class="input-group-addon">First name</span>
<input id="msg" type="text" class="form-control" name="f" placeholder="First name">
</div>
<div class="input-group">
<span class="input-group-addon">Last name</span>
<input id="msg" type="text" class="form-control" name="l" placeholder="Last name">
</div>
<Br>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input id="email" type="email" class="form-control" name="e" placeholder="Email">
</div>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input id="password" type="password" class="form-control" name="p" placeholder="Password">
</div>
<br>
<input type="submit" name="submit" class="btn btn-primary" value="Submit">
</form>
</div>
You try to use html tag while dlform.php only has php code. It won't work. Try to set the message into SESSION.
Your code
<script>
alert('You are now verified the file will automatically download.');
window.location.href='downloadform.php';
</script>
Change your code into php
$_SESSION['message'] = 'You are now verified the file will automatically download.';
header('Location: downloadform.php');
The same goes for incorrect password one.
And in your downloadform.php, add this code.
<?php if (isset($_SESSION['message'])): ?>
<div class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Message</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p><?php echo $_SESSION['message']; ?></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary">Save changes</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php unset($_SESSION['message']); ?>
<?php endif; ?>
This code is in bootstrap style. This code is not an alert, but a modal similar to alert. It will show up if there is a message from dlform.php. After the message is shown, destroy the message session so it won't appear each time downloadform.php is reload, unless you submit the form.
I'm building a form within a Boostrap Modal, it has 3 INPUT fields and a Submit button for each row. Each Submit is POST onto another page. What I then want to do is use the variables to return data into a table which will show all the results for that particular search ie Postcode, StreetName. Within the table I have a SUBMIT button which will return the output into my main form on the main page.
The section I'm struggling with is to get the variable from the INPUT (from my modal, which I'm using on jobdetailssearch.php) to POST onto the search page (search.php). Once this is return then I'm going to show all the results in the form on my jobdetails page (jobdetails.php)
This below is my code for the 3 pages.
jobdetailssearch.php
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
<h4 class="modal-title">Search Projects</h4>
</div>
<div class="modal-body">
<form class="modal-form" id="searchform" name="searchform" action="includes/search.php" method="post">
<div class="form-group">
<label class="col-md-4 control-label">Project Number</label>
<div class="col-md-6">
<input type="text" class="form-control input-inline input-medium" name="searchprojno" id="searchprojno" placeholder="Enter Project Number">
</div>
<button type="submit" class="btn blue" id="submitsearchprojno" name="submitsearchprojno" >Search <i class="m-icon-swapright m-icon-white"></i></button>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Address</label>
<div class="col-md-6">
<input type="text" class="form-control input-inline input-medium" name="searchaddress" id="searchaddress" placeholder="Enter Address">
</div>
<button type="submit" class="btn blue" id="submitsearchadd" name="submitsearchadd" >Search <i class="m-icon-swapright m-icon-white"></i></button>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Postcode</label>
<div class="col-md-6">
<input type="text" class="form-control input-inline input-medium" name="searchpostcode" id="searchpostcode" placeholder="Enter Postcode">
</div>
<button type="submit" class="btn blue" id="submitsearchpc" name="submitsearchpc" >Search <i class="m-icon-swapright m-icon-white"></i></button>
</div>
<div class="form-group">
<div class="col-md-12">
<div class="table-responsive">
<table class="table table-striped table-bordered table-advance table-hover">
<thead>
<tr>
<th width="100px"><i class="fa fa-list-alt"></i> Address</th>
<th width="50px"></th>
</tr>
</thead>
<tbody>
<tr>
<td width="100px"></td>
<td width="50px">Select Address</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="modal-footer right">
<button type="button" data-dismiss="modal" class="btn default">Cancel</button>
<!--<button type="submit" class="btn blue">Select</button>-->
</div>
</form>
</div>
search.php
<?php
require '../core/cnn.php';
if(isset($_POST['submitsearchprojno'])) {
$searchprojno = $_POST["searchprojno"];
}
if(isset($_POST['submitsearchadd'])) {
$searchaddress = $_POST["searchaddress"];
}
if(isset($_POST['submitsearchpc'])) {
$searchpostcode = $_POST["searchpostcode"];
}
$searchpostcode = mysql_real_escape_string($searchpostcode);
$searchaddress = mysql_real_escape_string($searchaddress);
$searchprojno = mysql_real_escape_string($searchprojno);
$searchrs = mysql_query("SELECT ProjectNo, CONCAT(COALESCE(HouseNoName, ''), ' ', COALESCE(StreetName, ''), ' ',
COALESCE(TownOrCity, ''), ' ', COALESCE(Postcode, '')) AS Display,
PropID, AreaID, AWGMember, Householder, HouseNoName, StreetName, TownOrCity,
Postcode, ContactTelephone, AlternatePhone, Email, PropertyTenure, PropertyNotes
FROM prop_property
WHERE IsActive = 1
AND (Postcode = '".$searchpostcode."'
OR StreetName = '".$searchaddress."'
OR ProjectNo = '".$searchprojno."')
") or die(mysql_error());
$checkrs = mysql_query("SELECT * FROM prop_property WHERE IsActive = 0");
if(!mysql_num_rows($checkrs) > 0) {
echo '<td> No record found!</td><td></td>';
}
else {
while ($results = mysql_fetch_array($searchrs)) {
echo '
<td>'.$results['Display'].'</td>
<td>
<form action="jobdetails.php" method="post">
<input type="hidden" name="searchhouse" value=" '.$results['HouseNoName'].'" >
<input type="hidden" name="searchstreet" value=" '.$results['StreetName'].'" >
<input type="hidden" name="searchtown" value=" '.$results['TownOrCity'].'" >
<input type="hidden" name="searchpostcode" value=" '.$results['Postcode'].'" >
<input type="hidden" name="searchpropid" value=" '.$results['PropID'].'" >
<input type="hidden" name="searchprojectno" value=" '.$results['ProjectNo'].'" >
<button type="submit" class="btn default btn-xs blue-stripe" name="viewsearch">View Address</button>
</form>
</td>';
}
}
?>
The modal opens fine and shows the form in the way I want. What's the best way I should go about this to input the search criteria and show the results in a table for me to select and pull on to my main form on jobdetails.php (I've not included this as it's too big and not sure its needed to be seen)?
Let me know if I understood your issue, you have your form in a modal view of bootstrap and you want send the data in the form to another page, process the search and then return the data that you find to the same modal and put it into the < tables> that's your issue?
Well, if that is. Look I think the easier way to do this is using jquery, and change the input submit for a input button, because I don't remember very well but when you send a submit inside the modal, the modal it's closed. That's true? if that the problem change the submit for a button. Then you have to create a function .click() to the button to catch the event click, with the .serialize() (if you want to check that you really are recieving the data you can make a die(var_dump($_POST)); in the php and check it in the console with firebug or something like that.) you get the data of your < form> and then you have to send it with a .post() to the other file, in the php you recive the data and When you recive the response you can put it into the table with .html().
So the code that I'm thinking should look like this, uou can change it to make it how you need it, but this can be the base:
JQUERY CODE:
$(document).ready(function(){
$("#yourButtonID").click(function(){
data = $("#yourFormID").serialize();
$.post("yourPHPfileToSearch.php",data,function(dataReturn)){
$("#yourTableID").html(dataReturn);
});
});
});
Let me know if you need more helpe. Regards. Have a nice day.