Hi
I have a problem With the $_POST

Here is the code i have

i called this albums.php

<?php
Echo"
<table cellpadding='5' width='100%' border='1' bgcolor='white'>
<tr>
<td width='50%' align='left'>
Usere Alben die schon bestehen.
</td>
<td align='right'>
<form action='createalbum.php' method='POST'>	
	<table>
		<tr>
		<td align='left'>
		<font face='arial' size='2'>
		Albumauswahlliste.</font>
		</td>
		</tr>
		<tr>
		<td align='left'>
		
			 
		 <select name='albumname'>
 
  <option value='' selected='' >
<option value='Weinachtfeier'>Weinachtfeier</option>
<option value='Vereinsauftritte'>Vereinsauftritte</option>
<option value='Auftaktsitzungen'>Auftaktsitzungen</option>
<option value='Prinzenfuhrungen'>Prinzenfürungen</option>
 <option value='Kindersitzungen'>Kindersitzungen</option>
<option value='Kostumball'>Kostümball</option>
<option value='sonstiges'>sonstiges</option>
</select>
 
</select><input type='submit' name='submit' value='Senden. '>
	 		<a href='logout.php'>Abmelden</a><br>
		</td>
		</tr>
		</table></form>
</td>
</tr>
<tr>
<td colspan='2'>
</td>
</tr>
</table>
";	
	}
	else
	
	echo "bla bla";

i call this createalbum.php

<?php
if(isset($_SESSION['user']))
		{
		require("connect.php");

$id = $_SESSION['id'];
$albumname = $_POST['albumname'];
If ($_POST['albumname']=="")
{
echo "
	<form action='albums.php'
	<div  style='background-color: white; border: solid red 3px; width:52%;'><br>Sie haben kein album gewählt <br>aus der Albumauswahlliste.<br>Klicken Sie auf OK, um zurückzukehren.<br><br><input type='submit' value='OK' ><br>&nbsp;</div></form>
	";//do not reload page	
	die;
}
if ($albumname);
{
if (strlen($albumname)>100)
echo "albumname ist zu lang sie darf nicht mehr als 100 zeichen sein.";
else
{	
echo"
<form action='albumcreated.php' method='POST'>
<table calpadding='7' width='100%' border='1'>

<tr>
<td width='40%'>
<font face='arial' size='2' color='white'>Geben Sie eine kurze Beschreibung<br> des Fotos für das Album</font><br><font face='arial' size='3' color='white'><b>$albumname</b></font>. 

<input type='text' name='$albumname' value='$albumname'>
<textarea name='albumdescription' name='beschrijving' maxlengt='200'></textarea><br>
</td>
<td>
<font face='arial' size='2' color='white'>Suche nach neuen Album Cover</font><br>
<input type='hidden' name='MAX_FILE_SIZE' value='102400'><input type='file' name='userfile' accept='image/jpeg'><input type='submit' value='Senden'>


</td>


</tr>
</table>
</form>
";
}
}

}
else
	
	echo "bla bla":
?>

and the last one called albumcreated.php this is where the $_POST is not working.
and it gives me the folowing error
Notice: Undefined index: $albumnaam on line 6

<?php
	session_start();
	
	if(isset($_SESSION['user']))
		{
		$albumnaam=($_POST["$albumname"]); //this is lin 6		
$conn1=mysql_connect("localhost","bla", "blabla"); 
mysql_select_db("fotos") or die($error);
if (!$conn1) {
    die('Could not connect: ' . mysql_error());
}	
$sql1 ="CREATE TABLE IF NOT EXISTS $albumnaam (
	id int(11) NOT NULL auto_increment,
	albumname VARCHAR(25) NOT NULL,
	PRIMARY KEY (id)
	)";
	mysql_query($sql1) or die(mysql_error());
	
	$create = mysql_query("INSERT INTO $albumnaam VALUES('','$albumnaam')");
	echo"datatable created";
	echo"$albumnaam naam toegevoegd in table $albumnaam";
	 mysql_close($conn1);
	 }
	 ?>

if i put the code from albumcreated.php into createalbum.php just before echo"
<form action='albumcreated.php' it works perfect.

can someone exlain why this is not working ?

Thanks in advice John

it's better not to use variable for $_POST

gives a different name: i put "aname" for example

line 31 of createalbum.php
<input type='text' name='$albumname' value='aname'>

line 6 of albumcreated.php
$albumnaam=($_POST["aname"]); //this is lin 6

let me know how it works.

it's the same error

Notice: Undefined index: aname in line 6

line 31 of createalbum.php
<input type='text' name='aname' value='$albumname'> //does this input box show the correct variable $albumname?

line 6 of albumcreated.php
$albumnaam=$_POST["aname"]; //this is lin 6

echo $albumnaam; // does this give you the correct result?

Thank you.
for your help this is working now.

Learned a bit more.

Greetings John.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.