Jump to content

helloworld001

Members
  • Posts

    90
  • Joined

  • Last visited

Posts posted by helloworld001

  1. If you do want multiple projects/sites on your dev box, create a virtual host and you don't need to muck around with that stuff. Each project should have one. Then the url could just be "www.yoursite.dev" or whatever you want the domain name to be on your dev server instead of "localhost/projectname". Then when you create absolute links like "/post/12/postname" it would be correct, like www.yoursite.dev/post/12/postname. You also wouldn't need to alter settings between the dev and live servers.

    Understood. I will try that.

     

    Thanks.

  2. Then you need to account for the "websitename". Best would be rebasing the site into that folder (ie, setting the DocumentRoot to be /path/to/websitename) or else you'll need to track that value somewhere and make sure you output it every time you generate URLs.

    Because you can't do relative paths (eg, just "post/12/postname") all the time: on the /websitename/post/12/postname page, trying that link again would take you to /websitename/post/12/post/12/postname.

     

    Here is the new link.

    <a href="/websitename/post/12/postname">
    	Click here to see the post!
    </a> 
    

    It appears as  in the url and it gives an internal server error.

     http://localhost/websitename/post/12/postname.
    

    How do I set up the DocumentRoot path in the .htaccess?

  3. You have to change your own links so the second form is what you should use - not the post.php one.

     

    1. The link should be absolute, so /post/12/postname (note the leading slash)

    2. Your RewriteRule requires a trailing slash so either you remove that or you put the slash in your URLs

     

    If you still get an Internal Server Error, try

    Options +FollowSymLinks -MultiViews

     

     

     

    Here is the updated link with the added slash.

    <a href="/post/12/postname">
    	Click here to see the post!
    </a> 
    

    The url does change now in the url field. It looks like this. http://localhost/post/12/postname, when it should look like this http://localhost/websitename/post/12/postname   It does not give me the internal error but it gives me a different error. 

    "The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error."

  4. Here is what I am trying to do.

     

    Get from this

    http://mysite.com/post.php?id=12&title=postname

     

    to this

    http://mysite.com/post/12/postname/

     

     

    here’s the rewrite rule.

    Options +FollowSymLinks
    
    RewriteEngine On
    
    RewriteRule ^post/([a-zA-Z]+)/([0-9]+)/$ post.php?id=$1&title=$2
    
    

    This is my html link that links to the post.php page.

    <a href="post.php?id=12&title=postname">
    	Click here to see the post!
    </a> 
    

    It does not change the url. 

     

     

    I have also tried it like below and it gives me an internal error.

    <a href="post/12/postname">
    	Click here to see the post!
    </a> 
    

    Can you see what I have done wrong?  Also if the above method for the linking is correct, how do I get the "id" and "title" using the $_GET?

     

     

  5. You need to store their ID in the URL somewhere to make it unique. The name alone is not enough. For example:

    example.com/member/1234/johnsmith

    or example.com/member/1234-johnsmith

     

    When someone visits the URL you extract the ID and use that to locate the member. Just ignore the name part, it's there only for SEO / Users benefit.

     

    Yes I came to that concolusion as well, Your idea of using their unique id with the name is very nice.

  6. I can't speak for the way Shopify specifically achieves this, but this can easily be achieved through Ajax calls to the database.

    Basically, the user selects certain preferences for background colors etc. and these values are then stored in the db. When the user logs in again, these values are extracted from the db and presented as CSS values. When the user wants to change these settings they have some user settings link which allows them to do this. The information is sent to the back-end through Ajax, stored in the database and then Javascript updates whatever elements on the screen.

     

    This is interesting. I will have to dig more on how to do what you have mentioned.

  7. If you want their name to appear in the url then just show it regardless whether anyone else has that name. 

    I assume they are logged in so they are the only ones viewing it. The session is what will keep track of who they really are as they move about from page to page. The username is their unique identity, not their real name.

     

    The thing is, I am not using usernames for unique id.  The only other unique id I can think of is the register id itself.  Come to think of it, I think I know how this can be achieved.  I think I have to create 2 columns for the full name. Column 1 will be regular name  and column 2 will be regular name + unique number.  This way I can input the name with unique number in the url field and use that to fetch rest of the user information from the database.

  8. Question 1. Say I have a register form where a member registers with their full name but  many people can have the same full name. What would be the best way to make the full name appear unique in the url(eg. website.com/member/johnsmith) for each member?

     

    Question 2.  I am not sure about other CMS but Shopify has this feature where you can change the colors of certain things on the website, in the backend. How is that achieved? I am a little lost on how you should connect css with php.

     

     

  9. For eg.  I have a page with a query that retrives records from the database and I want to have options of filtering out the shown records by date, time, likes, views..etc; how would I go about doing that?

     

    The way I am thinking is having a html form with those filter inputs and using a relative query based on the filter selection to retrive the results.  

     

    What you think? 

  10. have you set the PDO error mode so that an error will throw an exception?

     

    id's in database tables are generally defined to be unique and trying to insert more than one row with the same id value could be (depending on your table definition) throwing an error.

     

    btw - in your ajax code, you need to prevent the default form action so that the form won't submit a second time.

     

     

    I have solved the issue.  

     

    I did add "ev.preventDefault();" into the ajax code.  But the real problem was that I had to change the ' Input type="submit" ' to ' Input type="button" '.  Now it works like a charm.

     

    Also in my original code, It's $_POST and not $_GET for the name and details variables.

  11. Below is my code that is suppose to insert and show records from database using ajax. 

     

    Retrieving the records from the database works.  However it won't insert a record.  I do not get any errors. The page simply refreshes when I hit submit button.

     

    Can you see what might be wrong in my code?

     

     

    index.php

    <script>
    	$(document).ready(function(){
    		function showComment(){
    		  $.ajax({
    			type:"post",
    			url:"process.php",
    			data:"action=showcomment",
    			success:function(data){
    				 $(".wrapper").html(data);
    			}
    		  });
    		}
    
    		showComment();
    
    
    		$("#submit").click(function(){
    
    			  var name=$("#name").val();
    			  var message=$("#details").val();
    
    			  $.ajax({
    				  type:"post",
    				  url:"process.php",
    				  data:"name="+name+"&details="+message+"&action=addcomment",
    				  success:function(data){
    					showComment();
    					  
    				  }
    
    			  });
    
    		});
       });
       </script>
    
    $id      =     $_GET['id'];
    $title    =    $_GET['title'];
            
    $_SESSION['id']      =    $id;
    $_SESSION['title']   =    $title;
    
    <div class="wrapper"></div>
    
    <form action="" method="post" enctype="multipart/form-data">
        <div class="newfield">
            <label for="title">Name <span class="highlight">*</span></label>
            <input id="name" type="text" name="name">
        </div>
        <div class="newfield">
            <label for="details">Details <span class="highlight">*</span></label>
            <textarea id="details" name="details""></textarea>
        </div>
        <input type="submit" name="submit" id="submit" value="Submit Tale">
    </form>
    
    
    

    process.php

    <?php require_once '/core/init.php';
    
    $id 	= 	$_SESSION['id'];
    		
    $action = $_POST['action'];
    
    if($action == 'showcomment') {
    
    	try {
    		$get = $db->prepare("SELECT * FROM sub_posts WHERE id = :id");
    		$get->bindParam('id', $id);
    		$get->execute();
    		$getStmt = $get->fetchAll(PDO::FETCH_ASSOC);
    		if(count($getStmt) > 0) {
    			
    			foreach($getStmt as $row) {
    			
    				$new_name		= 	$row['name'];
    				$new_details	= 	$row['details'];
    				
    				?>	
    					<ul>
    						<li>
    							<?php echo $new_name; ?>
    						</li>
    						<li>
    							<?php echo $new_details; ?>
    						</li>
    					</ul>
    				<?php 
    			}	
    			
    		} else {
    
    			// no records found.
    			
    		}
    		
    	} catch(Exception $e) {
    		die($e->getMessage());
    	}
    
    } else if($action == 'addcomment') {
    								
    	$name		= 	$_GET['name'];
    	$details	= 	$_GET['details'];
    			
    	
    		try {
    			
    			$insert = $db->prepare("INSERT INTO sub_posts(id, name, details) VALUES(:id, :name, :details)");
    			$insert->bindParam('id', $id);
    			$insert->bindParam('name', $name);
    			$insert->bindParam('details', $details);
    			$insert->execute();
    			
    			if($insert == false){
    				
    				echo 'record could not be inserted.';
    				
    			} else {
    			
    				echo 'record has been inserted.';
    			
    			}
    			
    		} catch(Exception $e) {
    			die($e->getMessage());
    		}
    	
    
    } else {
    
    	echo 'no results.';
    }
    
  12. I have a pdo prepared statement that fetches records from mysql database.  The records show up on the page. However if there are no records on a page, I get this error message.

     

    "QLSTATE[42000]: Syntax error or access violation: 1064 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 '-10' at line 4"

     

    Here is my statement

    $getCategoryId = $_GET['id'];
    $limit = 10;
    $offset = ($page - 1)  * $limit;
    
    $statement = $db->prepare("SELECT records.*, categories.* FROM records 
    LEFT JOIN categories ON records.category_id = categories.category_id
    WHERE records.category_id = :category_id 
    ORDER BY record_id DESC LIMIT {$limit} OFFSET ".$offset);
    $statement->bindParam('category_id', $getCategoryId);
    $statement->execute();
    $results = $statement->fetchAll(PDO::FETCH_ASSOC);
    

    If I remove try and catch block, it'll tell me exactly which line is giving the issue.  So from the above code, the error has to do with "$statement->execute();".  This is where the error occurs.

     

    As far as I know, the above pdo statement is correct.  Can you tell me if something is wrong with it?

×
×
  • 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.