Jump to content

FraanXT

Members
  • Posts

    20
  • Joined

  • Last visited

Posts posted by FraanXT

  1. Hello guys, I have a form where you can select a score between 0 and 10(only integers).

    I want to check if the value that I recive, is integer.

     

    Im using this code(exemple):

    $integer =  intval($_POST["p1"]);
        if(is_int($integer)){
            echo 'INT';
        } else {
            echo 'NO INT';
        }
    

    My problem is that if it recive letters, the conversion converts it to 0, and it says that it is integer.

    So with this method I should discard the 0.

     

    You guys know a method to avoid that?

     

    Thank you guys

  2. Yep, I understand that. And I don't expect you would have figured out the error through that (reserved words usually catch everyone at least once in the beginning). But, when asking for help it's common courtesy to provide the errors (if you are getting them). In this case I could have told you what the problem was from the query you posted. But, it could have been any number of problems that could not be identified through the query alone.

     

    I will do as you say next time don't worry :), ty for help guys!

  3. How do you know there is an error? Did you check for an error from MySQL? If you had, I would have expected you would have provided it.

     

    FYI: I know what the problem is, but I'm going to make you work for it. Sorry, I believe in teaching someone to fish as opposed to just giving them one. So, please post the error you receive.

     

    I'm getting this mysql error:

    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 'Like INT,Score CHAR(30))' at line 1
    

    Tried some things but still getting the error TT, Im nubie in mysql :(

  4. Can you guys tell me where is the error please...

    $sql2= ('CREATE TABLE `'.$pub_unik.'` (ID SERIAL,ID_Use CHAR(30),Comment TEXT,Like INT,Score CHAR(30))');
    

    I can't find...

     

    Thank you guys

  5. Hello everybody,

     

    I want to obtain from the database the rows that have been inserted in the last seven days.

    Every time that I insert a row, I add a date with this format:

    $today = date("Y-m-d H:i:s");
    

    So it should be like:

    $lastweek = date("Y-m-((d)-7) H:i:s");
    
    SELECT * FROM pub WHERE data BETWEEN('$today' AND '$lastweek')
    

    Is it possible? which is the method to do that?

     

    Thank you all

  6. Hello everybody,

     

    I have a form like that:

    <form method="post" action="x.php">
    <input type="hidden" name="pubid" value="<?php echo $_SESSION["public_id"][$a]; ?>" />
    <input type="submit" name="update" />
    
    

    The public id is an id that every user have and that I use for get and post, imagine that this form is in a php "for" that print all this forms with public_id.

     

    Then I have a code like that:

    if(isset($_POST["update])){
     if($_POST["pubid"]!==(There are some checks to avoid mysql injection)){
      mysql_query=update from xxx set x=1 where pubid=$_POST["pubid"])(EXEMPLE)
    }}
    

    I want to avoid any change of form, because if someone change the value of the hidden input can modify information of mysql, someone know any method to do that?

    A friend told me to use js to compare form fields, but the user can modify js too I think, then I need to check it with php I think, correct me if Im wrong.

     

    Someone help me please.

  7. I can't find the error, someone help me please.

     

                    $conn = mysql_connect("localhost","root","Pass");
                    $err_db = mysql_select_db('bd_amics');
                    $sql = ("INSERT INTO `'".$_SESSION["use"][14]."'` (ID,Amic,PubID) VALUES ('".$_SESSION["person"][14]."', "1", '".$_SESSION["person"][15]."')");
                    mysql_query("SET NAMES utf8");
                    mysql_query($sql, $conn);
                    mysql_close();

     

                    $conn3 = mysql_connect("localhost","root","Pass");
                    $err_db3 = mysql_select_db('bd_amics');
                    $sql3 = ("UPDATE `'".$_SESSION["person"][14]."'` SET Amic="2" WHERE ID='".$_SESSION["use"][14]);
                    mysql_query("SET NAMES utf8");
                    mysql_query($sql3, $conn3);
                    mysql_close();

  8. rand(), mt_rand() and uniqid() produce very poor pseudo-random numbers derived from trivial factors like the server time and the process ID. With a bit of effort, it's in fact possible to predict the next value.

     

    If the IDs aren't secret, and if the traffic of your website is low, then those functions may still be good enough in your case. But if you want “real” random numbers, you must use the generator of your operating system. There are three ways to access it:

    • through openssl_random_pseudo_bytes() as mentioned by mac_gyver
    • through mcrypt_create_iv()
    • by reading directly from the system device (e. g. /dev/urandom)

    If you read 16 bytes from any of those interfaces, you don't have to worry about collisions. There won't be any.

     

    Thank you bro, helped me a lot.

  9. your database table(s) should continue to use the auto-increment id as a primary key. this id should be used for internal purposes, i.e. relating database tables to each other, identifying the user in a login session variable...

     

    if you need to have a random and unique id for external use, i.e. a remember-me cookie, a password reset token, a form/link consumable token,..., then generate a value using uniqid(), and store this for each visitor in addition to the auto-increment id.

     

    you can enforce unique values using the database table, by defining any database column storing the values as a unique key and checking if when storing the value if the query produced an error for a duplicate value.

    How uniqid() works? 

  10. Hello guys,

     

    I have a php page that inserts some data in a table, example: Name, email, password. Every line have an identificator(ID) that have autoincrement, so when I insert some data it generates the following number(exemple if last line have id 13, id 14 will be the next(as always).

     

    I want to continue using this method but without using this id type, I want to use random ids like 1234567890 and the next line 4324234234(exemple), but always a new and unique id, pretty simple.

     

    Would have to make it creating a random number, checking in table if it exists and then insert it? or I can make it with mysql or any fastest method?

     

    Sorry for my english, I don't know how to explain that.

     

    If someone can help me please.

  11. Im having problems with this line, i don't know where is the error, can you guys help me please?

     

    mysql_query('SELECT * FROM `users` WHERE CONCAT(Nom, CONCAT( " ", Cognoms)) like %'.$_POST["busca"].'%');
     
    I want to select from table users only the rows that contains $_POST["busca"] in columns Nom + " " + Cognoms.
     
    Help me please!
     
    Thank you all!
  12. Hey guys, this is my first post here(not going to be the last one, Im sure), im trying to insert in mysql from session array, i don't know where is my error, I leave the code below, if someone can help me please :).

     

                    $conn = mysql_connect("localhost","root","Password");

                    $err_db = mysql_select_db('bd_amics');

                    $sql = ('INSERT INTO `'.$_SESSION["use"][0].'` (ID,Amic) VALUES (`'.$_SESSION["person"][0].'`, `"1"`)');

                    mysql_query("SET NAMES utf8");

                    mysql_query($sql, $conn);

                    mysql_close();

     

    Im trying to insert in table $_SESSION["use"][0] the values $_SESSION["person"][0] and 1.

     

    Thank you guys.

     

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