Loading ...
Sorry, an error occurred while loading the content.

Re: [phpXperts] Re: $_POST problem

Expand Messages
  • kevin myers
    actually its a script i am working on to mass populate a database with cards that i am selling using oscommerce. its funny how when you input the number in
    Message 1 of 6 , May 31, 2008
    • 0 Attachment
      actually its a script i am working on to mass populate a database with cards that i am selling using oscommerce.  its funny how when you input the number in the form and hit submit it works fine with the for loop. but once you input the data in the second form, the variables are not being sent.
      ----- Original Message -----
      From: nsbucky
      Sent: Saturday, May 31, 2008 10:59 PM
      Subject: [phpXperts] Re: $_POST problem

      ok I put this script into an editor just to sort it all out, but there
      are alot of problems with this script, $_POST problems being only a
      small part of it.

      First of all $_POST['startingnum ber'] isn't even being sent an
      integer, its just a string according to your form:

      <input type = "text" name = "startingnumber" value = "starting number" />

      Im thinking you would put a number in there, but Im just pointing out
      this in case you thought someone would hypothetically just put their
      own number in there. I have a feeling you didn't post an actual
      working script, can you just post the file that you have or email it
      to me and Ill just rewrite it for you so that it makes sense for you?

    • kevin myers
      i went and changed all the text inputs to int inputs and still nothing. the vars are being lost between the pages. i changed the ways its done this time.
      Message 2 of 6 , Jun 1, 2008
      • 0 Attachment
        i went and changed all the text inputs to int inputs and still nothing.  the vars are being lost between the pages. i changed the ways its done this time.
        //add.php
        <form action = "add2.php" method="post">
        <input type = "int" name = "startingnumber" value = "starting number" />
        <input type = "int" name = "endingnumber" value = "num cards in set" />
        <input type = "int" name = "cat" value = "set cat id" />
        <input type = "submit" name = "submit" value = "submit">
        </form>
        //add2.php
        <form action = "add3.php" method="POST">
        <?php
        define('STARTING', $_POST['startingnumber']);
        define("ENDING", $_POST['endingnumber']);
         
        for($X= $_POST['startingnumber']; $X<($_POST['startingnumber'] + $_POST['endingnumber']); $X++)
         {
         echo $X;
         echo "</br><input type = \"text\" name =\"cardname[$X]\" value = \"card name\">
        <textarea name = \"cardtext[$X]\" cols = \"25\" rows = \"6\" >card text</textarea>";
         print "hi</br></br></br>";
         }
        ?>
        <input type = "submit" name = "submit" value  = "submit" />
        </form>
        //add3.php
        <?php
        if(!$_POST['startingnumber'])
        {
        die("vars not being sent");
        }
        $connection = mysql_connect("localhost", "ravenslo_shaggy", "gh73x2") or die("no connection");
        mysql_select_db("ravenslo_store", $connection) or die("can't select db");
         //this is the place i add the code to add stuff to the database
         echo $_POST['startingnumber'];
         echo $_POST['endingnumber'];
         echo $startingnumber;
         echo STARTING;
         $cat = $_POST['cat'];
          for($y=$_POST['startingnumber']; $y<($_POST['startingnumber'] + $_POST['endingnumber']); $y++)
          {
          $card = $cardname[$x];
          $cardtext = addslashes($cardtext[$x]);
          mysql_query("INSERT INTO products VALUES($y, 0, 'single', '$card.jpg', '0.0000', '2008-01-12 13:13:50', NULL, NULL, '0.00', 1,0,0,0)") or die("messed up somewhere:" . mysql_errno()  . ":" . mysql_error());
          mysql_query("INSERT INTO products_description VALUES ($y, 1, '$card', '$cardtext', '', 0)") or die("messed up somewhere2:" . mysql_errno()  . ":" . mysql_error());
          mysql_query("INSERT INTO products_to_categories VALUES ($y, $cat)") or die("messed up somewhere3:" . mysql_errno()  . ":" . mysql_error());
          echo "hi!!";
          }
         echo "hi!";
        ?>
         
        add.php and add2.php work. but add3.php dies because the vars that i need are being sent over.
        ----- Original Message -----
        From: nsbucky
        Sent: Saturday, May 31, 2008 10:59 PM
        Subject: [phpXperts] Re: $_POST problem

        ok I put this script into an editor just to sort it all out, but there
        are alot of problems with this script, $_POST problems being only a
        small part of it.

        First of all $_POST['startingnum ber'] isn't even being sent an
        integer, its just a string according to your form:

        <input type = "text" name = "startingnumber" value = "starting number" />

        Im thinking you would put a number in there, but Im just pointing out
        this in case you thought someone would hypothetically just put their
        own number in there. I have a feeling you didn't post an actual
        working script, can you just post the file that you have or email it
        to me and Ill just rewrite it for you so that it makes sense for you?

      • nsbucky
        Well the reason the int inputs do not work is because there is no such thing. It should stay text or hidden. The problem is the values you are putting in, they
        Message 3 of 6 , Jun 1, 2008
        • 0 Attachment
          Well the reason the int inputs do not work is because there is no such
          thing. It should stay text or hidden. The problem is the values you
          are putting in, they are not integers:

          <input type='hidden' value='1' name='somename' >

          The problems in your script originate from poor html and not
          understanding PHP, but I would like to try and help you. Please email
          me your original script: nsbucky@...
        • Kristiono Setyadi
          First, try to put one line of code in top of this page:
          Message 4 of 6 , Jun 2, 2008
          • 0 Attachment
            First, try to put one line of code in top of this page:

            <?php
            session_start();

            make sure there is no space between <?php and session_start();

            I think you have already check it because you said that
            your code run perfectly in the first chance.

            Second, try to be consistent with your code. I see the
            conditional statement,

            if (!submit)

            still using the old method. Try using the new method as
            PHP5 have its register globals set to off. Try the
            $_POST['submit'] or $_GET['submit'] or $_REQUEST['submit']
            to easily read your code (and of course, trace the error).
            Do this to all of your global variables.

            Third, you have using define() in the middle of your code.
            As far as I know, define is use only for variables that CAN
            NOT BE CHANGED after first initialization. We often call it
            CONSTANT. So, change your code to something flexible if you
            mean STARTING and ENDING act as variables, not constant.

            Hope it helps ;)



            Kristiono Setyadi



            Web and .NET Programmer

            CitraWeb Nusa Infomedia

            http://www.citra.web.id



            http://ksetyadi.blogs.friendster.com/kristiono_setyadi_catatan/

            --- On Sat, 5/31/08, shaggy2dope2126 <shaggy2dope2125@...> wrote:
            From: shaggy2dope2126 <shaggy2dope2125@...>
            Subject: [phpXperts] $_POST problem
            To: phpexperts@yahoogroups.com
            Date: Saturday, May 31, 2008, 8:57 PM











            heres the problem. the first set of code runs perfect. the second

            hunk of code doesn't run. the only thing that happens is that the "hi"

            message at the very end is printed. i have tried putting the vars.

            into hidden fields and that didn't work. it seems as though they are

            not being sent over to be used by the for loop. anyone got any ideas?



            if(!$submit)

            {

            ?>

            <form action = "<?php php_self; ?>" method="post" >

            <input type = "text" name = "startingnumber" value = "starting number" />

            <input type = "text" name = "endingnumber" value = "num cards in set" />

            <input type = "text" name = "cat" value = "set cat id" />

            <input type = "submit" name = "submit" value = "submit">

            </form>

            <?php

            }

            else

            {

            ?>

            <form action = "add.php">

            <?php

            define('STARTING' , $_POST['startingnum ber']);

            define("ENDING" , $_POST['endingnumbe r']);



            for($X= $_POST['startingnum ber']; $X<($_POST[' startingnumber' ] +

            $_POST['endingnumbe r']); $X++)

            {

            echo $X;

            echo "<input type = \"text\" name =\"cardname[ $X]\" value = \"card

            name\">

            <textarea name = \"cardtext[$ X]\" cols = \"25\" rows = \"6\" >card

            text</textarea> ";

            print "hi</br></br> </br>";

            }

            ?>

            <input type = "hidden" name = "startingnumber" value = "<?php

            $_POST['startingnum ber']; ?>" />

            <input type = "submit" name = "submit" value = "submit" />

            </form>

            <?php

            }

            echo $_POST['startingnum ber'];

            echo $_POST['endingnumbe r'];

            ?>



            if(!$startingnumber )

            {

            die("vars not being sent");

            }

            //db code

            //this is the place i add the code to add stuff to the database

            echo $_POST['startingnum ber'];

            echo $_POST['endingnumbe r'];

            echo $startingnumber;

            echo STARTING;

            $cat = $_POST['cat' ];

            for($y=$_POST[ 'startingnumber' ]; $y<($_POST[' startingnumber' ] +

            $_POST['endingnumbe r']); $y++)

            {

            $card = $cardname[$x] ;

            $cardtext = addslashes($ cardtext[ $x]);

            mysql_query( "INSERT INTO products VALUES($y, 0, 'single',

            '$card.jpg', '0.0000', '2008-01-12 13:13:50', NULL, NULL, '0.00',

            1,0,0,0)") or die("Fucked up somewhere:" . mysql_errno( ) . ":" .

            mysql_error( ));

            mysql_query( "INSERT INTO products_descriptio n VALUES ($y, 1,

            '$card', '$cardtext', '', 0)") or die("Fucked up somewhere2:" .

            mysql_errno( ) . ":" . mysql_error( ));

            mysql_query( "INSERT INTO products_to_ categories VALUES ($y, $cat)")

            or die("fucked up somewhere3:" . mysql_errno( ) . ":" . mysql_error( ));

            echo "hi!!";

            }

            echo "hi!";

            ?>
          Your message has been successfully submitted and would be delivered to recipients shortly.