Jump to content

Arbu

Members
  • Content Count

    25
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Arbu

  • Rank
    Newbie

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. w3 schools says "Python can be used on a server to create web applications." and wikipedia says "Examples of commonly-used, web applications, include: web-mail, online retail sales, online banking, and online auctions.". But why do you need an application on the server to access these things? Surely the information is just held in a database or as variables which you can access with PHP and AJAX? What does Python add? I thought that a web application was something like Google Docs - something that is like a computer program but which you run in your browser. But would that actually run on the server? Surely you are better off with something like that running in the browser because otherwise there will be calls back to the server with every keystroke, which seems very inefficient. So maybe someone can clarify for me. Thanks.
  2. Arbu

    Can't update SQL record.

    I'm already saving files with much the same code, and that works OK. So I don't think there was an issue with not using prepared statements. What now seems to have fixed it however is simply placing single quote marks around $data in $sql.
  3. I'm getting an error when I try to update a record in my sql database. Here's my code: function updateRecord($mysqli,$diagram_id,$data,$image){ if(login_check($mysqli)){ $sql = "UPDATE diagrams SET data=$data WHERE id=$diagram_id"; if ($mysqli->query($sql) === TRUE) { // echo "Record updated successfully"; //header("Location: ../account.php"); echo "Success"; exit(); // return true; } else { echo "Error: " . $sql . "<br>" . $mysqli->error; // return false; } $mysqli->close(); exit(); } else { header('Location: ../login.php'); exit(); } } and the response I get is: I have some similar code for deleting a record which works fine: function deleteRecord($mysqli,$diagram_id){ if ($mysqli->connect_error) { die("Connection failed: " . $mysqli->connect_error); } $sql = "DELETE FROM diagrams WHERE id=$diagram_id"; if ($mysqli->query($sql) === TRUE) {} else { echo "Error deleting record: " . $mysqli->error; } $mysqli->close(); } What am I doing wrong? Thanks.
  4. Yes, there are loads. It seems that if I remove the single quotes around the php command the error goes away. I don't actually understand why they were there in the first place.
  5. I'm using this code <?php if (isset($_POST["json"])) : ?> loadfile('<?php echo $_POST["json"] ?>'); <?php endif; ?> to insert a command into my scrjavascript script and it appears like this: loadfile('{ ... ... }'); But I get a message for the loadfile line "Uncaught SyntaxError: Invalid or unexpected token". I can't see anything wrong. Why am I getting this error?
  6. var data = encodeURIComponent(formattedJSON()); seems to fix the problem.
  7. I'm sending some information to the server with AJAX: function saveFileToAccount(filename){ /** [Storing JSON representations of the canvas] */ var data = formattedJSON(); /** [Store preview of transaction diagram] */ var image = canvas.toSVG(); var xmlhttp = new XMLHttpRequest(); var sendstring = "filename=" + filename + "&json=" + data + "&image=" + image; xmlhttp.open("POST", "includes/process_save.php", true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.send(sendstring); } This goes into an SQL database and I get it back with php when a new page is opened. But the data comes back truncated at the first ampersand that it contains. How do I fix this? I suppose I could convert all the ampersands into a little used character before saving the data and then convert them back when it comes back, but that doesn't seem very satisfactory. Is there a proper way to sort this out? Thanks.
  8. OK, setting my display items for the login status wasn't too hard. I don't need an AJAX request to find out; I can just set a variable with php on loading the page. The problem I'm running into now is that, if the user enters the wrong login details I'd like the login form to remain in place so that I can give him a notification to that effect and he can try to enter in again. But by the time the code gets to hashandlogin, the login form has already gone. I tried removing data-iziModal-close from the submit button and closing the loginform manually if the login details were correct, but that really messed things up. Any ideas? Maybe I should simply redisplay the login form with the relevant message instead of trying to get it to stay in place.
  9. At the moment I have the following. But I need to update the page to show whether the user is logged in (a) on loading and (b) when he logs in. So I'm thinking that I need to make an AJAX request in $(document).ready to see if he is logged in, then have a js function to set the details on the page that I can call from there and also when he logs in and out. I don't know if there's some way to have php simply send the log in details when the page is loaded. <?php if (login_check($mysqli) == true) : ?> <p>Welcome <?php echo ucwords(htmlentities($_SESSION['username'])); ?>!</p> </div> <a href="account.php"><div class="userLogin tooltip" title="Your account"> <img src="images/icons/user.png" alt="" class="iconUser"> </div></a> <a href="includes/process_logout.php"> <div style="margin-right: 15px;" class="userLogin tooltip" title="Logout"> <img src="images/icons/logout.png" alt="" class="iconUser"> </div> </a> <?php else : ?> <p>You are not signed in.</p> </div> <div class="userLogin tooltip" title="Login or Sign Up" data-izimodal-open="loginform" data-izimodal-transitionin="fadeInDown"> <img src="images/icons/user.png" alt="" class="iconUser"> </div> <?php endif; ?>
  10. OK, thanks very much, it seems to work OK now. I've gone with using POST rather than GET because I wasn't sure if I'd need to change INPUT_POST if I used GET. Hopefully sorting out the display at the browser end should be reasonably straightforward now. function hashandlogin(a, b) { formhash(a, b); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { console.log(this.responseText); } }; var sendstring="email=" +document.getElementById("login_email").value + "&p="+document.getElementById("hashedp").value; xmlhttp.open("POST", "includes/process_login.php", true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.send(sendstring); }
  11. OK, good point, I hadn't noticed that that was there. So I've taken it out and now the page doesn't refresh. Hooray! The next thing is to get the data that I send to the server to be recognised. Naturally this doesn't work first time. I don't think that the server is actually finding the data that I send. Here's my code using the post method: function hashandlogin(a, b) { formhash(a, b); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { console.log(this.responseText); } }; xmlhttp.open("POST", "includes/process_login.php", true); xmlhttp.send("email=" +document.getElementById("login_email").value + "&p="+document.getElementById("hashedp").value); } and <?php include_once 'db_connect.php'; include_once 'functions.php'; sec_session_start(); // Our custom secure way of starting a PHP session. echo($_POST['email'] + 'abc'); exit(); The responseText is 0. What am I doing wrong? Edit: OK, so string concatenation in php is just done with a ".". But I'm still not getting the email setting through, just the abc. Same if I use GET and put the data after the url.
  12. Yes, but as I say, regardless of whether I have type=submit or not, the event.preventDefault never gets triggered. If I can fix that I'll have a go at putting my AJAX code in the curly braces with that. But otherwise there's no point in trying that.
  13. OK here's my code now. I believe there should be a question mark after process_login.php not a full stop as you have it. Anyway I'm getting told that the post data is not set correctly. <?php if (login_check($mysqli) == false) : ?> <div id="loginform" data-iziModal-group="grupo1"> <button data-iziModal-close class="icon-close">x</button> <!--watch out here - JSFormat formatted the izimodal spec to have spaces in it and the button no longer worked.--> <header> <a href="" id="signin">Sign in</a> </header> <section> <form name="login_form" id="login_form"> <input type="text" placeholder="Email" name="email" class="login_email" id="login_email"> <input id="password" type="password" placeholder="Password" name="password" class="login_password"> <footer> <button data-iziModal-close>Cancel</button> <button class="submit" data-iziModal-close onclick="hashandlogin(this.form, this.form.password);">Log in</button> <p style="text-align: center; color: #444; font-size: 16px; font-family: Lato; padding-top: 70px; font-weight: 500;"> Don't have an account? <a style="font-size: 16px; font-weight: 500; font-family: Lato;" href="register.php">Register here.</a></p> </footer> </form> </section> </div> <script type="text/javascript"> document.getElementById("login_form").addEventListener("submit", function (event) { event.preventDefault() }); function hashandlogin(a, b) { formhash(a, b); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { console.log(this.responseText); } }; xmlhttp.open("GET", "includes/process_login.php?email=" +document.getElementById("login_email").value + "&p="+document.getElementById("hashedp").value, true); xmlhttp.send(); } function formhash(a, b) { var c = document.createElement("input"); a.appendChild(c), c.name = "p", c.type = "hidden", c.id="hashedp", c.value = hex_sha512(b.value), b.value = "", a.submit() }
  14. Should it be the "submit" event or the "onsubmit" event. In any case I can't ever get the event.preventDefault() to trigger. If I set a break point there it doesn't get caught. If I take out the onclick property then still it doesn't trigger. I'll keep working on how to access the email and password from the form.
  15. Seems I have to take out the post method for the form or it still refreshes the page. Which means that I have to figure out how to send the login information to the server. I think I do it by adding the details at the end of the address in xlmhttp.open, although how I get these details in the first place doesn't look straightforward.
×
×
  • Create New...