Jump to content

Arbu

Members
  • Posts

    39
  • Joined

  • Last visited

Everything posted by Arbu

  1. Slightly disconcertingly, though, I find that Notepad++, which I use, doesn't show the code formatting colours when I put the inverted commas around the php. This makes it look as if the code won't work, although clearly it does.
  2. If you want to write a program on your own PC I don't understand why you wouldn't use vb.net or the like. Do people just want the program to operate through their browser? Anyway thanks for the link, I'll have a look. Actually I guess I can just use php instead. All I'm trying to do is make a cURL command so php ought to be adequate. Maybe Python is for full blown applications that run on the server. There's a handy converter here https://reqbin.com/req/java/c-w7oitglz/convert-curl-to-http-request
  3. OK, thanks. But then how do I actually use it? Presumably I have to put something in my file like I do with php: <?php.....?> I have looked over the Python tutorial and I can't see where it tells me this fundamental piece of information. It only seems to talk about using it on my own PC. Maybe I have to use a module and have my Python code separate from my other code? Edit: No it's not that. When I try that I get the message "non-JS module files deprecated".
  4. Arbu

    node.js

    You say that "Node.js uses JavaScript on the server". But your tutorial relates to setting up my own computer as a server and running node on that. I need to use the server from my hosting company. When I try to use node on my website I fall at the first hurdle. I get the error: "Uncaught ReferenceError: require is not defined". How do I ensure that node is running on my hosting provider?
  5. I have some data in the form "I-AHUSH" (it's a Paypal subscription reference). I'm saving it as a $_SESSION variable on the server. When I recover it and do the following, javascript insists on treating it as something to be evaluated. This causes an error. How do I stop it from doing so? You can see that I've tried forcing it to be a string. But that doesn't help. var s = String(<?php echo $_SESSION['subscriptionid'] ?>); Thanks
  6. I think I've got it. You have to specify type="button" for the button. Otherwise it's treated as if the type were "submit".
  7. Er, that's not so good because then none of the data is set to the server. But if I don't have it, the form seems to get submitted before the Paypal instructions are completed. I'd really like to understand what the trigger is for submitting the form. I had thought that it would be done by the user clicking a button with type="submit". But my button doesn't have this type. So what on earth is the trigger? Is it just the fact of hiding the form?
  8. The instructions I was using to do this are now in "quality review" (https://www.wikihow.com/Create-a-Secure-Login-Script-in-PHP-and-MySQL) so I guess I'll have to start again with another set of instructions. It seems incredibly complicated for something that many websites seem to do without any problems.
  9. OK thanks. So the file which includes it does so, as I say, at the beginning, and it contains an html form. Once the user has completed the form and pressed "Submit", the data gets sent to the server. I then want register.inc.php to be run using that data. So it seems that the include statement is placed in a completely inappropriate place in the file. register.inc.php should only be included after the form has been submitted. Otherwise the data won't be there. Should it be included in the form's onsubmit property perhaps?
  10. I've got some code which looks like this: <?php if (isset($_POST['username'],$_POST['first_name'],$_POST['surname'], $_POST['email'], $_POST['p'])) { // Sanitize and validate the data passed in... in a file called register.inc.php. The only references to this file are include_once 'includes/register.inc.php'; in the opening lines of a couple of other files. What is puzzling is just how the php condition gets called. Is it called continuously, so that as soon as the variables have been set, it triggers? Or is it called when the page that includes it is loaded? Whatever, it doesn't seem to be called like a normal function. It all seems a bit mysterious and unexplained. Can anyone help me out? Thanks.
  11. OK, I added this into the form declaration, and it seems to fix it: onsubmit="return false"
  12. Hmm, if I type the code from showpaypal() into the chrome console and execute the lines one by one it all works well. But I'm still getting the same problem with calling this function on the page- the paypal div shows for an instant and then the form details reappear.
  13. I'm trying to set up a registration form with Paypal payment. Once all the data has been entered and verified in the form, the registration form should be hidden and the Paypal form show. But the Paypal form only shows for two seconds before the registration form reappears. What am I doing wrong? I attach code below. Also, I don't understand the lines in regformhash which someone else has written for me. It seems that you can return multiple instructions in one line in a function. But what does the false at the end of each line do? Where does it get picked up? Thanks. <form class="clearfix" method="post" id="registerform" name="registration_form" action="<?php echo esc_url($_SERVER['PHP_SELF']); ?>"> <div class="form" id ="formdetails"> <input class="user" type="text" placeholder="Username" name="username" autocomplete="off"> <input class="first_name" type="text" placeholder="First Name" name="first_name" autocomplete="off"> <input class="surname" type="text" placeholder="Surname" name="surname" autocomplete="off"> <input class="em" type="text" placeholder="Email" name="email" autocomplete="off"> <input class="pass" type="password" placeholder="Password" name="password" autocomplete="off"> <input class="pass" type="password" placeholder="Confirm Password" name="confirmpwd" autocomplete="off"> </div> <div id="clearfix"> <div style="width: 50%; float: right; position: relative; height: 54px;"> <button class="register" onclick="return regformhash(this.form, this.form.username, this.form.first_name, this.form.surname, this.form.email, this.form.password, this.form.confirmpwd);">Continue</button> </div> <div class="terms"> <!-- <label style="line-height: 36px; font-size: 14px; font-family: Lato; color: #4285F4; padding-left: 6px;">Terms and conditions</label> --> </div> </div> <div id="paypal-button-container" hidden ="true"></div> <script src="https://www.paypal.com/sdk/js?client-id=Aa0YBaV1-WR_MAf-ExcJw38f8kwG-Oir7r5xPgbC1Bz1-tgEC4J6UAPNZopfkyBzzE4vMie3WiBdYIyF&vault=true&intent=subscription" data-sdk-integration-source="button-factory"></script> <script> paypal.Buttons({ style: { shape: 'rect', color: 'gold', layout: 'vertical', label: 'subscribe' }, createSubscription: function(data, actions) { //this triggers on the user clicking a Paypal button. return actions.subscription.create({ 'plan_id': '****************' }); }, onApprove: function(data, actions) { document.getElementById("registerform").submit(); } }).render('#paypal-button-container'); </script> </form> <script type = "text/javascript"> function showpaypal(){ document.getElementById("formdetails").hidden=true; document.getElementById("clearfix").hidden=true; document.getElementById("paypal-button-container").hidden=false; return false; } function regformhash(a, b, h, i, c, d, e) { if ("" == b.value ) return swal({title: "Please try again",text: "Please enter your username.",showConfirmButton: true,showCancelButton: false,allowOutsideClick: true}), a.username.focus(), false; if ("" == h.value ) return swal({title: "Please try again",text: "Please enter your first name.",showConfirmButton: true,showCancelButton: false,allowOutsideClick: true}), a.first_name.focus(), false; if ("" == i.value ) return swal({title: "Please try again",text: "Please enter your surname.",showConfirmButton: true,showCancelButton: false,allowOutsideClick: true}), a.surname.focus(), false; if ("" == c.value ) return swal({title: "Please try again",text: "Please enter your email address.",showConfirmButton: true,showCancelButton: false,allowOutsideClick: true}), a.email.focus(), false; if ("" == d.value ) return swal({title: "Please try again",text: "Please enter your password.",showConfirmButton: true,showCancelButton: false,allowOutsideClick: true}), a.password.focus(), false; if ("" == e.value ) return swal({title: "Please try again",text: "Please confirm your password.",showConfirmButton: true,showCancelButton: false,allowOutsideClick: true}), a.confirmpwd.focus(), false; if (f = /^\w+$/, !f.test(a.username.value)) return swal({title: "Please try again",text: "Username must contain only letters, numbers and underscores.",showConfirmButton: true,showCancelButton: false,allowOutsideClick: true}), a.username.focus(), false; if (f = /^[a-zA-Z]*$/, !f.test(a.first_name.value)) return swal({title: "Please try again",text: "First name must contain only letters.",showConfirmButton: true,showCancelButton: false,allowOutsideClick: true}), a.first_name.focus(), false; if (f = /^[a-zA-Z]*$/, !f.test(a.surname.value)) return swal({title: "Please try again",text: "Surname must contain only letters.",showConfirmButton: true,showCancelButton: false,allowOutsideClick: true}), a.surname.focus(), false; if (d.value.length < 6) return swal({title: "Please try again",text: "Passwords must be at least 6 characters long.",showConfirmButton: true,showCancelButton: false,allowOutsideClick: true}), a.password.focus(), false; var f = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}/; if (!f.test(d.value)) return swal({title: "Please try again",text: "Passwords must contain at least one number, one lowercase and one uppercase letter.",showConfirmButton: true,showCancelButton: false,allowOutsideClick: true}), false; if (d.value != e.value) return swal({title: "Please try again",text: "Your password and confirmation do not match.",showConfirmButton: true,showCancelButton: false,allowOutsideClick: true}), a.password.focus(), false; //regardless of whether the last argument here is true or false, the paypal buttons only show for two seconds before the page reverts to show the form details. showpaypal(), true; } </script>
  14. 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.
  15. 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.
  16. 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.
  17. 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.
  18. 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?
  19. var data = encodeURIComponent(formattedJSON()); seems to fix the problem.
  20. 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.
  21. 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.
  22. 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; ?>
  23. 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); }
  24. 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.
×
×
  • Create New...