Jump to content

rdkurth

Members
  • Posts

    14
  • Joined

  • Last visited

rdkurth's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I am having a problem making this work. It adds and deletes but it does it by passing the date directly to the PHP files and refreshing the screen. I want it to do it through the jquery Ajax script. This should work according to what I have read but no mater what I try the jquery script does not work. <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script> </head> <body> <script type="text/javascript"> $(document).ready(function(){ $('MySignform').submit(function(e) { e.preventDefault(); $.ajax({ type: 'POST', url: $('MySignform').prop('action'), data: $('MySignform').serialize(), success: function() { alert("It worked!"); } }); }); }); </script> <script type="text/javascript"> $(document).ready(function(){ $('DelForm').submit(function(e) { e.preventDefault(); $.ajax({ type: 'POST', url: $('DelForm').prop('action'), data: $('DelForm').serialize(), success: function() { alert("It worked!"); } }); }); }); </script> <br /> <br /> <br /> <center> <form name="MySignform" action="addsigningfee.php" method="post"> <label>Signing fee</label> <input name="signingfee" type="text" id="signingfee"/> <input name="pid" type="hidden" value="7"/> <p></p> <button id="form-submit" type="submit">Save</button> </form> <br /> <div id="result"></div> <br /> <form name="DelForm" action="delsigningfee.php" method="post"> <select name="signingfee"> <?php require_once("connect.php"); foreach ($db->query("SELECT signingfee,id FROM options WHERE signingfee <> '' AND pid = '7'") as $row) { echo "<option value=" . $row['id'] . ">" . $row['signingfee'] . "</option>"; } ?> </select> <p></p> <button type="submit" >Delete</button> </form> </center> </body> </html> Adding and Deleteing mysql date using jquery AjaxI am having a problem making this work. It adds and deletes but it does it by passing the date directly to the PHP files and refreshing the screen. I want it to do it through the jquery Ajax script. This should work according to what I have read but no mater what I try the jquery script does not work. Some help getting me In the right direction would be great. Code:<html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"></script> </head> <body> <script type="text/javascript"> $(document).ready(function(){ $('MySignform').submit(function(e) { e.preventDefault(); $.ajax({ type: 'POST', url: $('MySignform').prop('action'), data: $('MySignform').serialize(), success: function() { alert("It worked!"); } }); }); }); </script> <script type="text/javascript"> $(document).ready(function(){ $('DelForm').submit(function(e) { e.preventDefault(); $.ajax({ type: 'POST', url: $('DelForm').prop('action'), data: $('DelForm').serialize(), success: function() { alert("It worked!"); } }); }); }); </script> <br /> <br /> <br /> <center> <form name="MySignform" action="addsigningfee.php" method="post"> <label>Signing fee</label> <input name="signingfee" type="text" id="signingfee"/> <input name="pid" type="hidden" value="7"/> <p></p> <button id="form-submit" type="submit">Save</button> </form> <br /> <div id="result"></div> <br /> <form name="DelForm" action="delsigningfee.php" method="post"> <select name="signingfee"> <?php require_once("connect.php"); foreach ($db->query("SELECT signingfee,id FROM options WHERE signingfee <> '' AND pid = '7'") as $row) { echo "<option value=" . $row['id'] . ">" . $row['signingfee'] . "</option>"; } ?> </select> <p></p> <button type="submit" >Delete</button> </form> </center> </body> </html> addsigningfee.php <?php require_once("connect.php"); //print_r($_POST); //exit; $stmt = $db->prepare("INSERT INTO options(signingfee,pid)values(?,?)"); $stmt->bindParam(1, $_POST['signingfee'], PDO::PARAM_STR, 250); $stmt->bindParam(2, $_POST['pid'], PDO::PARAM_INT, 11); $stmt->execute(); ?> delsigningfee.php <?php require_once("connect.php"); $id = $_POST['signingfee']; $db->exec("DELETE FROM options WHERE id = '$id'"); ?>
  2. I need help with adding some ajax to my jquery script to pass a php var to a modal. I can open the modal with the bit of jquery below but I am at a lose on how to add any ajax to this jquery script to take the $id from the link to the modal. The jquery I am opening the modal with $(document).ready(function(){ $(".launch-modal").click(function(){ $("#editexpenses").modal({ keyboard: false }); }); }); I am opening the modal with this link to the jquery <a id="<?php $id ?>" title="Edit this item" class="launch-modal" href="#editexpenses">edit</a> The modal <div class="modal fade" id="editexpenses" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="myModalLabel">Modal title</h4> </div> <div class="modal-body"> <?php $id = $_POST['expID']; echo 'id' . $id; var_dump($_POST); ?> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog --> </div><!-- /.modal -->
  3. How can I call another script and pass a id so I can fill another drop down pulling data from mysql. I have added the scripts below I just don't understand how to call them $( document ).ready(function() { $.ajax({ //create an ajax request to load_page.php type: "GET", url: "customer.php", dataType: "html", //expect html to be returned success: function(response){ $(".responsetext").html(response); //alert(response); } }); }); THIS SCRIPT FILLES THE DROPDOWE BELOW USING responsetext <select name="customer"id="customer" class="form-control input-sm responsetext"> </select> SO WHEN I SELECT THIS IT WILL PASS THE ID AND RUN THE SCRIPT BELOW $(function() { // document.ready $("#id").on("change", function() { $.ajax({ url: "contact.php", type: "GET", data: { id: $(this).val() }, success: function(data) { $(".contactresults").html(data); } }); }); }); SO IT WILL FILL THIS SELECT BOX WITH contactresults <select name="contact" class="form-control input-sm contactresults" id="contact"> </select>
  4. oops I forgot I took Notice off error handling the other day. I'm bad!! this is the error Notice: Trying to get property of non-object I am new with PDO so I don't understand alot about it but what I have seen I like. What do you mean by "have you configured pdo to fetch the data as an object" and what are array notation
  5. I no about using try/catch block and yes I have the E_ALL and display_errors set to ON but this is just a test script to see how to fill in the area. What is happing is it is not passing any info from the database, It looks like the problem is in my select statment but I can not figure out way. This is what I am getting no data at all but there is four records it just not giving me the data. {"success":1,"result":[{"id":null,"title":null,"start":false,"end":false},{"id":null,"title":null,"start":false,"end":false},{"id":null,"title":null,"start":false,"end":false},{"id":null,"title":null,"start":false,"end":false}]}
  6. This script is running thru without any errors but it is not producing any data but the database is full of data. What am I doing wrong. I am trying to understatnd PDO with MYSQLI <?php include("connect.php"); $pid = $_SESSION['profile']['id']; $sql ="SELECT * FROM signings WHERE pid = \"$pid\" AND done= 0"; $result = $db->query($sql); $out = array(); // Parse the result set foreach($result as $row) { $out[] = array( 'id' => $row->id, 'title' => $row->lname, //'url' => Helper::url($row->id), 'start' => strtotime($row->signstart), 'end' => strtotime($row->signend) ); } echo json_encode(array('success' => 1, 'result' => $out)); exit;
  7. I'm trying to learn jquery and ajax and not doing so well I am trying to pass the id from this dropdown when it is selected to the next ajax script and it is not working. Both scripts pull there data from the same table so if there is a way to do this with one script I would be interested. <select name="customer"id="customer" class="form-control input-sm responsetext" > </select> $( document ).ready(function() { $.ajax({ //create an ajax request to load_page.php type: "GET", url: "customer.php", dataType: "html", //expect html to be returned success: function(response){ $(".responsetext").html(response); //alert(response); } }); }); <?php include("connect.php"); $id = $_SESSION['profile']['id']; echo "<option value=''>SELECT A CUSTOMER</option>"; foreach($db->query("SELECT * FROM customers WHERE pid = '$id'") as $row) { echo "<option value=" . $row['id'] . ">" .$row['name'] . "</option>"; } The above script creates the select box and it works. Now I need the $row['id'] To be picked up by the next script to fill in the input field. <input name="contact" class="form-control input-sm contactresults" id="contact"> $(function() { // document.ready $("#id").on("change", function() { $.ajax({ url: "contact.php", type: "GET", data: { id: $(this).val() }, success: function(data) { $(".contactresults").html(data); } }); }); }); <?php include("connect.php"); $id= $row['id']; echo "<option value=''>SELECT A CUSTOMER</option>"; foreach($db->query("SELECT * FROM customers WHERE id = '$id'") as $row) { echo $row{contact"}; }
  8. I need to pass a variable from html through ajax to php The following code is what I have contacttext is what fells in the data from ajax <select name="contact"type="text" class="form-control input-sm contacttext" id="idcontact"></select> $( document ).ready(function() { $.ajax({ //create an ajax request to load_page.php type: "GET", url: "php/contact.php", dataType: "html", //expect html to be returned success: function(response){ $(".contacttext").html(response); //alert(response); } }); }); $id is what I need to pass threw the ajax script <?php include("connect.php"); $pid = $_SESSION['profile']['id']; echo "<option value=''>SELECT A CONTACT</option>"; foreach($db->query("SELECT * FROM contact WHERE pid = '$pid' AND cid = '$id'") as $row) { echo "<option value=" . $row['cid'] . ">" .$row['contact'] . "</option>"; }
  9. I fixed the div errors But it still did not work </head> <body> <select name="customer"> <div id="responsetext"></div> </select> </body> </html> </head> <body> <select name="customer"id="responsetext"> </select> </body> </html> I put it in the select tag still did not work. This is frustrating I start to think I have jquey and ajax figured out and then this happens. any other ideas
  10. I am having a problem understanding why when I run my script and I put the results inside a select statement it does not show the values but when I remove the select statement the values or visible . The following code will show you what I mean. If you comment out the select statement in the html script it will work. I don't understand way <?php // CONNECT TO THE DATABASE $DB_NAME = 'notary'; $DB_HOST = 'localhost'; $DB_USER = 'root'; $DB_PASS = ''; $db=$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } ?> <?php include("db.php"); $sql='SELECT * FROM customer'; $result=$db->query($sql); while($row = mysqli_fetch_array($result,MYSQLI_BOTH)) { echo "<option value=" . $row['name'] . ">" .$row['name'] . "</option>"; } <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>ready demo</title> <script src="js/jquery.js"></script> <script> $( document ).ready(function() { $.ajax({ //create an ajax request to load_page.php type: "GET", url: "php/display.php", dataType: "text", //expect html to be returned success: function(response){ $("#responsetext").text(response); //alert(response); } }); /*$( "p" ).text( "The DOM is now loaded and can be manipulated." );*/ }); </script> </head> <body> <div align="center"> <select name="customer"> <!--<---comment out this line--> <div id="responsetext"> </select> <!--<---comment out this line--> </div> </body> </html>
  11. plunged it into full on production form and it worked don't no why it would not work with this little test form Thanks for the help
  12. I changed it but it is still make page reload any other ideas $("#sub").click( function(e) { //stop the click event from bubbling e.preventDefault(); $.post( $("#myForm").attr("action"), $("#myForm :input").serializeArray(), function(info){ $("#result").html(info); return false; // at end }); clearInput(); }); $("#myForm").submit( function() { return false; }); function clearInput() { $("#myForm :input").each( function() { $(this).val(''); }); }
  13. The three scripts below are working except when it returns "Successfully Inserted" it creates a new page. It is suppose to return "Successfully Inserted" between the <span> tags in the index.php page index.php <form id="myForm" action="userInfo.php" method="post"> Name: <input type="text" name="name" /><br /> Age : <input type="text" name="age" /><br /> <button id="sub">Save</button> </form> <span id="result"></span> my_script.js $("#sub").click( function() { $.post( $("#myForm").attr("action"), $("#myForm :input").serializeArray(), function(info){ $("#result").html(info); }); clearInput(); }); $("#myForm").submit( function() { return false; }); function clearInput() { $("#myForm :input").each( function() { $(this).val(''); }); } userinfo.php include_once('db.php'); $name = $_POST['name']; $age = $_POST['age']; if(mysql_query("INSERT INTO user VALUES('$name', '$age')")) echo "Successfully Inserted"; else echo "Insertion Failed";
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.