undefined index

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lucylew
    New Member
    • Sep 2007
    • 6

    undefined index

    ive got a box i want to click which will add the product to the basket but i keep gettin the undefined index error

    [CODE=php]
    <?include("conn info.php")?>
    <?session_start ();?>
    <html>
    <head>
    <title>Products </title>
    </head>
    <link rel="stylesheet " type="text/css" href="style.css "/>
    <body background="htt p://i145.photobucke t.com/albums/r224/lucy_lew/backgroundandlo go.jpg" border="0" alt="background img">
    <h1>
    <a href="login.php ">Home</a>&nbsp;&nbsp;
    <a href="search.ph p">Search</a>&nbsp;&nbsp;
    <a href="products. php">Products</a>&nbsp;&nbsp;
    <a href="basket.ph p">Shopping Basket</a>&nbsp;&nbsp;
    <a href="register. php">Register New User</a>
    </h1>

    </div>
    <div id="container" >
    <div id="left_conten t">
    <div id = "left_text" >
    <?
    $query="select * FROM products ";
    $result=mysql_q uery($query) or die("Couldnt do it");?>
    <?$numrows=mysq l_num_rows($res ult);
    if ($numrows>0)
    {?>
    <table border="1">
    <?
    while($r=mysql_ fetch_array($re sult))
    {?>
    <form action="basket. php" method="post">
    <td><?echo $r["price"];?></td>
    <td><?echo $r["productnam e"];?></td>
    <td><img src="images/<?echo $r["productima ge"];?>" alt="Image"></td>
    <td><input type="submit" value="Add to Basket"><td/>
    </form>

    </td>
    </tr>
    <?
    }
    ?>
    </table>

    <?}
    else
    {
    echo("Nothing Found.");
    }


    [/CODE]
    [code=php]
    <?include("conn info.php");?>
    <?session_start ();?>
    <html>
    <link rel="stylesheet " type="text/css" href="style.css "/>
    <body background="htt p://i145.photobucke t.com/albums/r224/lucy_lew/backgroundandlo go.jpg" border="0" alt="background img">
    <h1>
    <a href="login.php ">Home</a>&nbsp;&nbsp;
    <a href="search.ph p">Search</a>&nbsp;&nbsp;
    <a href="products. php">Products</a>&nbsp;&nbsp;
    <a href="basket.ph p">Shopping Basket</a>&nbsp;&nbsp;
    <a href="register. php">Register New User</a>
    </h1>

    <?
    $productid=$_PO ST["productid"];
    $price=$_POST["price"];
    $productname=$_ POST["productnam e"];

    $query = "INSERT INTO basket(producti d, price,productna me)
    VALUES'$product id','$price','$ productname'" or die("Couldn't") ;
    $result=mysql_q uery($query);
    ?>
    Go to Basket:
    <a href="showbaske t.php">Go to Basket</a>
    </html>




    [/CODE]
    Last edited by ak1dnar; Sep 3 '07, 01:19 PM. Reason: Added the CODE=php Tags
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    Welcome to theScripts.com

    Could you please post the entire error message here, because It will help to find out the errors easily as it is saying well, where the problem occurred, rather than your post.

    Comment

    • Lucylew
      New Member
      • Sep 2007
      • 6

      #3
      [PHP]
      <?include("conn info.php")?>
      <?session_start ();?>
      <html>
      <head>
      <title>Products </title>
      </head>
      <link rel="stylesheet " type="text/css" href="style.css "/>
      <body background="htt p://i145.photobucke t.com/albums/r224/lucy_lew/backgroundandlo go.jpg" border="0" alt="background img">
      <h1>
      <a href="login.php ">Home</a>&nbsp;&nbsp;
      <a href="search.ph p">Search</a>&nbsp;&nbsp;
      <a href="products. php">Products</a>&nbsp;&nbsp;
      <a href="basket.ph p">Shopping Basket</a>&nbsp;&nbsp;
      <a href="register. php">Register New User</a>
      </h1>

      </div>
      <div id="container" >
      <div id="left_conten t">
      <div id = "left_text" >
      <?
      $query="select * FROM products ";
      $result=mysql_q uery($query) or die("Couldnt do it");?>
      <?$numrows=mysq l_num_rows($res ult);
      if ($numrows>0)
      {?>
      <table border="1">
      <?
      while($r=mysql_ fetch_array($re sult))
      {?>
      <form action="basket. php" method="post">
      <td><?echo $r["productid"];?></td>
      <td><?echo $r["price"];?></td>
      <td><?echo $r["productnam e"];?></td>
      <td><img src="images/<?echo $r["productima ge"];?>" alt="Image"></td>
      <input type="hidden" name="productid " <?echo $r['productid'];?>>
      <input type="hidden" name="price" <?echo $r['price'];?>>
      <input type="hidden" name="productna me" <?echo $r['productname'];?>>
      <td><input type="submit" value="Add to Basket">
      <td/>
      </form>

      </td>
      </tr>
      <?
      }
      ?>
      </table>

      <?}
      else
      {
      echo("Nothing Found.");
      }
      [/PHP]
      [PHP]
      <?include("conn info.php");?>
      <?session_start ();?>
      <html>
      <link rel="stylesheet " type="text/css" href="style.css "/>
      <body background="htt p://i145.photobucke t.com/albums/r224/lucy_lew/backgroundandlo go.jpg" border="0" alt="background img">
      <h1>
      <a href="login.php ">Home</a>&nbsp;&nbsp;
      <a href="search.ph p">Search</a>&nbsp;&nbsp;
      <a href="products. php">Products</a>&nbsp;&nbsp;
      <a href="basket.ph p">Shopping Basket</a>&nbsp;&nbsp;
      <a href="register. php">Register New User</a>
      </h1>

      <?
      $productid=$_PO ST["productid"];
      $price=$_POST["price"];
      $productname=$_ POST["productnam e"];

      $query = mysql_query("IN SERT INTO basket(producti d,price,product name)
      VALUES('$produc tid','$price',' $productname')" )or die("Couldn't") ;

      ?>
      Go to Basket:
      <a href="showbaske t.php">Click here</a>
      </html>
      [/PHP]

      Comment

      • ak1dnar
        Recognized Expert Top Contributor
        • Jan 2007
        • 1584

        #4
        you should always initialize your variables before use, That is the meaning of your eror, Do you have any undefined variable.? Its there on the Line number of your Error report.

        Comment

        • Lucylew
          New Member
          • Sep 2007
          • 6

          #5
          the error says that these lines are unfined:
          [CODE=php]
          $productid=$_PO ST["productid"];
          $price=$_POST["price"];
          $productname=$_ POST["productnam e"];
          [/code]
          could u please tell me how to resolve this error coz ive tryed loads of things but just cant find wat it is
          Last edited by ak1dnar; Sep 4 '07, 05:09 AM. Reason: There was error with the text editor

          Comment

          • ak1dnar
            Recognized Expert Top Contributor
            • Jan 2007
            • 1584

            #6
            Hi there,
            when you sending the hidden form fields, there is no value with them.Try to send them too
            This will work for you.

            [CODE=php]
            <input type="hidden" name="productid " value="<?Php echo $r['productid'];?>"/>
            <input type="hidden" name="price" value="<?Php echo $r['price'];?>"/>
            <input type="hidden" name="productna me" value="<?Php echo $r['productname'];?>"/>
            [/CODE]

            Post back with your updates. Thanks :)

            Comment

            • Lucylew
              New Member
              • Sep 2007
              • 6

              #7
              Originally posted by ajaxrand
              Hi there,
              when you sending the hidden form fields, there is no value with them.Try to send them too
              This will work for you.

              [CODE=php]
              <input type="hidden" name="productid " value="<?Php echo $r['productid'];?>"/>
              <input type="hidden" name="price" value="<?Php echo $r['price'];?>"/>
              <input type="hidden" name="productna me" value="<?Php echo $r['productname'];?>"/>
              [/CODE]

              Post back with your updates. Thanks :)
              Hi, thanks for that code i was just wondering where abouts to put it coz ive tryed it on the basket page and i still am gettin the "undefined index" error

              Comment

              • ak1dnar
                Recognized Expert Top Contributor
                • Jan 2007
                • 1584

                #8
                Originally posted by Lucylew
                Hi, thanks for that code i was just wondering where abouts to put it coz ive tryed it on the basket page and i still am gettin the "undefined index" error
                You have to put the hidden parameters to the form. That form is the one which calling for the php script to process the form data, additionally now you getting the error from the called script. as undefined index. So first put the values to the calling script.Then post it.
                You should replace the line number 36,37,38 on this post.

                Comment

                • Lucylew
                  New Member
                  • Sep 2007
                  • 6

                  #9
                  [CODE=php]


                  <?include("conn info.php")?>
                  <html>
                  <head>
                  <title>Products </title>
                  </head>
                  <link rel="stylesheet " type="text/css" href="style.css "/>
                  <body background="htt p://i145.photobucke t.com/albums/r224/lucy_lew/backgroundandlo go.jpg" border="0" alt="background img">
                  <h1>
                  <a href="login.php ">Home</a>&nbsp;&nbsp;
                  <a href="search.ph p">Search</a>&nbsp;&nbsp;
                  <a href="products. php">Products</a>&nbsp;&nbsp;
                  <a href="basket.ph p">Shopping Basket</a>&nbsp;&nbsp;
                  <a href="register. php">Register New User</a>
                  </h1>

                  </div>
                  <div id="container" >
                  <div id="left_conten t">
                  <div id = "left_text" >
                  <?
                  $query="select * FROM products ";
                  $result=mysql_q uery($query) or die("Couldnt do it");?>
                  <?$numrows=mysq l_num_rows($res ult);
                  if ($numrows>0)
                  {?>
                  <table border="1">
                  <?
                  while($r=mysql_ fetch_array($re sult))
                  {?>
                  <form action="basket. php" method="post">

                  <td><?echo $r["productid"];?></td>
                  <td><?echo $r["price"];?></td>
                  <td><?echo $r["productnam e"];?></td>
                  <td><img src="images/<?echo $r["productima ge"];?>" alt="Image"></td>
                  <td><input type="submit" value="Add to Basket">
                  <td/>
                  </form>

                  </td>
                  </tr>
                  <?
                  }
                  ?>
                  </table>

                  <?}
                  else
                  {
                  echo("Nothing Found.");
                  }


                  [/CODE]

                  [CODE=php]




                  <html>
                  <link rel="stylesheet " type="text/css" href="style.css "/>
                  <body background="htt p://i145.photobucke t.com/albums/r224/lucy_lew/backgroundandlo go.jpg" border="0" alt="background img">
                  <h1>
                  <a href="login.php ">Home</a>&nbsp;&nbsp;
                  <a href="search.ph p">Search</a>&nbsp;&nbsp;
                  <a href="products. php">Products</a>&nbsp;&nbsp;
                  <a href="basket.ph p">Shopping Basket</a>&nbsp;&nbsp;
                  <a href="register. php">Register New User</a>&nbsp;&nbsp;

                  </h1>
                  <head>
                  <title>Basket </title>
                  </head>
                  <body>

                  </body>

                  <?include("conn info.php");

                  $productid=$_PO ST["productid"];
                  $price=$_POST["price"];
                  $productname=$_ POST["productnam e"];

                  $query = mysql_query("IN SERT INTO basket(producti d,price,product name)
                  VALUES ('$productid',' $price','$produ ctname')")or die("Couldn't")

                  ?>
                  Added to the basket
                  </html>
                  [/CODE]

                  I think ive put that code in in the right place because its adding to the basket but its adding blank entries, this is the error i get on the basket page:

                  Notice: Undefined index: productid in d:\inetpub\wwwr oot\lucyclewis\ basket.php on line 23

                  Notice: Undefined index: price in d:\inetpub\wwwr oot\lucyclewis\ basket.php on line 24

                  Notice: Undefined index: productname in d:\inetpub\wwwr oot\lucyclewis\ basket.php on line 25
                  Added to the basket

                  Please help its really stressing me out...
                  Last edited by ak1dnar; Sep 4 '07, 02:08 PM. Reason: Added the CODE=php Tags

                  Comment

                  • ak1dnar
                    Recognized Expert Top Contributor
                    • Jan 2007
                    • 1584

                    #10
                    Where is the <hidden> fields? Still Its not there in the above post. you have to add them inside the FORM on the first code listening.


                    Please use the code tags in this format.
                    [code=php]
                    and
                    make sure to close them as described in the reply Guidelines on the right hand side with your text editor.

                    Comment

                    • Lucylew
                      New Member
                      • Sep 2007
                      • 6

                      #11
                      Originally posted by ajaxrand
                      Where is the <hidden> fields? Still Its not there in the above post. you have to add them inside the FORM on the first code listening.


                      Please use the code tags in this format.
                      [code=php]
                      and
                      make sure to close them as described in the reply Guidelines on the right hand side with your text editor.
                      sorry, it all works now thank you so so so soooo much for your help

                      Comment

                      • ak1dnar
                        Recognized Expert Top Contributor
                        • Jan 2007
                        • 1584

                        #12
                        Originally posted by Lucylew
                        sorry, it all works now thank you so so so soooo much for your help
                        No Problem, glad you got it working. Post back any time if you ever need anything. good luck!

                        Comment

                        Working...