Jump to content

Arbu

Members
  • Posts

    45
  • Joined

  • Last visited

Posts posted by Arbu

  1. I've got a database of files which is kept on a server and for which I use MySQL. Each entry includes a user ID, a unique reference, and file data. I would like to now allow users to share files, in a similar fashion to how it's done on Dropbox. I'm trying to figure out what the format of the amended database will be. I have a separate database with the details of all users. I think:

    1. The user ID should be removed from the files database.

    2. The users database should have extra columns listing, by ID, (a) all files created by the relevant user (who remains the "owner" of the files, and is the only person who can delete them or invite other people to access them), (b) all files which the relevant user can view, and (c) all files which the relevant user can view and edit. I think each file should only appear in one of a, b and c.

    3. To populate the list of files which are available for the active user I need to loop through each of a, b and c. I will also have to display who else can use the relevant file, so to do that I will also have to loop through the whole user database, not just the active user's entry in it. It will be fairly complicated to display, but Dropbox is my guide.

    I guess that's the thrust of it, but if anyone has any comments, I'd be pleased to hear them.

    Thanks.

  2. I have a web application which allows the user to have an account and store files under it. I'd like him to be able to share those files with other registered users, in a similar fashion to that done in Dropbox, except that he would never have to upload anything - the files are just created in the application. Can anyone give me any pointers as to how to do this? I guess it may not only be Dropbox that does this, so there may be a library or existing code that I can use.

    Thanks.

  3. Well, if a desktop browser is resized, the application won't work on that either. So the test is for the screen width.

    Anyway, my code seems to be working OK now:

    if (screen.width < 1150)  {
    	var amv2 = sessionStorage.getItem("amv");
    
    	if (amv2 !== 'true') {
    
    	window.location = 'sorry.html';}
    	
    };

    It's in a script and I wanted to call it from other pages that don't include the whole script, but my function idea wouldn't work. Also the test for the variable amv2 being true required inverted commas around true to work. I don't know why. I set it to true, not 'true' after all.

    And for debugging the script I can just add a line to throw an error, and get the Chrome console to break on all errors.

  4. 23 hours ago, dsonesuk said:

    The way I checked if device is mobile is to check if it supports touchscreen, which was a good few years ago.

     

    But the issue is the screen size, not whether it supports touchscreen. Tablets typically support touchscreen.

  5. I've got a web application which isn't optimised for mobile phone usage and I don't think it would every be practical to do it. But when I tell people about the application they always go and look it up on their phones. So I was thinking that I would have a page that explains, when they look on their phones, that it really isn't designed for use on a phone, but, if they really want, they can access it on their phone to get an idea of what the product looks like. This is proving a lot harder than I expected. I have some code which redirects from the main page to a warning page. But I can't debug it in the Chrome console because it only ever appears for a fraction of a second. When the user clicks on a link on the warning page, that is supposed to set a variable so that the phone knows not to redirect to the warning page next time the main page is shown. But every time it does redirect to the warning page, and I can't tell why it keeps doing this. I'm trying to debug it, but the console messages that I have inserted never seem to appear. Maybe they are there for such a short time that I can't see them. Anyway my code is below. Can anyone help?

    Thanks

    In init.js:

     redirectformobile();
     
     function redirectformobile()
     {
     
    if (screen.width < 1150)  {
    	var amv = sessionStorage.getItem("amv");
    	console.log (amv);
    	if (amv !== true) {
    		console.log ("redirected");
    	window.location = 'sorry.html';}
    } 
     }

    In the warning page:

    <body>
    	<div class="outer">
            <span>
            Sorry, this is a web application and it requires too much screen space to be displayed well on your device.<br><br>
            <span>Please use a pc instead to view it.<a href="javascript:history.back()"> Go back.</a></span><br><br>
    		<span>If you would nonetheless like to view the application on your device, please click here. Operation will be difficult!<a onclick="allowmobileview()" href="index.php"> Take me to the site anyway.</a></span>
            </span>
        </div>
    </div>
    
    <script>
    	function allowmobileview(){
    		sessionStorage.setItem("amv", true);
    	}
    </script>

     

  6. I've got a few bits of php in my javascript. I understand it's better to minify my code. But if I use a javascript minifier for the whole lot I get "// Error : Unexpected token: operator (<)" where the php is. So what to do? Should I minify the php and javascript separately? Could take quite a while to go through it all.

    Thanks.

  7. 12 hours ago, Ingolme said:

    It seems that W3Schools does not explain how to set up and use Python on the server-side, maybe because it is very common for people to use Python for programming on their PC rather than as a server-side programming language.

    I don't use Python myself, so I can't tell you how it works. This page seems to have some explanations: https://pythonbasics.org/webserver/

    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

  8. 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".

  9. 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?

  10. 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

  11. On 4/8/2021 at 4:20 PM, Arbu said:

    OK, I added this into the form declaration, and it seems to fix it:

    
    onsubmit="return false"

     

    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?

  12. 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?

  13. 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.

  14. 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.

  15. 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>

     

  16. 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.

  17. 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.

  18. 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:

    Quote

    Error: UPDATE diagrams SET data={
        "version": "3.4.0",
        "objects": [
            {
                "type": "group",
                ...
        "linecounter": 1
    } WHERE id=88<br>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"version": "3.4.0",
        "objects": [
            {
                "type": "group",
        ' at line 2

    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.

  19. 5 hours ago, Ingolme said:

    It is probably that there is a quotation mark in the JSON contents.

    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.

  20. 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?

×
×
  • Create New...