Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Don't input into database

    Hello,

    i got my slef a problem with my code with the databaste input. I got an random code generator that i want to send a code when you call on the address with an sms function i got on a site. But when i do that i just get the code back but it wont get into the database. But if i do it manualy and go the site the code gets to database so if someone can take a look at the code i would be glad.

    PHP Code:

    <?php
    $con 
    mysql_connect ("localhost","root","");
    if (!
    $con)
       {
       die(
    'Could not connect: ' mysql_error());
       }

    $code mt_rand();
    if (
    strlen($code) > 6)
    {
        
    $length strlen($code);
    $take $length 6;
    $finalcode substr($code$take);

    mysql_select_db("vip"$con);

    $pw="INSERT INTO pw (code)
    VALUES ('$finalcode')"
    ;

    if (!
    mysql_query($pw,$con))
        {
        die(
    'Error: ' mysql_error());
        }
     
    echo 
    "Din kod är $finalcode //Zobat";
    }

    mysql_close($con)
    ?>
    //zubat

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Are you getting any errors? Can you post your table structure?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Dec 2011
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by _Aerospace_Eng_ View Post
    Are you getting any errors? Can you post your table structure?
    No im not getting any errors and the table struture or the one i did use to execute it is

    PHP Code:
    CREATE TABLE pw
    (id INT NOT NULL AUTO_INCREMENT
    PRIMARY KEY(id),
     
    code VARCHAR(255), 
     
    datum date

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Change this
    PHP Code:
    $pw="INSERT INTO pw (code) 
    VALUES ('$finalcode')"


    if (!
    mysql_query($pw,$con)) 
        { 
        die(
    'Error: ' mysql_error()); 
        } 
    to this
    PHP Code:
    $pw="INSERT INTO pw (code) VALUES ('$finalcode')"
    $result mysql_query($pw,$con) or die('Error: ' mysql_error());
    echo 
    $pw.'<br>'
    Post the results.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New Coder
    Join Date
    Dec 2011
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Edit: I did solve the problem i just needed to move down the database input to the end of the code instead of shearing it up in diffrent peases over the code
    Last edited by zubat; 12-31-2011 at 11:25 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •