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 3 of 3

Thread: PHP script

  1. #1
    New to the CF scene
    Join Date
    Jul 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP script

    Hi how are you? I try to run this script but it isn't working. After entering dates, it should only come up "Thank you for fill out" Not (texts ex name country and so on)

    And I would like to make a link to Home.

    My php editor says "Undefined variable: rets in c:\itohideo\kkk.php on line 27"


    Here is my code

    <html>
    <body>
    <?php
    $con = mysql_connect("localhost","itohideo","1234");
    if(!$con) {
    print("Fail DB Connection<br>\n");
    exit;
    }
    if(!mysql_select_db("itohideo")) {
    print("Fail DB Selection<br>\n");
    exit;
    }
    if (isset($_POST["submit"])){
    $number = $_POST["number"];
    $name = $_POST["name"];
    $country = $_POST["country"];
    $query_insert = "insert into takao (number, name, country) values ('$number', '$name', '$country')";
    $query_result_insert = mysql_query($query_insert, $con) or die (mysql_error($con));
    if(mysql_insert_id()){
    $rets = "Thank you for filling out my form";
    }
    mysql_close($con);
    }
    ?>

    <?
    if($rets){
    echo $rets;
    ?>
    <?}else{?>
    <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
    <P>please fill out this form and it goes to my database</P>
    Number<input name="number" type="text"><br>
    Name<input name="name" type="text"><br>
    You country<input name="country" type="text"><br>
    <input type="submit" name="submit">
    <input type="reset" name="reset">
    </form>
    <?}?>
    </body>
    </html>

  • #2
    New Coder
    Join Date
    Aug 2002
    Location
    Henderson, NV
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Unfortunately I can't provide you a direct answer, but there might be a couple issues to take a peek at.

    First: In prociessing your result inquiry, it isn't necessary for you to reconnect to the database, you only need one connection per page, unless you're doing some crazy stuff. Try omitting the $con part of the statement.

    Second: Sometimes the results of a query are deceptive. Testing for a simple mysql_insert_id might be providing deceptive results. For a few tries, try printing out the mysql_error() to see what results you're actually getting. I had a recent project where I was formatting my e-mai addresses wrong and still getting a successful result.

    Hope this helps
    Peace out homeskillets!!!

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can't find any obvious errors in your code. The error message points to the mysql_insert_id() functions, because it returns false, the variable $rets does not get set and PHP complains about that at a later stage.

    Was your insert actually successful? Also, does your mysql table "takao" have an AUTO_INCREMENT column specified correctly?


  •  

    Posting Permissions

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