Dysan Posted November 16, 2007 Share Posted November 16, 2007 How do I insert data into an array, from a form? Quote Link to comment Share on other sites More sharing options...
Barand Posted November 16, 2007 Share Posted November 16, 2007 Data from a form is already in $_GET or $_POST array depending on form method. Quote Link to comment Share on other sites More sharing options...
Dysan Posted November 16, 2007 Author Share Posted November 16, 2007 Can you give me an example of how to insert data from a database, into an array? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 16, 2007 Share Posted November 16, 2007 It's in an array when you call it from the database. <?php $query = mysql_query("SELECT * FROM table"); //Make $row an array of DB values $row = mysql_fetch_assoc($query); //Now you can echo values out from the array echo $row['val']; ?> Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted November 16, 2007 Share Posted November 16, 2007 example: $sql = mysql_query("SELECT * FROM data WHERE id=1"); $row = mysql_fetch_array($sql); now you can do $row['column_1'], $row['column_2'] etc depending on how many columns you have Quote Link to comment Share on other sites More sharing options...
Dysan Posted November 16, 2007 Author Share Posted November 16, 2007 how do Shopping Karts work, how do they remember whats in your shopping Kart? How do I create a PHP Shopping Kart? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 16, 2007 Share Posted November 16, 2007 You need to use sessions to create a shopping cart. If you have all these questions, your obviously not ready to take on programming your own shopping cart. I suggest reading tutorials to learn the basics of PHP. Quote Link to comment Share on other sites More sharing options...
Dysan Posted November 16, 2007 Author Share Posted November 16, 2007 What just sessions? So I don't need to use an array? Can sessions hold multiple values? - e.g. The contents of a shopping cart (Product, Cost etc) Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 16, 2007 Share Posted November 16, 2007 Yes, a session can be an array. Quote Link to comment Share on other sites More sharing options...
Dysan Posted November 16, 2007 Author Share Posted November 16, 2007 How do I do that? store an array as a session? Can you give me an example of storing values from a form inside an array? Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted November 16, 2007 Share Posted November 16, 2007 ^ well, i would try to help you, but it would only lead to more endless questions.. use Google and search for your questions first.. google is truely amazing Quote Link to comment Share on other sites More sharing options...
Dysan Posted November 16, 2007 Author Share Posted November 16, 2007 Try me! I know a fair bit about sessions, and a little bit about arrays. I just need to see an exmplae, in order to make it self explanatory. Quote Link to comment Share on other sites More sharing options...
revraz Posted November 16, 2007 Share Posted November 16, 2007 Buy a PHP/MySQL book. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 16, 2007 Share Posted November 16, 2007 Take a look at these for an example http://www.php-shopping-cart-tutorial.com/shopping-cart.htm http://www.thewatchmakerproject.com/journal/276/building-a-simple-php-shopping-cart Quote Link to comment Share on other sites More sharing options...
Dysan Posted November 16, 2007 Author Share Posted November 16, 2007 So how do I insert data into an array via a form? Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 16, 2007 Share Posted November 16, 2007 <?php $arr = array(); if (isset($_POST['submit'])){ $arr[] = $_POST['var']; print_r($arr); } ?> <p> <form method="post"> <input type="text" name="var"> <input type="submit" name="submit"> </form> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.