Jump to content

How to send multiple variables into database?


dwex

Recommended Posts

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));

 

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.

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' ";

 

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.

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.