pranav88raval's Profile
Default
38
points

Questions
2

Answers
9

  • Default Asked on July 9, 2016 in Programming.

    For any website development first you need to be clear about the idea. What you are going to develop and what will it do?
    We all know once we make any software or web application then after we make more perfect and more user friendly and more effective
    in term of quality, design, code, speed.  But while you are thinking to create it first Just focus on the motive of the application. Concentrate
    about the functionalities. According to it follow the steps below.
    1) Decide the actual need and motive of  an application.
    2) Make a vision how your system will work once its completed.
    3) As per your functionality and maintenance go for appropriate framework.
    4) Before starting development complete some documentation like user Diagram, Data Dictionary, Process Flow Diagram, Relationship Diagram
    5) Complete Database schema, and numbers of tables, fields of these tables, Constraints.
    6) Choose a quality template which suits to your application.
    7) Complete core functionalities.
    8) Work out on designs.
    9) Test it completely on every aspects (w3c Validations, Broken links, Sql Injection prevention, data encryption).
    10) Speed up your application in terms of page load, data load, Query optimization.
    11) Code hierarchy, Code optimization, Code re usability.

    • 1348 views
    • 3 answers
    • 0 votes
  • Default Asked on July 9, 2016 in Database.

    existing table have primary key and you want to add new one?
    or existing table does not have and you wants to add new one;
    because a single table can have a single primary key.
    so more than one filed can not defined as primary key.

    • 1729 views
    • 2 answers
    • 0 votes
  • Default Asked on December 31, 2015 in Programming.

    your code have logical issue you have pushed three element in the array 1,2,3 while array index will count from 0 so its will make array like this 0=1, 1=2, 2=3 while you have looped from 0 to 3 so the number of time loops will continue is equal to 4 and your array have element upto 2 so while it will go for last round it will not found $a[3]’s value so

    Replace

    for($i=0;$i<4;$i++){

    Line of code with

    for($i=0;$i<3;$i++) { it will work fine.

    • 1072 views
    • 1 answers
    • 0 votes
  • Default Asked on December 28, 2015 in Programming.
    $(location).attr('href','http://yourPage.com/');
    • 1287 views
    • 2 answers
    • 0 votes
  • Default Asked on December 28, 2015 in Programming.
    <? php 
    
    //1 Day = 24*60*60 = 86400
    
    echo date("d-m-Y", time()+86400); 
    
    ?>
    • 1442 views
    • 1 answers
    • 0 votes
  • Default Asked on December 11, 2015 in Database.

    You basically have two options to achieve this:

    1. Using PDO (for any supported database driver):
      $stmt = $pdo->prepare('SELECT * FROM employees WHERE name = :name');
      
      $stmt->execute(array('name' => $name));
      
      foreach ($stmt as $row) {
          // do something with $row
      }
    2. Using MySQLi (for MySQL):
      $stmt = $dbConnection->prepare('SELECT * FROM employees WHERE name = ?');
      $stmt->bind_param('s', $name);
      
      $stmt->execute();
      
      $result = $stmt->get_result();
      while ($row = $result->fetch_assoc()) {
          // do something with $row
      }

    If you’re connecting to a database other than MySQL, there is a driver-specific second option that you can refer to (e.g. pg_prepare() and pg_execute() for PostgreSQL). PDO is the universal option.

    Correctly setting up the connection

    Note that when using PDO to access a MySQL database real prepared statements are not used by default. To fix this you have to disable the emulation of prepared statements. An example of creating a connection using PDO is:

    $dbConnection = new PDO('mysql:dbname=dbtest;host=127.0.0.1;charset=utf8', 'user', 'pass');
    
    $dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    $dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    In the above example the error mode isn’t strictly necessary, but it is advised to add it. This way the script will not stop with a Fatal Error when something goes wrong. And it gives the developer the chance to catch any error(s) which are thrown as PDOExceptions.

    What is mandatory however is the first setAttribute() line, which tells PDO to disable emulated prepared statements and use real prepared statements. This makes sure the statement and the values aren’t parsed by PHP before sending it to the MySQL server (giving a possible attacker no chance to inject malicious SQL).

    Although you can set the charset in the options of the constructor, it’s important to note that ‘older’ versions of PHP (< 5.3.6) silently ignored the charset parameter in the DSN.

    Explanation

    What happens is that the SQL statement you pass to prepare is parsed and compiled by the database server. By specifying parameters (either a ? or a named parameter like :name in the example above) you tell the database engine where you want to filter on. Then when you call execute, the prepared statement is combined with the parameter values you specify.

    The important thing here is that the parameter values are combined with the compiled statement, not an SQL string. SQL injection works by tricking the script into including malicious strings when it creates SQL to send to the database. So by sending the actual SQL separately from the parameters, you limit the risk of ending up with something you didn’t intend. Any parameters you send when using a prepared statement will just be treated as strings (although the database engine may do some optimization so parameters may end up as numbers too, of course). In the example above, if the $name variable contains 'Sarah'; DELETE FROM employees the result would simply be a search for the string "'Sarah'; DELETE FROM employees", and you will not end up with an empty table.

    Another benefit with using prepared statements is that if you execute the same statement many times in the same session it will only be parsed and compiled once, giving you some speed gains.

    Oh, and since you asked about how to do it for an insert, here’s an example (using PDO):

    $preparedStatement = $db->prepare('INSERT INTO table (column) VALUES (:column)');
    
    $preparedStatement->execute(array('column' => $unsafeValue));

    Can Prepared Statements Be Used For Dynamic Queries?

    While you can still use prepared statements for the query parameters, the structure of the dynamic query itself cannot be parametrized and certain query features cannot be parametrized.

    For these specific scenarios, the best thing to do is use a whitelist filter that restricts the possible values.

    // Value whitelist
      // $dir can only be 'DESC' or 'ASC'
    $dir = !empty($direction) ? 'DESC' : 'ASC'; 

    This answer accepted by Vandna Thakar. on December 17, 2015 Earned 15 points.

    • 1348 views
    • 1 answers
    • 0 votes
  • Default Asked on December 10, 2015 in Programming.
    <?php
    
    $query_date = '2010-02-04';
    
    // First day of the month.
    $f_day=explode('-', date('Y-m-01', strtotime($query_date)));
    // Last day of the month.
    $l_day=explode('-',date('Y-m-t', strtotime($query_date)));
    echo $f_day[2];
    echo "<br/>";
    echo $l_day[2];
    ?>
    
    • 1967 views
    • 2 answers
    • 0 votes
  • Default Asked on November 30, 2015 in Programming.

    <?php
    $curr_month=date(‘m’);
    $curr_year=date(‘m’);
    echo cal_days_in_month(CAL_GREGORIAN, $curr_month,$curr_year);
    ?>

    • 1341 views
    • 2 answers
    • 0 votes
  • Default Asked on November 27, 2015 in Programming.

    using this approach i have to go thtrough all the tab its not tooglingbetween two tab…

    • 1180 views
    • 2 answers
    • 0 votes