Jump to content
Larry Ullman's Book Forums

thara

Members
  • Posts

    54
  • Joined

  • Last visited

Posts posted by thara

  1. I am trying to make SEO friendly URLs of using apache mod_rewrite.

    My normal URLs is something like this -

    index.php?p=about
    index.php?p=contact
    index.php?p=this

    My expecting SEO friendly URLs should be something similar to this -

    localhost/php_advance/ch02/about
    localhost/php_advance/ch02/contact
    localhost/php_advance/ch02/this

    I tried it with creating a .htaccess file and doing some changes to my apache httpd.conf file.

    This is my .htaccess file

    <ifModule mod_rewrite.c>
    
    # Turn on the engine:
    RewriteEngine on
    
    # Set the base to this directory:
    RewriteBase /php_advance/ch02/
    
    # Redirect certain paths to index.php:
    RewriteRule ^(about|contact|this|that|search)/?$ index.php?p=$1
    
    </ifModule>

    And also, At the end of the httpd.conf file, I added some code like this -

    <Directory "C:/wamp/www/php_advance/ch02">
    AllowOverride All
    </Directory>

    NOTE: I am using WAMP server and Windows 07

    But this coding is not working for me. Hope someone will help me out. Thank you.

  2. I have modified form_functions.inc.php to radio button for suit for me. But It seems its not working..

     

    This is my code so far..

     

    from form function

     

       	 if (preg_match('/sex\d{1}$/', $name)) {
               $i = substr($name, -1);
               $name = substr($name, 0, 3);
               $sex = array(1=>'Male', 'Female' );
    
               // Display the error first:
               if (array_key_exists($name, $errors)) {
                   echo ' <span class="inline-error">' . $errors[$name] . "</span>\n";
               }
    
               echo '<input type="' . $type . '"  name="' . $name . '"  value="' . $i . '" /> ' . $sex[$i] . '   ';
           }

     

     

    This is from validation code..

     

        // Check for gender:  
       $sex = array();
       for ($i=1, $count=2; $i <= $count; $i++) {
           if (isset($_POST['sex'. $i])) {
               $sex[] = $_POST['sex'. $i];
           }
       } // end for loop
       if (empty($sex)){
           $reg_errors['sex1'] = 'You have NOT entered your gender type!';
       }

     

    This from HTML

     

                               	 <div class="last-child">
                                   <?php
                                     for ($i=1, $count=2; $i <= $count; $i++) {
                                       create_form_input('sex' . $i, 'radio', $reg_errors);
                                     }
                                   ?>
                                   </div>   

     

     

    radio button working.. but validation not working its always going to error message..

     

    hope someone help me out this..

     

    thank you.

  3. Hello...

     

    I have a form to get some urls from users. Eg: Web Address, Facebook Address, Twitter Address, Google+ address etc... My problem is how I validate these urls when they submit the form. I tried to validate URL in PHP by using the FILTER_VALIDATE_URL or simply, using regular expression.

     

    Here, I would like to know what are the best methods to get such a urls from users. Is it always good to let them to enter protocol? sometimes they may not know it is http, https, ftp, ftps.. etc. I think it is something hard to do some users.

     

    I tried something like this using FILTER_VALIDATE_URL, But it always use protocol and sometime I am confusing how its work..

     

    // validate url
    $url = '[url="http://www.example.com%27;"]http://www.example.com';[/url]
    
    if (filter_var( $url, FILTER_VALIDATE_URL)){
    echo "<br>valid";
    } else {
    echo "<br>invalid";
    }
    
    [b]OUTPUT[/b] : valid

     

     

    // validate url
    $url = 'hp://www.example.com';
    
    if (filter_var( $url, FILTER_VALIDATE_URL)){
    echo "<br>valid";
    } else {
    echo "<br>invalid";
    }
    
    [b]OUTPUT[/b] : valid

     

    // validate url
    $url = 'http://example.com';
    
    if (filter_var( $url, FILTER_VALIDATE_URL)){
           echo "<br>valid";
    } else {
           echo "<br>invalid";
    }
    
    [b]OUTPUT[/b]: valid

     

    // validate url
    $url = 'http://example.com?id=32&name=kamalani';
    
    if (filter_var( $url, FILTER_VALIDATE_URL)){
           echo "<br>valid";
    } else {
           echo "<br>invalid";
    }
    
    [b]OUTPUT[/b] : valid

     

    Can you tell me what are the best ways to get urls from user and how those validate?

    Any comments are greatly appreciating..

     

    Thank you.

  4. thanks for reply.. SQL return the values properly...there are category_id, category_name, subject_id, subject_name. I have started the session properly in my configuration file and have included to this page. I am trying to display above return data into a list something like this..

     

    Catagory 01
      subjects1   subjects4
      subjects2   subjects5
      subjects3   subjects6
    
    Catagory 02
      subjects1   subjects4
      subjects2   subjects5
      subjects3   subjects6
    
    Catagory 03
      subjects1   subjects4
      subjects2   subjects5
      subjects3   subjects6
    

     

    I tried to do it like this. Its working as 50%. But I need to display subjects under each categories in a table with 2 columns.

     

        $catID = false;
    
    
       while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
    
           echo '<div>';
    
           if ( $catID != $row['ci']) {
    
               echo '<h3>Category 01: <span>' . $row['cn'] . '</span><span></span></h3>';
           }
    
           echo '<div class="container">';
    
               echo '<p>' . $row['sn']. '</p>'; // This subjects I need to display in a table with 2 columns..
    
           $catID = $row['ci'];
    
               echo '</div>';
    
           echo '</div>';
       }

     

    The problem I face is, when I am tring to add the subjects into a table..

     

    This is my HTML design..

     

    <div>
     <h3>Category 01: <span>Information Technology</span><span></span></h3>
     <div class="container">
    
       <table>
         <tr>
           <td width="50%">
               <input type="checkbox" value="1" name="category[]">Subject1
           </td>
           <td width="50%">
               <input type="checkbox" value="2" name="category[]">Subject4
           </td>
         </tr>                                    
         <tr>
           <td width="50%">
               <input type="checkbox" value="1" name="category[]">Subject2
           </td>
           <td width="50%">
               <input type="checkbox" value="2" name="category[]">Subject5
           </td>
         </tr>                                    
         <tr>
           <td width="50%">
               <input type="checkbox" value="1" name="category[]">Subject3
           </td>
           <td width="50%">
               <input type="checkbox" value="2" name="category[]">Subject6
           </td>
         </tr>                                                        
       </table>                        
     </div>
    </div>

  5. I am going to create a HTML form dynamically with php. Using that form users can select subjects under different category. A category and Its subjects have broken to one logical section and have applied jquery accordion. In my form I need to create more logical section like that.

     

    this is the HTML structure of the form..(which need to create dynamically with php)

     

    <form action="" method="post">
    <div id="accordion">
    <!-- logical section 1 -->
    <div>
    <h3>Category 01: <span>category name</span><span></span></h3>
    <div class="container">
    <table>
    <tr>
     <td width="50%">
    <input type="checkbox" value="1" name="subject[]">subject1
     </td>
     <td width="50%">
    <input type="checkbox" value="2" name="subject[]">subject2
     </td>
    </tr>		
    </table>											
    </div>
    </div>
    
    <!-- logical section 2 -->
    <div>
    <h3>Category 02: <span>category name</span><span></span></h3>
    <div class="container">
    <table>
    <tr>
     <td width="50%">
    <input type="checkbox" value="1" name="subject[]">subject1
     </td>
     <td width="50%">
    <input type="checkbox" value="2" name="subject[]">subject2
     </td>
    </tr>		
    </table>											
    </div>
    </div>
    </div>										
    </form>
    

     

     

     

    Can anybody tell my where I am going wrong? I troubled how to create inner table with 2 columns.

  6. hi.. everyone..

     

    This is a sql query problem that I have uncounted and have been in the same script for hours. But Still I couldn't get it to work.

     

    I need to get a image from database and its type should be one of a value from my $designation array. The query should check $designation array's value with database and if its match with one of a value in database then query can retrieve one row.

     

    This is my designation array. its value I use for image type in my db.

     

    $designation = array ( 'Managing Director', 'Manager', 'Director', 'The Principal', 'Deputy Principal', 'Proprietor', 'Assistant Manager', 'Head Master');
    

     

    My problem is how can I check these value exit in my table and how can I make a query for this. In query where condition is confusing to me...

     

    any comments are greatly appreciated.

    Thank you..

  7. Yes.. I used tutor_institute directory and sometimes used lanka_institute directory too for experiments porpose. when I use both directories I did it correctly in my htaccess and browser url. But still I couldn't it to get working. actually what has happend there... I followed more online tutorials to subject and all of them are fomfort for me. but I cant get it work in my project...

     

    any comments are greatly appreciated.

     

    Thank you..

  8. I change .htaccess file like this

     

    RewriteEngine on
    RewriteBase tutor_institute/profiles/tutors/
    RewriteUrl ^test.html index.php
    

     

    Create test.html file and placed it in tutors sub directory which is my index.php file exist.

     

    typed url in address bar, its like this

     

    http://localhost/lanka_institute/profiles/tutors/test.html
    

     

    Now I can get this massege in browser window.

     

    Internal Server Error

     

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

     

     

    page title display

     

    500 intenal server errors

     

     

    where I am going wrong????

     

    Thank you

  9. Actually I cant understand what I need to do with your answer. sorry for my little knowledge of the subject. Any way I change my .htaccess file like this

     

    RewriteEngine on
    RewriteBase tutor_institute/profiles/tutors/
    RewriteRule ^/profiles/tutors/([0-9]+)/([A-Za-z_]+)/([A-Za-z_]+)$ index.php?tutorCode=$1&tutorName=$2&city=$3 [NC]
    

     

    but nothing happen.. if you can elaborate your solution, It will help me understand the subjects.

     

    any comments are greatly appreciated.

     

    thank you.

  10. thanks for response...

     

    I am not going to redirect to another domain. sorry for my incomplete and unclear question. actually Im going to do is a dynamically generated url convert to frienly url.

     

    this is php generated url..

     

    http://localhost/tutor_institute/profiles/tutors/index.php?tutorCode=1255&tutorName=Jhon Amarathunga&city=Perth
    

     

    I need to rewrite it like this

     

    http://localhost/tutor_institute/profiles/tutors/1255/Perth/Jhon Amarathunga.html
    

     

    My index.php page dynamically generate more teacher's profile in my website. Thats why I need to rewrite that url to a friendly format.

     

    the path to my index.php file from the server's root directory is 'tutor_institute/profiles/tutors/index.php'

    tutor_institute,profiles and tutors are sub folders in my root directory.

     

    In my home page there are links to all tutor profiles generated by system. It link is something like this..

     

    echo '<h2><a href="profiles/tutors/index.php?tutorCode=' . $row3['tutor_code'] . '&tutorName=' . $row3['tutor_name'] . '&city=' . $row3['city_name'] . '">' . $row3['tutor_name'] . '</a></h2>';
    

     

    This is from my .htaccess file and I have placed .htaccess file in to 'tutors' sub directory which contain my index.php file.

     

    RewriteEngine on
    RewriteRule ^/profiles/tutors/([0-9]+)/([A-Za-z_]+)/([A-Za-z_]+)$ index.php?tutorCode=$1&tutorName=$2&city=$3 [NC]
    

     

     

    Thank you

  11. hello... everyone..

     

    I have some small problem. It is when Im fetch data from my database and print those in different location.

    I have a database to store images and it contain many type of images. Eg. gallery image, comments image, ad image and so on. So now I need to get only images which type is 'ad'.

     

    Note: A single user can store only 2 images as ad images. That mean there are two ad images to a particular user.

     

    It ok for me. I did it like this.

     

    $q = "SELECT image_name FROM images WHERE image_type = 'ad' AND user = $id";
    $r = mysqli_query( $dbc, $q );
    while ( $row = mysqli_fetch_array( $r, MYSQLI_ASSOC)) {
     $imageName = $row['image_name'];
     $imageName; // two images contain in this variable.
    }
    

     

    My problem is, can anybody say, is there a way to print those 2 images in different location (in different two DIV ) and out of while loop.

     

    Eg: <div class="add1"> image1 </div>

    <div class="add2"> image2 </div>

     

    any comments are highly appreciated.

    thank you.

  12. hi.. everyone..

     

    I need to rewrite this URL

     

    http://localhost/lanka_institute/profiles/tutors/index.php?tutorCode=1255&tutorName=Kasun%20Perera&city=Bandarawela
    

    like this

     

    http://www.mydomain.com/profiles/tutors/1255/Kasun+Perera.html
    

     

    I tried this with Apache’s mod_rewrite feature. But I couldn't reach to my expecting result.

     

    Here is Code that I have tried.

     

    <IfModule mod_rewrite.c>
    RewriteEngine on
    # For specific teachers:
    RewriteRule ^localhost/lanka_institute/profiles/tutors/([0-9]+)/([A-Za-z\+\-]+)/([A-Za-z\+\-]+)/$ index.php?tutorCode=$1&tutorName=$2&city=$3
    </IfModule>
    

     

    It is not working and then I can get this error message.

     

    Internal Server Error

     

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

     

     

    any comments are greatly appreciated.

     

    Thank you.

  13. Hello...

     

    I am some confuse with this matter. I want to print a order list with a title in php. those come from my database. Title is my category name and order list should be my subjects. I used 'institute_category_subject' table and i contain all institutes, categories and their subjects. something like this...

     

     

    I now need to create my list with these values. It is something like this..

     

    +--------+--------------+-------------+------------+
    | ics_id | institute_id | category_id | subject_id |
    +--------+--------------+-------------+------------+
    |	  1 |			1 |		   1 |		  2 |
    |	  2 |			1 |		   1 |		  4 |
    |	  3 |			1 |		   2 |		  2 |
    |	  4 |			1 |		   2 |		  3 |
    |	  5 |			1 |		   3 |		  1 |
    |	  6 |			1 |		   3 |		  4 |
    +--------+--------------+-------------+------------+
    

     

    category_name1

    • sub1
    • sub2
    • sub3

    category_name2

    • sub1
    • sub2
    • sub3 and so on....

    My problem is category id with same value going on many rows in the table and when i retrieve that id and when try to print, same category name printing repeatedly. I need to print my category name at only one time as my title and then need to print their subjects as a order list.

     

    any comments are highly appreciated.

     

    thank you..

  14. Thank you margaux... It working properly as I expect. But this code is hard to understand....

     

    if (preg_match('/group\d{1}$/', $name)) {
     $i = substr($name, -1);
     $groupVal = array(1=>'Individual', 'Small Groups &nbsp;<small>( Below 10 )</small>', 'Medium Groups &nbsp;<small>( Between 10 to 20 )</small>', 'Big Groups &nbsp;<small>( Over 20 )</small>', 'Online Tuition');
        // Display the error first:
        if (array_key_exists($name, $errors)) echo ' <span class="error">' . $errors[$name] . '</span>';
        echo '<input type="' . $type . '"  name="' . $name . '"  value="' . $i . '"  class="checkbox" />&nbsp; ' . $groupVal[$i] . '<br />';
        }
     }
    

     

     

    can you explain how it works.... and If I use select box in a form how can I display error massege like that.... further A select box display in the page with database values..

     

    any comments are highly appreciated....

     

    thank you..

  15. Hello...everyone...

     

    In my registration form I need to add some check boxes to select more than 1 option about teachers' class option. Larry's Effortless E-Commerce with PHP and MySQL book teach us how to use form input function for text, password and taxtarea inputs. So I modified the function for my check boxes. there I need to display a error message in my registration form when a user not select at least one option from the teacher option check boxes in my register page. further I need to display my error message above the check boxes as Larry did to textarea.

     

    I tried like this in my form function... but I can't get my error message... can anybody tell me where I have gone wrong????

     

    this code is my form function.

     

    } elseif ($type == 'checkbox') {
    
     if ( $name == 'option[]' ) {
      // Display the error first:
      if (array_key_exists($name, $errors)) echo ' <span class="error">' . $errors[$name] . '</span>';
      // Start creating the textarea:
      echo '<input type="' . $type . '"  name="' . $name . '"  value="1"  class="checkbox" />  Individual<br />';
      echo '<input type="' . $type . '"  name="' . $name . '"  value="2"  class="checkbox" />  Small Groups  <small>( Below 10 )</small><br />';
      echo '<input type="' . $type . '"  name="' . $name . '"  value="3"  class="checkbox" />  Medium Groups  <small>( Between 10 to 20 )</small><br />';
      echo '<input type="' . $type . '"  name="' . $name . '"  value="4"  class="checkbox" />  Big Groups  <small>( Over 20 )</small><br />';
      echo '<input type="' . $type . '"  name="' . $name . '"  value="5"  class="checkbox" />  Online Tuition<br />';
     }
     if ( $name == 'medium[]' ) {
      // Display the error first:
      if (array_key_exists($name, $errors)) echo ' <span class="error">' . $errors[$name] . '</span>';
      // Start creating the textarea:
      echo '<input type="' . $type . '"  name="' . $name . '"  value="1"  class="checkbox" />  Hindi<br />';
      echo '<input type="' . $type . '"  name="' . $name . '"  value="2"  class="checkbox" />  English<br />';
      echo '<input type="' . $type . '"  name="' . $name . '"  value="3"  class="checkbox" />  Tamil<br />';
     }  
    }// End of primary IF-ELSE.
    

     

     

    These are my register.php page

     

    // Check for Institute Options:
    if(empty( $_POST['option'])) {
    $reg_errors['option'] = 'Please select at least one tuition option';
    } else {
     $option = $_POST['option'];
    }
    // Check for Institute medium:
    if(empty( $_POST['medium'])) {
    $reg_errors['medium'] = 'Please select at least one tuition medium';
    } else {
     $medium = $_POST['medium'];
    }
    

     

     

    This is My HTML part in register page

     

       <div>
    	<label for="option">Tutoring Option <img src="../images/required_star.png" alt="required" /> : </label>
    	<div class="checkbox1">
    	 <?php create_form_input('option[]', 'checkbox', $reg_errors);?>
    	</div>
       </div>
       <div>
    	<label for="option">Tutoring Medium <img src="../images/required_star.png" alt="required" /> : </label>
    	<div class="checkbox1">
    	 <?php create_form_input('medium[]', 'checkbox', $reg_errors);?>
    	</div>
       </div>
    

     

     

    any helps are greatly appreciated...

     

    thank you..

×
×
  • Create New...