Jump to content

Digitizer

Members
  • Posts

    46
  • Joined

  • Last visited

Posts posted by Digitizer

  1. 1 - do you have error checking turned on?

    2 - the bindvalue function returns a result.  Did you bother to check that it ran ok?  No.

    3 - the manual gives you the proper syntax for this function.  Read it.

     

    Thanks for reply my friend,

     

    1. 

    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // is set as error check
    

    2. If I run delete.php?delete=3 //for example, in browser directly, the script runs fine and deletes the corresponding row from table

    3. I have not read the manual yet though

  2. Hello guys,

    I have been away for a couple of days. Its nice to be back :)

     

    Yesterday night I was practicing an AJAX/PHP delete tutorial and file "delete.php" was wrtiten in mysql* which I converted to PDO but it didnt seem to work after conversion. The three bits of code are as follows

    //I got the results using PDO::FETCH_ASSOC in following div getting ID of row in link
    while ($r = $getData->fetch(PDO::FETCH_ASSOC)){
      echo ("
         <div class='record' id='record-".$r['id']."'>
           <a href='?delete=".$r['id']."' class='delete'>[x]</a>
         </div> 
      ");
    } 
    $(document).ready(function() {
    	$('a.delete').click(function(e) {
    		e.preventDefault();
    		var parent = $(this).parent();
    		$.ajax({
    			type: 'get',
    			url: 'delete.php',
    			data: 'ajax=1&delete=' + parent.attr('id').replace('record-',''),
    			beforeSend: function() {
    				parent.animate({'backgroundColor':'#fb6c6c'},300);
    				},
    			success: function() {
    				parent.slideUp(300,function() {
    					parent.remove();
    				});
    			}
    		});
    	});
    }); 

    and delete.php contains

     include "inc.connect.php";
     if(isset($_GET['delete'])){
       $id = $_GET['delete'];
       $query = "DELETE FROM tempdata WHERE id=?";
       $runThis = $db->prepare($query);
       $runThis->bindValue(1,$id);
       $runThis->execute();
     } 
    
    /*The problem I am facing is in delete.php. because If i run the same script in mysql_*,
    it works, which is as follows first (I had to write connect in mysql as
    original connection is written in PDO)
    ------------------------------------------------------
    
    $con = mysql_connect('localhost','munni****','*******');
    mysql_select_db('stockcontrol',$con);
    
    if(isset($_GET['delete'])) {
      $result = mysql_query('DELETE FROM tempdata WHERE id = '.(int)$_GET['delete'],$con);
    }
    mysql_close($con); */
    
    
  3. Hello,

    sorry for late reply, I have been busy yesterday.

     

    Well, as you pointed out, the checksum actually changed from LTR/RTL ... didnt notice.. lolz..

     

    As luhn Algo says, After all the adittion/multiplication etc, you will come up with 2 digits which you will need to either,

     

    1. Multiple by 9 (it will always give you 3 digits - and last digit is checksum) (e-g 45, 45*9 = 405, [5 is checksum])

    2. From those 2 digits, subtract the last from 10 and you will be left with 1 digit, which is check sum. (e-g 45, [10-5],[5 is checksum])

     

    I used the first logic. And with your writen algo, I am going to try this too :)

     

    Lemme get back to you on this mate

  4. Thanks for the tip @Jacques1, I am now going to try this as well, Its not about what the logic is about, what i am trying to do is to get the solution as simple way as possible.

     

    So I am going to try with different logics making it as short as possible, so I have completed first solution, as follows,

    if(isset($_POST['submitIMEI'])){
    	$imei = $_POST['imei'];
    	$odd = $even = array();
    	$arr = str_split($imei);
    	$oddFinal = array(); // Will hold addition of odd indexed numbers
    
    	foreach ($arr as $k => $v) {if ($k%2) {$odd[] = $v*2;}else {$even[] = $v;}}
    
    	// Add all 2 Numbered digits to make them 1 digit
    	foreach($odd as $sepNo){
    		$first = substr($sepNo,0,1);
    		$second = substr($sepNo,1,1);
    		$total = $first+$second;
    		$oddFinal[] = $total;
    	}
    	$oddSum = array_sum($oddFinal);
    	$evenSum = array_sum($even);
    	$totalAll = $oddSum+$evenSum;
    	$totalFinal = $totalAll*9;
    	$imeiSV = substr($totalFinal,2,1);
    	
    	echo "IMEI: " . $imei . "<br>";
    	echo "ChkSum: " . $imeiSV . "<hr>";
    }
    
    echo ("
    	<form name='imei' method='post' action='#'>
    		<input type='text' name='imei' placeholder='IMEI' />
    		<input type='submit' name='submitIMEI' />
    	</form>
    ");
    
    

    I understand the style of writing may be very non professional, if it is so, I humbly request to please point out the mistakes I have done, this will be a great help for me to get me better on writing.

  5. ok, I cannot edit the post now, so this is a little solution I have come up with, getting the alternate numbers into another array using modulus.

    $imei = "356565451265856";
    $lenOfString = strlen($imei);
    $myArray = array();
    $alternateArray = array();
    for($i=0;$i<$lenOfString;$i++){
    	$myArray[] = substr($imei,$i,1);
    }
    foreach($myArray as $key => $value){
    	
      if($key % 2 == 0){
      $alternateArray[] = $value;
      }
    }
    
    
    print_r($alternateArray); //Array will get 36641686
    
    

    So if there was a more convinient solution? if I can get such numbers from $imei directly??

  6. Hello Guys,

    You  might have known about Luhn Algorithm, which is used to get checksum of IMEI of phones, credit cards etc etc. It is a public domain so it is not used for security but to ensure that client has passed the correct numbers etc etc.

     

    Anyway, I am trying to get my hands on this algorithm and I will build a logic based on luhn algo to get the checksum, where I am stuck is how can I get the alternate numbers from a numeric string, for example I have written the following code to get all the numbers one by one into the array.

    $imei = "356565451265856";
    $lenOfStr= strlen($imei);
    $myArray = array();
    
    //Get all numbers one by one in array
    for($i=0; $i < $lenOfStr; $i++){
      $myArray[] = substr($imei,$i,1);
    }
    
    // Checking the array
    foreach($myArray as $seperatedNumbers){
      echo $seperatedNumbers;
    }
    

    No the problem is that I want to select every 2nd number from right to left e-g 5,5,2,... or 6,8,6

    How can I get it done?

     

    This logic may not be so good, there may be more brilliant solutions to write luhn algo, but I want to try myself once... 

     

    Thanks.

  7. I didnt get this error, I tried this on my page and it works without errors

    $rules_column1 = array(
    "No prop pushing, or prop killing",
    "No building in the Skybox",
    "No prop spamming",
    "No thruster or turret noises"
    );
    
    foreach($rules_column1 as $rule){
    	echo $rule . "<br>";
    }
    
    /*
    The Result was
    No prop pushing, or prop killing
    No building in the Skybox
    No prop spamming
    No thruster or turret noises
    */
    
    

    It should have told you which line of code is generating error, note if it is the same line where "No Pro..." exists or is it where you are getting values with a loop?

  8. I once wrote a login script, and put some modules to be displayed to authorized users only, I used cookies though, but to authorize specific users to those certain modules, (giving more control over app) I used another logic without using any OOP approach at all.. The logic was assigning a groupName to each user, "Standard" when user registers which can be changed by superAdmin (hardcoded in program) The pseudo logic I can write here, I know it was a bad practice 

    // All this is just a hinting code, not proper code
    
    get_login_details ($username,$password);
    $query = mysql_query(select * from userTable where username='$username' AND password='$password');
    
    // if a row is returned
    if(mysql_num_rows($query) == 1){
      set_cookie_thing
      $row = mysql_fetch_array($query);
      $group = $row['group'];
      if($group == 'admin'){$isAdmin = true;}else{$isAdmin = false;}
    } else {
       die("The username or password is incorrect");
    }
    
    if(isset($isAdmin)){// display the modules or whatever you want}
    

    I had issues at times with this code so dont use such logics, it is just as idea to get  you going and may come up with a better idea

  9. I thought to relax a bit and while i saw something and an idea came to my mind, lets play noobs, it will be fun... we ask noob questions here lolzzz

     

    so my question is 

     

    Hello,

    I have seen that there are always 3 users /* I know these are bots */ Google, Yahoo and Bing always online and we cannot see their profiles. They must be very professional hackers who have known how to hide their identities.. right??  :pirate:

  10. I love to be with guys like you here :D

     

    I am cleared now, as @Jacques1 said, why give up knowledge of PHP I already have and Java wont improve my coding skills anyway...

     

    So yeah, I am gonna stick with PHP, I am gonna learn PDO, now, actually have started it last night, and I am gonna be good at it... 

     

    About being hesitant, well, I have some traces of being treated bad, left in my mind from StakOverFlow, they are bad guys lemme tell u that. So sometime before asking something, i think twice that people are not going to bully me because I opened up... u know...!

     

    Once a professor from a well known high repute college told me, Muneeb, We dont take coal and turn them into diamonds, we take diamonds and we polish them.

     

    I think he was wrong, diamond was once coal and went through extreme pressure to become what it is now and people want to polish it. The real skill lies in turning a coal to a diamond. :)

  11. that is something to do with xampp configuration i guess

     

    Make sure your file has the .php extension on it, otherwise it will not be executed as PHP.

     

    Make sure that the PHP module is listed and uncommented inside of your Apache's httpd.conf This should be something like LoadModule php5_module "c:/php/php5apache2_2.dll" in the file. Search for LoadModule php, and make sure that there is no comment (;) in front of it.
     
    Make sure that the http.conf file has the PHP MIME type in it. This should be something like AddType application/x-httpd-php .php. This tells Apache to run .php files as PHP. Search for AddType, and then make sure there is an entry for PHP, and that it is uncommented.
  12. @ginerjm: Thanks a lot my friend. Your post in real became something i cant just explain... I will do PDO, and I will do it fast and I will do it organized... and when I step up in proficiency levels,  the credit will go to you :)

    try{
       $db = new PDO("mysql:host=localhost;dbname=thanksginerjm;charset=utf8", 'itsMe','mypass');
       $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    } catch(PDOException $exp){print $exp;}
    
    
    $name = 'ginerjm';
    $msg = 'Thanks Man';
    
    // Send thanks
    $getData = $db->exec("INSERT INTO thethanks(name,msg) VALUES ('$name','$msg')");
    
    // Receive Thanks
    
    $getData = $db->query("SELECT * FROM thethanks");
    echo $countRows = $getData->rowCount();
    foreach($getData as $row){
       echo "Received by" . $row['name'] . ": " . $row['msg'];
    }
    

    This is dedicated to you, my first ever code after a basic practice

  13. and for a more simple version of WebOutGateway for you is here

    nav li {
        display:inline-block;
        margin: 0 -2px 0 0;
        border-right: 1px solid #ccc;
     }
       #nav li a
     {
          display: block;
          padding: 8px 15px;
          text-decoration: none;
          font-weight: bold;
          color: #069;
          }
    
  14. You need to wrap it in a span with a label

     

    define a css style in your page, and paste the following code (not my code, searched on internet for it)

    <style type="text/css">
    label.browseButton{
        overflow:hidden;
        position:relative;
        width:100px;
        height:30px;
        background: url('path_of_image.extension') center center no-repeat;
        /* change the path of image with "path_of_image.extension" */
        /* center center no-repeat are optional */
    }
    
    label span input{
        z-index: 1000;
        line-height: 0;
        font-size: 50px;
        position: absolute;
        top: -2px;
        left: -700px;
        opacity: 0;
        filter: alpha(opacity = 0);
        -ms-filter: "alpha(opacity=0)";
        cursor: pointer;
        _cursor: hand;
        margin: 0;
        padding:0;
    }
    </style>
    

    and change your file button code like this

    <label class="browseButton">
        Browse File
        <span>
          <input type="file" id="file" name="file" />
        </span>
    </label>
    
×
×
  • 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.