How to Join 2 Variable

Hello,
I want to join 2 variable of php see the script below
[php]$no = $_SESSION[‘no’];
for($i=0;$i<=$no; $i++)
{

$item.$i = $_POST['item'.$i.''];

}[/php]

What do i want to do with the above script? :-
I have stored no in superglobal variable
Then i want to get multiple values via POST
Explanation

When $no = 5 

then 

$item1 = $_POST['item1'];

$item2 = $_POST['item2'];

$item3 = $_POST['item3'];

$item4 = $_POST['item4'];

$item5 = $_POST['item5'];

^ This is what i wanna do with the php script but it doesn’t allow it.

Some help would be really appreciated.
Thanks

Post your form. I think your going about this the wrong way.

Okay
Form is divided in 2 steps
Step 1
[php]
Number of Items :

Name of Raffle :

Slots :

Credit :

SteamID of user :

SteamID of Admin:



[/php] Step 2 [php]session_start(); $no = $_POST['no']; $_SESSION['no'] = $no; $nameofraffle = $_POST['nameofraffle']; $slots = $_POST['slots']; $credits = $_POST['credits']; $usteamid =$_POST['usteamid']; $asteamid =$_POST['asteamid']; $otherinfo =$_POST['otherinfo'];

$host = ‘localhost’;
$pass = ‘’;
$user = ‘root’;
$db = ‘test’;
$con=mysqli_connect($host,$user,$pass,$db);

// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,“INSERT INTO tstraffle VALUES (’$nameofraffle’,’$slots’,’$otherinfo’,’$credits’,’$usteamid’,’$asteamid’”);

?>

<? for ($x=0; $x<=$no; $x++) { echo "Item".$x.":
"; echo "Quality".$x.":
"; } ?>[/php]

Thats it!

It’s rather confusing they way you are doing things, but it appears you are wanting to generate x amount of form fields based on form input. You need to create an array of the generated form elements and then loop through them with foreach and then do what you want with the results. Notice the square brackets.

You could number the brackets but they are already going to be numbered as an array element.

[php]<?php
$no = 5;
for ($x = 0; $x <= $no; $x++)
{
echo “Item $x:<input type=“text” name=“item[]” placeholder=“Defindex”>
\n”;
echo “Quality$x :<input type=“text” name=“q[]” placeholder=“Quality”>
\n”;
}
?>[/php]

You can see an example of the foreach at my website here:
http://galaxyinternet.us/php-insert-form-array/

Sponsor our Newsletter | Privacy Policy | Terms of Service