Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Results 1 to 7 of 7

This is a discussion on Combining variables? in the Shared & Semi-Dedicated forum
Hey, is there any way to combie variables into one? I want to automatically generate forms (display a shipping info box for each order) and ...

  1. #1
    JPC Member
    Join Date
    Aug 2002
    Posts
    32

    Combining variables?

    Hey, is there any way to combie variables into one? I want to automatically generate forms (display a shipping info box for each order) and then write a script that enters it into the database...I thought I had oent that worked...but it's not, for SOME reason!



    Can anyone help me?



    here's the code

    PHP Code:

    <html>

    <head>

    <title>Lewright Meats</title>

    <?php

    @include("http://www.lewrightmeats.biz/includes/header.php")

    ?>

     

    <?php

     

    $cust 
    1;

     

    echo(
    "<font class='text20'>Please enter shipping information for the following ordered packages</font>");

     

    $dbcnx = @mysql_connect("localhost""jlewrigh_pages""password");

    if (!
    $dbcnx) { echo( "<P>Unable to connect to the database server at this time.</P>" ); exit();}

    mysql_select_db("jlewrigh_orders"$dbcnx);

    $sql2 mysql_query("select id, onea, oneb, onec, oned, two, three, four, five, six, seven from packages where cust='$cust' & submitted=0"); 

    if (!
    $sql2

    {

    echo(
    "<P>Error performing query: ".mysql_error()."</P>");

    exit(); 

    }

    while(
    $curresultmysql_fetch_array($sql2)) { 

    $id $curresult["id"];

    $onea $curresult["onea"];

    $oneb $curresult["oneb"];

    $onec $curresult["onec"];

    $oned $curresult["oned"];

    $two $curresult["two"];

    $three $curresult["three"];

    $four $curresult["four"];

    $five $curresult["five"];

    $six $curresult["six"];

    $seven $curresult["seven"]; 

    echo(
    "<br><font class='text14' color='000000'>");

    echo(
    "<form action='/packages/shipping2.php' method=post>");

    $sqlcount0;

    $curcount0;

    if (
    $onea 0) { 

    echo(
    "9-10 lb. Ham");

    while (
    $curcount $onea){

    echo(
    "<input type='hidden' name='pkg".$sqlcount."' value='onea'><b>Name:</b> <input name='name".$sqlcount."' maxlength='40' size='40'><br><b>Street Address:</b><input name='address1".$sqlcount."' maxlength='40' size='40'><br><b>City, State and ZIP code:</b> <input name='address2".$sqlcount."' maxlength='50' size='50'><br><br>");

    $curcount++;

    $sqlcount++;

    }

    }

    }

    echo(
    "<input type=submit name='submitshipping' value='submit'></form></font>");

     

    if (
    "submit" == $submitshipping) {

    $sqlcount2=1;

    while (
    $sqlcount2 <=$sqlcount) {

    echo(
    $cust1);

     

    $sql "insert into shipping set " "cust='$cust".$sqlcount2."', " "pkg='$pkg$sqlcount2', " "name='$name".$sqlcount2."', " "address='$address1".$sqlcount2."', " "address2='$address2".$sqlcount2."'";

    if (
    mysql_query($sql)) {    echo("<P class='text16'>Your information has been stored, you may begin using your username and password, click <a href='java_script_:window.close();'>here</a> to close this window.</P>"); } else {    echo("<P class='text16'>Error adding user: " .         mysql_error() . "</P>"); }

    $sqlcount2++;

    }



    ?>

     

     

     

    <?php

    @include("http://www.lewrightmeats.biz/includes/footer.php")

    ?>




    it inserts stuff into my database, but all it inserts is "1" in every column



    any suggestions?



    THANKS IN ADVANCE!!

    Darrin

  2. #2
    Smo
    Smo is offline
    JPC Addict
    Join Date
    Nov 2002
    Location
    Finland
    Posts
    218
    aren't inserts supposed to look like this:

    PHP Code:

    $sql 
    "INSERT INTO Table (field1, field2, field3) VALUES ('$var1', '$var2', '$var2')"
    (you might have it right too, but i've never seen it done like that.)

    to combine vars set a dot inbetween them.

    PHP Code:

    $one 
    1;

    $two 3;

    $sum $one.$two
    hope that helps

  3. #3
    JPC Member
    Join Date
    Aug 2002
    Posts
    32
    well, it now isn't interting ANYTHING



    I think I might not have stated my question correctly. I want the database NAMES to be generated automatically. for example If the customer ordered 6t packages, I want it to insert the shipping information 6 times and I want the 6 addrssses to me the variables $address1, $address2......$address6, ect.



    here is my updated code, anyone got any ideas?



    PHP Code:



    <html>
    <head>
    <title>Lewright Meats</title>
    <?php
    @include("http://www.lewrightmeats.biz/includes/header.php")
    ?>


    <?php


    $cust 
    1;


    echo(
    "<font class='text20'>Please enter shipping information for the following ordered packages</font>");


    $dbcnx = @mysql_connect("localhost""jlewrigh_pages""password");
    if (!
    $dbcnx) {  echo( "<P>Unable to connect to the database server at this time.</P>" );  exit();}

    mysql_select_db("jlewrigh_orders"$dbcnx);

    $sql2 mysql_query("select id, onea, oneb, onec, oned, two, three, four, five, six, seven from packages where cust='$cust' & submitted=0");  
    if (!
    $sql2
    {
     echo(
    "<P>Error performing query: ".mysql_error()."</P>");
     exit();  
    }

    while(
    $curresultmysql_fetch_array($sql2)) { 
    $id $curresult["id"];
    $onea $curresult["onea"];
    $oneb $curresult["oneb"];
    $onec $curresult["onec"];
    $oned $curresult["oned"];
    $two $curresult["two"];
    $three $curresult["three"];
    $four $curresult["four"];
    $five $curresult["five"];
    $six $curresult["six"];
    $seven $curresult["seven"]; 
    echo(
    "<br><font class='text14' color='000000'>");
    echo(
    "<form action='/packages/shipping2.php' method=post>");

    $sqlcount0;
    $curcount0;
    if (
    $onea 0) {  
    echo(
    "9-10 lb. Ham<br>");
    while (
    $curcount $onea){

    echo(
    "<input type='hidden' name='pkg' value='onea'><b>Name:</b> <input name='name' maxlength='40' size='40'><br><b>Street Address:</b><input name='address1' maxlength='40' size='40'><br><b>City, State and ZIP code:</b> <input name='address2' maxlength='50' size='50'><br><br>");

    $curpkg=$pkg.$sqlcount;
    $curname=$name.$sqlcount;
    $curaddress=$address.$sqlcount;
    $curaddress2=$address2.$sqlcount;

    $pkg.$sqlcount=curpkg;
    $name.$sqlcount=curname;
    $address.$sqlcount=curaddress;
    $address2.$sqlcount=curaddress2;


    $curcount++;
    $sqlcount++;
    }
    }
    }

    echo(
    "<input type=submit name='submitshipping' value='submit'></form></font>");


    if (
    "submit" == $submitshipping) {
    $sqlcount2=1;
    while (
    $sqlcount2 <=$sqlcount) {

    echo(
    $cust1);

    $sql "insert into shippping set " "cust='$cust.$sqlcount2', " "pkg='$pkg.$sqlcount2', " "name='$name.$sqlcount2', "  "address='$address1.$sqlcount2', " "address2='$address2.$sqlcount2'"
      if (
    mysql_query($sql)) {    echo("<P class='text16'>Your information has been stored, you may begin using your username and password, click <a href='javascript:window.close();'>here</a> to close this window.</P>");  } else {    echo("<P class='text16'>Error adding user: " .         mysql_error() . "</P>");  }
    $sqlcount2++;
    }


    ?>
      


       
    <?php
    @include("http://www.lewrightmeats.biz/includes/footer.php")
    ?>

  4. #4
    Smo
    Smo is offline
    JPC Addict
    Join Date
    Nov 2002
    Location
    Finland
    Posts
    218
    hmm, I got confused reading your script (just woke up in the middle of the night), I'll go back to sleep and try to figure it out in the morning incase one of the other members dont help you first.

  5. #5
    JPC Member
    Join Date
    Aug 2002
    Posts
    32
    GREAT! thanks!

  6. #6
    Smo
    Smo is offline
    JPC Addict
    Join Date
    Nov 2002
    Location
    Finland
    Posts
    218
    so what does it do in your updated version? does it give some error message?

  7. #7
    JPC Member
    Join Date
    Aug 2002
    Posts
    32
    no, it doesn't do ANYTHING, that I can tell

    see it live here:
    www.lewrightmeats.biz/packages/shipping2.php

Bookmarks

Posting Permissions

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