include.. but it doesn't!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vinnie

    include.. but it doesn't!

    this is my include file that i have uploaded on the server called
    DB_1.php

    <?php
    function connect()
    {
    // SERVER connection
    $con=mysql_conn ect('host', 'My_user_ID', 'My_Pwd');
    // DB selection
    $sql=mysql_sele ct_db('Database _name');
    }
    ?>

    when i point my browser to www.yyyyyy.com/insert_form.html and i
    submit the form, it recalls the follwing file:

    <?php
    include ("DB_1.php") ;
    // connect();
    $query_table="i nsert into table_name values('$_POST[nome]',
    '$_POST[cognome]','$_POST[indirizzo]', '$_POST[telefono]',
    '$_POST[cell]','$_POST[email]')";
    $insert=mysql_q uery($query_tab le) or die(mysql_error ());
    if (mysql_query($q uery_table, $con))
    {
    header ("Location: http://www.yyyyyy.com/thanks.html");
    exit;
    }
    else
    {
    echo '<br>something went wrong<br>';
    }
    ?>

    nothing happens, and no record are added to my database. Why? What
    should i change?

  • Spartacus

    #2
    Re: include.. but it doesn't!

    vinnie wrote:
    this is my include file that i have uploaded on the server called
    DB_1.php
    >
    <?php
    function connect()
    {
    // SERVER connection
    $con=mysql_conn ect('host', 'My_user_ID', 'My_Pwd');
    // DB selection
    $sql=mysql_sele ct_db('Database _name');
    }
    ?>
    >
    when i point my browser to www.yyyyyy.com/insert_form.html and i
    submit the form, it recalls the follwing file:
    >
    <?php
    include ("DB_1.php") ;
    // connect();
    $query_table="i nsert into table_name values('$_POST[nome]',
    '$_POST[cognome]','$_POST[indirizzo]', '$_POST[telefono]',
    '$_POST[cell]','$_POST[email]')";
    $insert=mysql_q uery($query_tab le) or die(mysql_error ());
    if (mysql_query($q uery_table, $con))
    {
    header ("Location: http://www.yyyyyy.com/thanks.html");
    exit;
    }
    else
    {
    echo '<br>something went wrong<br>';
    }
    ?>
    >
    nothing happens, and no record are added to my database. Why? What
    should i change?
    >
    Maybe the php.ini settings need to allow include files in the "current
    directory" or perhaps DB_1.php is not in the same directory as your script?

    Spartacus

    Comment

    • skeles

      #3
      Re: include.. but it doesn't!

      Your SQL query may be wrong. Try this one:

      $query_table="i nsert into table_name values('".$_POS T['nome']."',
      '".$_POST['cognome']."','".$_POS T['indirizzo']."', '".
      $_POST['telefono']."',
      '".$_POST['cell']."','".$_POS T['email']."')";

      Comment

      • Schraalhans Keukenmeester

        #4
        Re: include.. but it doesn't!

        At Wed, 13 Jun 2007 09:18:52 -0700, vinnie let h(is|er) monkeys type:
        this is my include file that i have uploaded on the server called
        DB_1.php
        >
        <?php
        function connect()
        {
        // SERVER connection
        $con=mysql_conn ect('host', 'My_user_ID', 'My_Pwd');
        // DB selection
        $sql=mysql_sele ct_db('Database _name');
        }
        ?>
        >
        when i point my browser to www.yyyyyy.com/insert_form.html and i
        submit the form, it recalls the follwing file:
        >
        <?php
        include ("DB_1.php") ;
        // connect();
        $query_table="i nsert into table_name values('$_POST[nome]',
        '$_POST[cognome]','$_POST[indirizzo]', '$_POST[telefono]',
        '$_POST[cell]','$_POST[email]')";
        $insert=mysql_q uery($query_tab le) or die(mysql_error ());
        if (mysql_query($q uery_table, $con))
        {
        header ("Location: http://www.yyyyyy.com/thanks.html");
        exit;
        }
        else
        {
        echo '<br>something went wrong<br>';
        }
        ?>
        >
        nothing happens, and no record are added to my database. Why? What
        should i change?
        You open the connection in a function, this makes $con a local variable to
        the function which goes out of scope as soon as the function ends. So your
        quesry isn't sent to the db.

        you could instead return $con from the function, call it like so:

        $conn = connect();

        and then execute your query.
        Note that you should _never_ trust POST userdata (nor GET for that
        matter); first validate it, sanitize it and only then put stuff into a db
        table.

        HTH

        --
        Schraalhans Keukenmeester - schraalhans@the .Spamtrapexampl e.nl
        [Remove the lowercase part of Spamtrap to send me a message]

        "strcmp('apples ','oranges') < 0"

        Comment

        • Jeff North

          #5
          Re: include.. but it doesn't!

          On Wed, 13 Jun 2007 09:18:52 -0700, in comp.lang.php vinnie
          <centro.gamma@g mail.com>
          <1181751532.086 784.293800@o11g 2000prd.googleg roups.comwrote:
          >| this is my include file that i have uploaded on the server called
          >| DB_1.php
          >|
          >| <?php
          >| function connect()
          >| {
          >| // SERVER connection
          >| $con=mysql_conn ect('host', 'My_user_ID', 'My_Pwd');
          >| // DB selection
          >| $sql=mysql_sele ct_db('Database _name');
          >| }
          >| ?>
          >|
          >| when i point my browser to www.yyyyyy.com/insert_form.html and i
          >| submit the form, it recalls the follwing file:
          Rename www.yyyyyy.com/insert_form.html to
          www.yyyyyy.com/insert_form.php then the web server will process your
          page. At present, because of the extension, the web server isn't
          looking at your file to see if it needs to anything with the files'
          contents.

          >| <?php
          >| include ("DB_1.php") ;
          >| // connect();
          >| $query_table="i nsert into table_name values('$_POST[nome]',
          >| '$_POST[cognome]','$_POST[indirizzo]', '$_POST[telefono]',
          >| '$_POST[cell]','$_POST[email]')";
          >| $insert=mysql_q uery($query_tab le) or die(mysql_error ());
          >| if (mysql_query($q uery_table, $con))
          >| {
          >| header ("Location: http://www.yyyyyy.com/thanks.html");
          >| exit;
          >| }
          >| else
          >| {
          >| echo '<br>something went wrong<br>';
          >| }
          >| ?>
          >|
          >| nothing happens, and no record are added to my database. Why? What
          >| should i change?
          ---------------------------------------------------------------
          jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
          ---------------------------------------------------------------

          Comment

          • Toby A Inkster

            #6
            Re: include.. but it doesn't!

            vinnie wrote:
            <?php
            function connect()
            {
            // SERVER connection
            $con=mysql_conn ect('host', 'My_user_ID', 'My_Pwd');
            // DB selection
            $sql=mysql_sele ct_db('Database _name');
            }
            ?>
            <?php
            function connect()
            {
            // SERVER connection
            $con=mysql_conn ect('host', 'My_user_ID', 'My_Pwd');
            // DB selection
            $sql=mysql_sele ct_db('Database _name');

            return $con;
            }
            $con = connect();
            ?>

            If you don't understand this, please read the PHP manual -- the part which
            explains what a function is and how they work. Read the bits on variable
            scope too.

            --
            Toby A Inkster BSc (Hons) ARCS
            [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
            [OS: Linux 2.6.12-12mdksmp, up 110 days, 20:10.]

            URLs in demiblog

            Comment

            • Willem Bogaerts

              #7
              Re: include.. but it doesn't!

              <?php
              include ("DB_1.php") ;
              // connect();
              $query_table="i nsert into table_name values('$_POST[nome]',
              Why is the call to the connect function commented out? If you do want
              the function to be called, remove the // at the start of that line.

              Best regards,
              --
              Willem Bogaerts

              Application smith
              Kratz B.V.

              Comment

              Working...