Jump to content

Miss-Ruth

Members
  • Posts

    94
  • Joined

  • Last visited

    Never

Posts posted by Miss-Ruth

  1. Hi Ken, here is a module of my project.

     

    my_db1 example structure

    student  |  exama  |  examb  |  examc  | examd .... up to examh  |  Achieved

    Ruth        |      A+      |      C      |      C      |    A+  .... up to      C    |     

    Martin    |      A+    |      C      |      B      | examd .... up to      A    |

    Nathan  |      A+    |      A      |      C      | examd .... up to      C    |

    //40 students are in the db.

     

    my_db2 example structure

    semester  |  qualifieda  |  qualifiedb  |  qualifiedc  | qualifiedd .... up to qualifiedh

    semester1 |        A+      |        A        |        B        |        B        .... up to        A

    //end of db

     

    I want to update each row in Achieved with the COUNT of the matching results in exama, examb, examc etc...  of my_db1 against qualifieda, qualifiedb, qualifiedc, etc... in my_db2.

     

    In this example the Achieved column should fill as

    Achieved

            1

            3

            2

     

    Hope it makes sense.

     

    Thanks,

    Ruth.

  2. ok... I got it fixed to a certain extent. But my loop is not functioning. Could someone help in fixing this so it loops through all the rows.

     

    //loop through all rows in my_db

    $query=mysql_query("SELECT * FROM my_db");

    $rownum=mysql_num_rows($query);

    for($i=0;$i<$rownum;$i++)

    {

        $query=mysql_query("SELECT * FROM my_db LIMIT $i,1");

        while($scoreU=mysql_fetch_array($query))

        {

    foreach (range('a','h') as $ltr) {

    $ArrayNew[] = array($scoreU['roundzA' . $ltr]);

    }

    $count = array();

    for($i=0;$i<count($ArrayNew);++$i) {

    $count[$i] = count(array_intersect($ArrayNew[$i],$ArrayOld[$i]));

    }

    $count1 = array_sum($count);

    $My_points = $count1;

    $update=mysql_query("UPDATE my_db SET points='$My_points'");

        }

    }

  3. Killer1390 - Thanks for your input.

     

    kenrbnsn - Thanks. But below is my full script and I was trying to update each row with a different value.

    In that script I'm trying to:

    get data from two databases (sub_db and master_db)

    and match the data between the two databases

    then get the count of the matching data.

    (I managed to succeed up to this stage)

    now i want to match data on each row of a database against only the first row of the other database. (E.g. all rows of sub_db against master_db's first row)

    then update the column "the_points" for each row.

     

    <?php
    $conn = mysql_connect("localhost","un","pw");
    mysql_select_db("the_db");
    
    $ArrayUs1 = array();
    $ArrayMk1 = array();
    //master_db
    $query1 =  "SELECT * FROM master_db WHERE round_one = round_one";
    $result = mysql_query($query1);
    $scoreM = mysql_fetch_assoc($result);
    foreach (range('a','h') as $ltr) {
    $ArrayMk1[] = array($scoreM['my_win' . $ltr]);
    }
    
    //sub_db
    $query=mysql_query("SELECT * FROM sub_db");
    $rownum=mysql_num_rows($query);
    for($i=0;$i<$rownum;$i++)
    {
        $query=mysql_query("SELECT * FROM sub_db LIMIT $i,1");
        while($select=mysql_fetch_array($query))
        {
    $scoreU = mysql_fetch_assoc($select);
    foreach (range('a','h') as $ltr) {
    $ArrayUs1[] = array($scoreU['first_round' . $ltr]);
    }
    $count = array();
    for($i=0;$i<count($ArrayUs1);++$i) {
    $count[$i] = count(array_intersect($ArrayUs1[$i],$ArrayMk1[$i]));
    }
    $count1 = array_sum($count);
    $my_poins = $count1;
    $update=mysql_query("UPDATE sub_db SET the_points='$my_poins'");
        }
    }
    ?>

     

    I really appreciate your help.

    Thanks,

    Ruth \-)

  4. I'm trying to update each row in my table with $upoin. But doesn't. No errors shown but it dosen't update the database (table) with $upoin.

     

    $count1 = array_sum($count);
    $upoin = $count1;
    
    $query=mysql_query("SELECT * FROM table");
    $rownum=mysql_num_rows($query);
    for($i=0;$i<$rownum;$i++)
    {
        $query=mysql_query("SELECT * FROM table LIMIT $i,1");
        while($select=mysql_fetch_array($query))
        {
             $update=mysql_query("UPDATE table SET cat_num=$upoin");
        }
    }

     

    Help fix the code.

    Thanks,

    Ruth \-)

  5. That did not solve the problem. I believe the syntax is correct  :shrug:

     

    <?php
    $link = mysql_connect("localhost","un","pw");
    mysql_select_db("the_db");
    $data1 = $_POST['data1'];
    $data2 = $_POST['data2'];
    $data3 = $_POST['data3'];
    
    $result =sprintf("SELECT * FROM my_db1 WHERE username ='%s'", mysql_real_escape_string($data1));
    $resultf = mysql_query($result);
    
    if (mysql_num_rows ($resultf) > 0){
    $register = "Retry.";
    echo($register);
    } else {
    $go =sprintf("INSERT INTO my_db1 (surname, firstname, username) VALUES ('%s', '%s', '%s'", mysql_real_escape_string($data1), mysql_real_escape_string($data2), mysql_real_escape_string($data3);
    
    $go1 =sprintf("INSERT INTO my_db2 (surname, firstname) VALUES ('%s', '%s'", mysql_real_escape_string($data1), mysql_real_escape_string($data2));
    $resultg1 = mysql_query($go1);
    
    $go2 =sprintf("INSERT INTO my_db3 (surname, firstname) VALUES ('%s', '%s'", mysql_real_escape_string($data1), mysql_real_escape_string($data2));
    $resultg2 = mysql_query($go2);
    
    $go3 =sprintf("INSERT INTO my_db4 (surname, firstname) VALUES ('%s', '%s'", mysql_real_escape_string($data1), mysql_real_escape_string($data2));
    $resultg3 = mysql_query($go3);
    }
    ?>

     

    I appreciate any help.

     

    Thanks,

    Ruth.

  6. This looks perfect but for some reason it's not functioning. Could someone help fixing this.

     

    $resultF =sprintf("SELECT * FROM xy_db WHERE clubname ='%s'", mysql_real_escape_string($data3));
    $resultFin = mysql_query($resultF);
    
    if (mysql_num_rows ($resultf) > 0){
    $register = "Retry.";
    echo($register);
    } else {
    $go =sprintf("INSERT INTO ab_db (surnamez, firstnamez) VALUES ('%s', '%s'", mysql_real_escape_string($data1), mysql_real_escape_string($data2));
    $result = mysql_query($go);

     

    Thank you.

    Ruth. \-)

  7. How can I change Yes to No for the NULL field in the mysql db structure.

     

     

    E.g. (Table name: address and Column name : state)

    <?php
    $link = mysql_connect("localhost","db","pw");
    mysql_select_db("db");
    
    mysql_query("alter table address modify state null NO); 
    $result = mysql_query($query);
    $sent = "Edit Successful.";
    echo ($sent);
    ?>

  8. Ok. I'm using this to create a countdown timer. Could someone show me how this should be done or how can I get the time difference between $start_time and $end_time stop at 0.

     

    <?php
    $timezone =  new DateTimeZone('Africa/Gaborone');
    $date = new DateTime('now', $timezone);
    $start_time=strtotime($date->format('Y-m-d H:i:s'));
    $end_time=strtotime("2010-12-14 17:9:0");
    echo round(abs($start_time - $end_time));
    ?>

     

    Thanks,

    Ruth.

  9. As you see this outputs the time in seconds. I don't think that's the issue here. It' that this difference never ends. When it reach 0 it jumps into another value and start it all over again.

     

    Ruth.

  10. I'm curious.... This time difference never ends. it doesn't send 0. Is there a more efficient way in doing this or please could someone tell what's wrong here.

     

    <?php
    $timezone =  new DateTimeZone('Africa/Gaborone');
    $date = new DateTime('now', $timezone);
    $start_time=strtotime($date->format('Y-m-d H:i:s'));
    $end_time=strtotime("2010-12-14 17:9:0");
    echo round(abs($start_time - $end_time));
    ?>

     

    Thanks,

    Ruth.

  11. I need this script to go through each row of the mysql db and update the cat_num colum (for each record) with the new value. But this doen't seem to work. 

     

    $marks = '25'; // this value is ever changing. For this example I'll put as 25
    
    $query=mysql_query("SELECT * FROM table1");
    $rownum=mysql_num_rows($query);
    for($i=0;$i<$rownum;$i++)
    {
        $query=mysql_query("SELECT * FROM table1 LIMIT $i,1");
        while($select=mysql_fetch_array($query))
        {
             $update=mysql_query("UPDATE table2 SET cat_num='$select[cat_num]'+$marks");
        }
    }

  12. When I turn register_global is turned off (register_argc_argv is also set to off), this script won't work. How can I have register_globals turned off and make this work for me. Any help is highly appreciated.

     

     

    <?php
    $bd_me = mysql_bd_meect("localhost","db_me","pw_me");
    mysql_select_db("db_me");
    
    $query =sprintf("SELECT * FROM db WHERE unamename = '%s' AND stus = 'Banned'", mysql_real_escape_string($uname));
    $query_new = mysql_query($query);
    if(mysql_num_rows($query_new)) {
    $login = "Sorry.";
    echo($login);
    } else {
    
    $result=sprintf("SELECT * FROM  db WHERE unamename = '%s' AND password ='%s'", mysql_real_escape_string($uname), mysql_real_escape_string($password));
    $resultf = mysql_query($result);
    if(mysql_num_rows ($resultf) == 0) {
    $login = "Failed.";
    echo($login);
    } else {
    $row = mysql_fetch_array($result);
    $uname=$row['uname'];
    $password=$row['password'];
    $login = "$uname=" . $uname . "$password=" . $password . "Successful.";
    echo($login);
    }
    }
    ?>

     

    Is there any other settings that needs to be changed in the php.ini to make this code work while register_globals is turned off?

  13. Thanks that solved my problem.

     

    One more thing, I was asked to use these 3 functions along with perg_match to avoid email injection /Hijacking. Is that sufficient? I came across something called quote() function which is also useful to prevent hijacking. BUt I'm not sure how to use it.

     

    DB interface class exposes some sort of quote() function

     

    I appreciate if you could share your knowledge in preventing these type of attacks.

     

    Thanks,

    Ruth.

  14. $stripped = array('name', 'location', 'bio');
    
    foreach ( $_POST as $k => $v ) {
        if ( in_array($k, $stripped) ) {
            ${$k} = strip_tags($v);
            ${$k} = htmlentitiess($v);
            ${$k} = stripslashes($v);
        }
    }

     

    Thanks.

     

    I'm curious. Why is't it bocking the bold tags <b>? I can pass bold tags via this code! it's supposed to remove them. also I can pass \\ \n, \t, %0A...

  15. In the code I want to proceed to the next step only after stripslashes and strip_tags are completed. How do I put the code below with if?

     

    $stripped = array('name', 'location', 'bio');
    
    foreach ( $_POST as $k => $v ) {
        if ( in_array($k, $stripped) ) {
            ${$k} = strip_tags($v);
        }
    } 
    
    foreach ( $_POST as $p => $q ) {
        if ( in_array($p, $stripped) ) {
            ${$p} = stripslashes($q);
        }
    }

     

    Thanks,

    Ruth.

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