Jump to content

searls03

Members
  • Posts

    907
  • Joined

  • Last visited

Everything posted by searls03

  1. ok....so I don't have to add anything to it.....so like this? <?php include_once("connect.php"); session_start(); foreach($_SESSION AS $key => $val) { $$key = $val; } $sql = "INSERT INTO transactions (price, product, quantity, product_id, priceunit, month, day, year, academy, date) VALUES('$priceunit', '$product', '$qty', '$id', '$price', '$month', '$day', '$year', '$academy', '$date' )"; $rs = mysql_query($sql) or die ("Problem with the query: $sql <br />" . mysql_error()); session_destroy(); $sql = mysql_query("SELECT * FROM cart"); while($row = mysql_fetch_array($sql)){ $cid = $row["cart_id"]+1; $_SESSION['cart_id'] = $cid; } ?> only problem is that it does insert one correctly, but then the rst of them insert blank.
  2. could you just show me one more line after $$key=$val? i am much more of a visual learner and I want to make sure that I do it right......I know that sometimes that first one can be different than the others...
  3. maybe you can also help me with this. what I need is for a loop to run to make tabbed pannels according to categories. then I need the buttons to be put into the correct tab based on the category it falls under. then a subcategory tabs inside the other tabs for products that have that specific sub category. here is what I sorta made....it doesn't work though.... <div id="TabbedPanels1" class="TabbedPanels"> <ul class="TabbedPanelsTabGroup"><?php $sql = mysql_query("SELECT * FROM categories"); while($row = mysql_fetch_array($sql)){ $category = $row["category"]; $sub =$row["subcategory"]; ?> <li class="TabbedPanelsTab" tabindex="0"><?php echo $category; ?></li> <div class="TabbedPanelsContentGroup"> <div class="TabbedPanelsContent"> <?php // set layout vars $x = 1; // set $x $start = array ('1', '10', '19', '28', '37', '46', '55', '64', '73', '82', '91', '100', '109', '118', '127', '135'); //columns will be started at each of these numbers $end = array( '9', '18', '27', '36', '45', '54', '63', '72', '81', '90', '99','108','117', '126' ); // set numbers to end columns at ?> <?php echo '<table border="1px" cellpadding="0px" cellspacing="0px" ><tr height=\'50px\'>'; //start the table, and the row. // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM products where category=".$category.""); while($row = mysql_fetch_array($sql)){ $product = $row["product"]; $id =$row["id"]; $price =$row["price"]; if (in_array($x, $start)) { // if x equals a number in the start array echo '<td width="100">'; // start a column } ?> <?php $sql = mysql_query("SELECT * FROM categories"); while($row = mysql_fetch_array($sql)){ $category = $row["category"]; $sub =$row["subcategory"]; ?> <?php } ?> <div id="products"> <form action="" method="POST" name="myform<?php echo $id; ?>" class="myform<?php echo $id; ?>"> <input type="hidden" name="hiddenField" class="hiddenField" value="<?php echo $product; ?>" /> <input type="hidden" name="hiddenField2" class="hiddenField2" value="<?php echo $id; ?>" /> <input type="hidden" name="hiddenField1" class="hiddenField1" value="<?php echo $price; ?>" /> <input type="submit" name="submit" class="submit" value="<?php echo $product; ?>" style="background-color:lightgreen; height:50px; padding: 0px; margin:0px; width:100px;"> </form> </div> <?php if (!in_array($x, $end)){ // if $x equals anything OTHER than 9, 18, etc - put in a line break } else { // else if it DOES equal 9, 18 ,etc end the column echo '</td>'; } $x ++; // increase x to keep count } // while loop ends //now outside of the loop, $x = $x - 1; //subtract the last $X++ so you know exactly how many buttons were added if (!in_array($x, $end)){ // if $x equals anything OTHER than 9, 18, etc - end the column as it wouldn't have ended itself echo '</td>'; } echo '</tr></table>'; // close the row and table ?><?php } ?> </div> </ul> </div>
  4. also I would like the buttons to touch.
  5. I am not quite sure what you mean. could you like write the first 3 pieces for me? that might help it make a bit more sense. as said before, I am not good with arrays or loops.
  6. how would I make a method similar to this work? this is where += is from http://php.net/manual/en/language.operators.increment.php
  7. so like: <?php include_once("connect.php"); session_start(); session_destroy(); session_start(); $sql = mysql_query("SELECT * FROM cart"); while($row = mysql_fetch_array($sql)){ $cid = $row["cart_id"]+1; $_SESSION['cart_id'] = $cid; } if($_POST['payment2']){ $sql = "INSERT INTO cart (cart_id) VALUES('".$_SESSION['cart_id']."' )"; $rs = mysql_query($sql) or die ("Problem with the query: $sql <br />" . mysql_error()) ; echo $cid; echo $sql; } foreach($_POST["product"] AS $key => $val) { $_SESSION['product']['key'] = $product; $_SESSION['month']['key'] = $month; $_SESSION['day'] ['key']= $day; $_SESSION['year']['key'] = $year; $_SESSION['date']['key'] = $date; $_SESSION['price']['key'] = $price; $_SESSION['qty']['key'] = $qty; $_SESSION['id']['key'] = $id; $_SESSION['total']['key'] = $total; $_SESSION['academy']['key'] = $academy; $_SESSION['priceunit']['key'] = $priceunit; $sql = "INSERT INTO transactions (price, product, quantity, product_id, priceunit, month, day, year, academy, date) VALUES('$priceunit', '$product', '$qty', '$id', '$price', '$month', '$day', '$year', '$academy', '$date' )"; $rs = mysql_query($sql) or die ("Problem with the query: $sql <br />" . mysql_error()); } then where setting: <?php include_once("connect.php"); session_start(); foreach($_POST["product"] AS $key => $val) { $_SESSION['product'] = $val; $_SESSION['month'] = $_POST['month'][$key]; $_SESSION['day'] = $_POST['day'][$key]; $_SESSION['year'] = $_POST['year'][$key]; $_SESSION['date'] = $_POST['date'][$key]; $_SESSION['price'] = $_POST['price'][$key]; $_SESSION['qty'] = $_POST['qty'][$key]; $_SESSION['id'] = $_POST['id'][$key]; $_SESSION['total'] = $_POST['total'][$key]; $_SESSION['academy'] = $_POST['academy'][$key]; $_SESSION['priceunit'] = $price * $qty; } ?> Like this?
  8. no, I need them to automatically fill in those numbers for like when more buttons are added. otherwise I have to manually key them in. so like $start = array (Automatically increment);
  9. how would I make the start numbers dynamic?
  10. I think I am running into the problem because they are not array....they are simply a looped result.
  11. so I need some help passing these variable from this page to final.php. how do I pass these arrays? I know if it were singled....not arrayed, I could use hidden fields in a form and echo them out....but these are multiples....not singled. The form way is prefered.....but it doesn't have to be. I just need these passed to the page where I am going to process them. I am not good at working with arrays. Thanks in advance <?php include_once("connect.php"); session_start(); foreach($_POST["product"] AS $key => $val) { $product = $val; $month = $_POST['month'][$key]; $day = $_POST['day'][$key]; $year = $_POST['year'][$key]; $date = $_POST['date'][$key]; $price = $_POST['price'][$key]; $qty = $_POST['qty'][$key]; $id = $_POST['id'][$key]; $total = $_POST['total'][$key]; $academy = $_POST['academy'][$key]; $priceunit = $price * $qty; } ?>
  12. this is what it is pulling from database. I also need all the fields to move too with the buttons. <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM products"); while($row = mysql_fetch_array($sql)){ $product = $row["product"]; $id =$row["id"]; $price =$row["price"]; ?> <div id="products"> <form action="" method="POST" name="myform<?php echo $id; ?>" class="myform<?php echo $id; ?>"> <input type="hidden" name="hiddenField" class="hiddenField" value="<?php echo $product; ?>" /> <input type="hidden" name="hiddenField2" class="hiddenField2" value="<?php echo $id; ?>" /> <input type="hidden" name="hiddenField1" class="hiddenField1" value="<?php echo $price; ?>" /> <input type="submit" name="submit" class="submit" value="<?php echo $product; ?>" style="background-color:lightgreen; height:50px; width:100px;"> </form> </div> <?php } ?>
  13. linebreak. if you are going to use a foreach loop....please help me with that.....I am not good at writing them. so here is like a visual representation of what I want: currently: | | | | | | | | | | | | | | | | | | | | what I want: ||||| ||||| ||||| ||||| ||||| ||||| ||||| ||||| ||||| does that make some more sense?
  14. quick question, I have this code that returns over 100 buttons: <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM products"); while($row = mysql_fetch_array($sql)){ $product = $row["product"]; $id =$row["id"]; $price =$row["price"]; ?> <div id="products"> <form action="" method="POST" name="myform<?php echo $id; ?>" class="myform<?php echo $id; ?>"> <input type="hidden" name="hiddenField" class="hiddenField" value="<?php echo $product; ?>" /> <input type="hidden" name="hiddenField2" class="hiddenField2" value="<?php echo $id; ?>" /> <input type="hidden" name="hiddenField1" class="hiddenField1" value="<?php echo $price; ?>" /> <input type="submit" name="submit" class="submit" value="<?php echo $product; ?>" style="background-color:lightgreen; height:50px; width:100px;"> </form> </div> <?php } ?> What I would like is for the buttons to form columns of nine. ie 9 buttons in a column then a new column form.... how do I do this?
  15. but the problem I have is associating the two with each other.....that is the main thing I need.........
  16. submission code: <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM cart where cart_id = ".$cid.""); while($row = mysql_fetch_array($sql)){ $id =$row["id"]; ?> <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".update<?php echo $id; ?>").validate({ debug: false, submitHandler: function(form) { // do other stuff for a valid form $.post('update.php', $(".update<?php echo $id;?>").serialize(), function(data) { $("#price").load("index.php #price");$("#total").load("index.php #total"); }); } }); }); </script> <?php } ?> form: <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM cart where cart_id = ".$cid.""); while($row = mysql_fetch_array($sql)){ $product = $row["product123"]; $price1 = $row["price"]; $id = $row["id"]; $qty = $row["quantity"]; if($product !=""){ ?> <form action="" class="update<?php echo $id; ?>" method="POST"> <input name="id" type="hidden" value="<?php echo $id; ?>" /> Quantity <input name="qty" type="text" value="<?php echo $qty; ?>" size="2" />$ <input name="price" type="text" value="<?php echo $price1; ?>" size="6" /> <input type="submit" name="update" id="update" value="update" /> </form> . so my problem is that only everyother time does the page actually not refresh.......so one time it does and database doesn't update......second time it doesn't refresh and it updates(this is what I want). why is it doing this? is it because it is inside a div that gets refreshed? if this is the problem....how do I fix it?
  17. what I would like to do is have a query that if $product_id with specific $cart_id is already present in database, then it will update quantity instead of inserting a new row, but if $product_id is not present with specific $cart_id(important that it isn't with this) then it will insert a new row. can anyone help? <?php include_once("connect.php"); session_start(); if($_POST['submit']) { // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM cart where cart_id = ".$_SESSION['cart_id'].""); while($row = mysql_fetch_array($sql)){ $product = $row["product123"]; $price1 = $row["price"]; $id = $row["product_id"]; $qty = $row["quantity"]; } $product = mysql_real_escape_string($_POST['hiddenField']); $price = mysql_real_escape_string($_POST['hiddenField1']); $id = mysql_real_escape_string($_POST['hiddenField2']); $sql = "INSERT INTO cart (price, product123, quantity, cart_id, product_id) VALUES('$price', '$product', '1', '".$_SESSION['cart_id']."', '$id' )"; $rs = mysql_query($sql) or die ("Problem with the query: $sql <br />" . mysql_error()); } ?>
  18. ok, I don't know if this fixed or not.....but with this code: <?php include_once("connect.php"); session_start(); $qty = ($_POST['qty']); $month = date("F Y"); $day = date("d"); $year = date("Y"); $date = date("Y-m-d"); for ($i = 0; $i <= count($_POST['product']); $i++) { $product = ($_POST['product'][$i]); $price = ($_POST['price'][$i]); $qty = ($_POST['qty'][$i]); $id = ($_POST['id'][$i]); $total = ($_POST['total'][$i]); $priceunit = $priceunit * $qty[$i]; $month = $month[$i]; $day = $day[$i]; $year = $year[$i]; $date = $date[$i]; $academy = ($_session['academy'][$i]); } $sql = "INSERT INTO transactions (price, product, quantity, product_id, priceunit, month, day, year, academy, date) VALUES('$priceunit', '$product', '$qty', '$id', '$price', '$month', '$day', '$year', '$academy', '$date' )"; $rs = mysql_query($sql) or die ("Problem with the query: $sql <br />" . mysql_error()); ?> I get results that are what the attachment is.....exactly what it is......how do I fix this.....and yes all my form fields do have values....
  19. one last question: how would I write this sentence: $priceunit = ($_POST['price']) * $qty; if this is an array: input name="qty[]" type="hidden" value="<?php echo $qty; ?>" /> without getting a fatal error of unsupported operand types?
  20. but it's not just $product that I need....it is all of those that I need. I get this error when I try: Warning: Invalid argument supplied for foreach() in /home/tkdpostk/public_html/collect.php on line 7: <?php include_once("connect.php"); session_start(); if($_POST['pay']) { foreach ($_POST['pay'] as $pay) { $product = mysql_real_escape_string($_POST['product']); $price = mysql_real_escape_string($_POST['price']); $qty = mysql_real_escape_string($_POST['qty']); $id = mysql_real_escape_string($_POST['id']); $total = mysql_real_escape_string($_POST['total']); $priceunit = ($_POST['price'])* $qty; $month = date("F Y"); $day = date("d"); $year = date("Y"); $date = date("Y-m-d"); $academy = mysql_real_escape_string($_session['academy']);} $sql = "INSERT INTO transactions (price, product, quantity, product_id, priceunit, month, day, year, academy, date) VALUES('$priceunit', '$product', '$qty', '$id', '$price', '$month', '$day', '$year', '$academy', '$date' )"; $rs = mysql_query($sql) or die ("Problem with the query: $sql <br />" . mysql_error()); } ?> and here is code inside of the loop <form name="pay" class="pay" method="POST" action="collect.php"> <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM cart where cart_id = ".$cid.""); while($row = mysql_fetch_array($sql)){ $product = $row["product123"]; $price1 = $row["price"]; $id = $row["id"]; $qty = $row["quantity"]; ?> <input name="product[]" type="hidden" value="<?php echo $product; ?>" /><input name="price[]" type="hidden" value="<?php echo $price1; ?>" /><input name="id[]" type="hidden" value="<?php echo $id; ?>" /> <input name="qty[]" type="hidden" value="<?php echo $qty; ?>" /><input name="total[]" type="hidden" value="$total" /> <hr /> <?php } ?><input type="submit" name="pay" id="pay" value="update" /></form> . I seriously am trying to explain.....but it is very hard to express in letters. I am sorry about it. Hopefully this one makes some sense.....although I doubt it.
  21. that's what I'm attempting to tell you......but as you can see I don't know much about them. but let me try again. I will have multiple products on one page......they will all be using the form name "product". I need all of these.....lets say 5......to submit to my database in a loop. currently it only submits that last one.....I need all of them to submit. I hope this makes a little more sense.
  22. ok. I am not good at writing foreach loops. I need help writing the first code in a foreach loop. the second code is in a while loop, but I didn't show that. I need it to be able to submit all the data in it that is present.....so like all products.....not just one.
  23. I do not understand how to write an array....maybe someone can help me. I need to write this in a foreach loop: if($_POST['pay']) { $product = mysql_real_escape_string($_POST['product']); $price = mysql_real_escape_string($_POST['price']); $qty = mysql_real_escape_string($_POST['qty']); $id = mysql_real_escape_string($_POST['id']); $total = mysql_real_escape_string($_POST['total']); $priceunit = ($_POST['price'])* $qty; $month = date("F Y"); $day = date("d"); $year = date("Y"); $date = date("Y-m-d"); $academy = mysql_real_escape_string($_session['academy']); $sql = "INSERT INTO transactions (price, product, quantity, product_id, priceunit, month, day, year, academy, date) VALUES('$priceunit', '$product', '$qty', '$id', '$price', '$month', '$day', '$year', '$academy', '$date' )"; $rs = mysql_query($sql) or die ("Problem with the query: $sql <br />" . mysql_error()); } from this: <input name="product[]" type="hidden" value="<?php echo $product; ?>" /><input name="price[]" type="hidden" value="<?php echo $price1; ?>" /><input name="id[]" type="hidden" value="<?php echo $id; ?>" /> <input name="qty[]" type="hidden" value="<?php echo $qty; ?>" /><input name="total[]" type="hidden" value="$total" /> .....values missing in the form I will add later. can anyone please help????
  24. ok, I got it figured out.....now one last problem......this code only seems to not refresh the page everyother time.....one time it doesnt and the next time it does.....it aint ever supposed to... <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM cart"); while($row = mysql_fetch_array($sql)){ $id =$row["id"]; ?> <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".delete<?php echo $id; ?>").validate({ debug: false, submitHandler: function(form) { // do other stuff for a valid form $.post('delete.php', $(".delete<?php echo $id;?>").serialize(), function(data) { $("#price").load("index.php #price");$("#total").load("index.php #total"); }); } }); }); </script> <?php } ?> <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM cart"); while($row = mysql_fetch_array($sql)){ $product = $row["product123"]; $price1 = $row["price"]; $id = $row["id"]; ?> <form name="delete<?php echo $id; ?>" class="delete<?php echo $id; ?>" method="POST" action=""> <input type="hidden" name="hiddenField" class="hiddenField" value="<?php echo $id; ?>" /> <input type="submit" name="submit" class="submit" value="delete" style="background-color:lightgreen; height:50px; width:100px;"> </form> <?php echo $product; echo"<br />"; echo $price1; echo"<br />"; $total = $price1 + $total; ?> <?php } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.