dwex Posted January 9, 2011 Share Posted January 9, 2011 This will only send 1 goggles information into the database but I have a "adding" page that can actually add more than 1 goggles at once. I have no idea how to go about saving multiple goggle's information using array or loop. $name= $_POST['goggles_name']; $price = $_POST['goggles_price']; $des = $_POST['goggles_description']; $file = $_FILES['goggles_image']['name']; $chkbox = $_POST['upload']; $id = $_POST['goggles_id']; $query = "UPDATE goggles SET goggles_name = '$name' , goggles_price = '$price' ,goggles_description = '$des' WHERE goggles_id ='".$id."' "; $result = mysqli_query($link, $query) or die(mysqli_error($link)); Quote Link to comment https://forums.phpfreaks.com/topic/223858-how-to-send-multiple-variables-into-database/ Share on other sites More sharing options...
MasterACE14 Posted January 9, 2011 Share Posted January 9, 2011 if it's multiples you need more than a single record in the database, you need INSERT as opposed to UPDATE Quote Link to comment https://forums.phpfreaks.com/topic/223858-how-to-send-multiple-variables-into-database/#findComment-1157003 Share on other sites More sharing options...
revraz Posted January 9, 2011 Share Posted January 9, 2011 You can ask the user how many items they wish to enter, then dynamically create that many form boxes, then just use a Insert statement to enter them one row at a time, but let it cycle for as many rows as you have. Quote Link to comment https://forums.phpfreaks.com/topic/223858-how-to-send-multiple-variables-into-database/#findComment-1157005 Share on other sites More sharing options...
dwex Posted January 9, 2011 Author Share Posted January 9, 2011 ah yeah.. sorry I copied paste the wrong one. $type = $_POST['tabledrop']; $item = $_POST['name']; $price = $_POST['price']; $des = $_POST['description']; $file = $_FILES['pbimage']['name']; $query = "INSERT into $type SET {$type}_name = '$item' , {$type}_price = '$price' , {$type}_image = '$file' , {$type}_description = '$des' "; Quote Link to comment https://forums.phpfreaks.com/topic/223858-how-to-send-multiple-variables-into-database/#findComment-1157006 Share on other sites More sharing options...
dwex Posted January 9, 2011 Author Share Posted January 9, 2011 how to let it cycle? Quote Link to comment https://forums.phpfreaks.com/topic/223858-how-to-send-multiple-variables-into-database/#findComment-1157009 Share on other sites More sharing options...
trq Posted January 9, 2011 Share Posted January 9, 2011 Let what cycle? Can you be more descriptive with your problem? Quote Link to comment https://forums.phpfreaks.com/topic/223858-how-to-send-multiple-variables-into-database/#findComment-1157010 Share on other sites More sharing options...
dwex Posted January 9, 2011 Author Share Posted January 9, 2011 "You can ask the user how many items they wish to enter, then dynamically create that many form boxes, then just use a Insert statement to enter them one row at a time, but let it cycle for as many rows as you have." From Rez Quote Link to comment https://forums.phpfreaks.com/topic/223858-how-to-send-multiple-variables-into-database/#findComment-1157011 Share on other sites More sharing options...
trq Posted January 9, 2011 Share Posted January 9, 2011 dwex. It is up to you to explain your issue well enough that people can help you. If you can't do that, you wont get much help. Quote Link to comment https://forums.phpfreaks.com/topic/223858-how-to-send-multiple-variables-into-database/#findComment-1157015 Share on other sites More sharing options...
dwex Posted January 9, 2011 Author Share Posted January 9, 2011 right now, I have 3 items that needs to be stored into the database but only the last item gets stored and I think it's because my Insert codes is only run once so I am wondering if it's possible to run it 3 times so that all 3 items will be stored into the database instead of just the last 1. Quote Link to comment https://forums.phpfreaks.com/topic/223858-how-to-send-multiple-variables-into-database/#findComment-1157016 Share on other sites More sharing options...
Anti-Moronic Posted January 9, 2011 Share Posted January 9, 2011 ..and escape your data! Damn. $postvar = mysql_real_escape_string($_POST['postvar']); Quote Link to comment https://forums.phpfreaks.com/topic/223858-how-to-send-multiple-variables-into-database/#findComment-1157018 Share on other sites More sharing options...
trq Posted January 9, 2011 Share Posted January 9, 2011 right now, I have 3 items that needs to be stored into the database What are these three items currently stored in? Quote Link to comment https://forums.phpfreaks.com/topic/223858-how-to-send-multiple-variables-into-database/#findComment-1157023 Share on other sites More sharing options...
dwex Posted January 9, 2011 Author Share Posted January 9, 2011 their information are to be stored and send to the inserting page but my insert page which looks like this ... $type = $_POST['tabledrop']; $item = $_POST['name']; $price = $_POST['price']; $des = $_POST['description']; $feature = $_POST['feature']; $file = $_FILES['pbimage']['name']; $target_path = "C:/xampp/htdocs/paintball/itemimages/"; $target_path = $target_path . basename( $_FILES['pbimage']['name']); if(move_uploaded_file($_FILES['pbimage']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['pbimage']['name']). " has been uploaded/"; } $query = "INSERT into $type SET {$type}_name = '$item' , {$type}_price = '$price' , {$type}_image = '$file',{$type}_feature , {$type}_description = '$des' "; $result = mysqli_query($link, $query) or die(mysqli_error($link)); can only store the last item , I'm thinking I'll need to use an array to go about sending all 3 items to this inserting page then through this inserting page , into my database. Quote Link to comment https://forums.phpfreaks.com/topic/223858-how-to-send-multiple-variables-into-database/#findComment-1157028 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.