Jump to content

Getting the id back, but no variables


bizzyweb

Recommended Posts

I made a file for updating data.

I do get the id back from the view page, but not the variable.

What do I do wrong? I'm puzzling a few days, but just don't see it.

 

This my code:

<?php
// init
$msg = '';
$errorMsg = '';
$rep_id = array();
$componist = '';
$repertoire = '';
$titel = '';

$formOK= false;


// + + + + + + + +  GET + + + + + + + + 
if(isset($_GET['id'])) 	{
$rep_id = inputControl($_GET['id']);
}
if(isset($_GET['componist']))	{
$componist = inputControl($_GET['componist']);
}

//print "session: $login_id, $login_recht"; // TEST van de sessie
// + + + + + + + + + + + + + + + + POST + + + + + + + + + +

if (isset($_POST['UpdateRepSubmit'])) {
	  if (isset($_POST['componist']))	{
		  $componist = inputControl($_POST['componist']);
}
if (isset($_POST['titel']))	{
		   $titel = inputControl($_POST['titel']);
}

}
//print'<pre>'; print_r($repertoire); print '</pre>'; //TEST2


// + + + + + + + + + + + + + + + + + + + queries

$select_query= "SELECT *
	FROM repertoire_eng
	ORDER BY componist ASC
	";


print $select_query; // TEST 3



// # # # # # # # # # # # database connectie # # # # # # # # # # 
$dblink = mysqli_connect($host,$user,$pass,$db) or die ('Mysql-connectie heeft gefaald.');

if (!$dblink)	{
	// + + + + + + fout bij met maken van databaseverbinding
	$errorMsg = "Geen verbinding met de MySQL-server";
}
else	{
	$result = mysqli_query($dblink, $select_query);

	if($result)	{
		$i = 0;
		while ($row = mysqli_fetch_array($result))	{ // uitlezen resultaat
			$repertoire_ids[$i] = $row['id'];
			$componisten[$i] = $row['componist'];
			$titels[$i] = $row['titel'];
			$i++;

	}
}
else	{
		// + + + + + fout bij het uitvoeren van de query
		$errorMsg = "De query kon niet worden uitgevoerd.";
}



// # # # # # # # # # # einde database connectie # # # # # # # # #

mysqli_close($dblink);
}
?>

 

In the html block:

<div id="container">
<form action="edit_repertoire.php" method="post" name="edit_repertoire" onsubmit = "return checkForm(this)">
<fieldset>
<legend>Update repertoire in your list:</legend>


<!-- # # # # # # Toevoegen van een hiddenfield om de id op te halen uit de URL # # # # # #  -->	

<input type="hidden" name="id" value = "<?php echo $rep_id; ?>" >

<p>ID= <?php echo $rep_id; ?></p>
<p> Componist = <?php echo $componisten; ?></p>

<!-- + + + + + + + FORMREGELComponist + + + + + + + -->
<div class="formregel">
<div class="formkolomlinks">Composer name:</div>
<div class="formkolomrechts"><input name="componist" id="componist"  type="text"  maxlength="128"
value="<?php echo $componist; ?>"  /> Name first, then the initials! </div>
    
</div><!-- Einde formregel -->


<!-- ++ + + + + + FORMREGEL Compositie en of rol + + + + + + + -->
<div class="formregel">
<div class="formkolomlinks">Composition and or role</div>
<div class="formkolomrechts"><input name="titel" id="titel" type="text"  maxlength="128" 
value="<?php echo $titel; ?>" /></div>
    
</div><!-- Einde formregel -->



<!-- +++++++ FORMREGEL +++++++ -->
<div class="formregel">
<div class="formkolomlinks"><input name="updateRepSubmit" type="submit" value="Update repertoire" /></div>

    
</div><!-- Einde formregel -->



</fieldset>
</form>
<div class="clear"></div>
</div><!-- einde container -->
</div><!-- einde tot_wrap -->

 

edit: added


blocks

 

Link to comment
https://forums.phpfreaks.com/topic/221200-getting-the-id-back-but-no-variables/
Share on other sites

Thank you,

The displaying in the body of the update form, in which I want to show the items composer and title in the textfields.

If I echo the ID, it returns the value of the item I want to edit in the other file.

 

If I echo $componist, nothing returns.

 

So If I get the ID, why not the other items from the database in the same table: componist and titel.

I  hope my question is now more clear.

Thank you in advance,

Georgette

 

 

 

my code :

// init
$msg = '';
$errorMsg = '';
$rep_id = array();
$componist = '';
$repertoire = '';
$titel = '';

$formOK= false;


// + + + + + + + +  GET + + + + + + + + 
if(isset($_GET['id'])) 	{
$rep_id = inputControl($_GET['id']);
}
if(isset($_GET['componist']))	{
$componist = inputControl($_GET['componist']);
}

//print "session: $login_id, $login_recht"; // TEST van de sessie
// + + + + + + + + + + + + + + + + POST + + + + + + + + + +

if (isset($_POST['UpdateRepSubmit'])) {
	  if (isset($_POST['componist']))	{
		  $componist = inputControl($_POST['componist']);
}
if (isset($_POST['titel']))	{
		   $titel = inputControl($_POST['titel']);
}

}
//print'<pre>'; print_r($repertoire); print '</pre>'; //TEST2


// + + + + + + + + + + + + + + + + + + + queries

$select_query= "SELECT *
	FROM repertoire_eng
	ORDER BY componist ASC
	";


print $select_query; // TEST 3



// # # # # # # # # # # # database connectie # # # # # # # # # # 
$dblink = mysqli_connect($host,$user,$pass,$db) or die ('Mysql-connectie heeft gefaald.');

if (!$dblink)	{
	// + + + + + + fout bij met maken van databaseverbinding
	$errorMsg = "Geen verbinding met de MySQL-server";
}
else	{
	$result = mysqli_query($dblink, $select_query);

	if($result)	{
		$i = 0;
		while ($row = mysqli_fetch_array($result))	{ // uitlezen resultaat
			$repertoire_ids[$i] = $row['id'];
			$componisten[$i] = $row['componist'];
			$titels[$i] = $row['titel'];
			$i++;

	}
}
else	{
		// + + + + + fout bij het uitvoeren van de query
		$errorMsg = "De query kon niet worden uitgevoerd.";
}



// # # # # # # # # # # einde database connectie # # # # # # # # #

mysqli_close($dblink);
}
?>

 

 

------------------------------------------------------------------

 

The html code:

 


<div id="container">
<form action="edit_repertoire.php" method="post" name="edit_repertoire" onsubmit = "return checkForm(this)">
<fieldset>
<legend>Update repertoire in your list:</legend>


<!-- # # # # # # Toevoegen van een hiddenfield om de id op te halen uit de URL # # # # # #  -->	

<input type="hidden" name="ud_id" value = "<?php echo $rep_id; ?>" >

<p>ID= <?php echo $rep_id; ?></p>
<p> Componist = <?php echo $componisten; ?></p>

<!-- + + + + + + + FORMREGELComponist + + + + + + + -->
<div class="formregel">
<div class="formkolomlinks">Composer name:</div>
<div class="formkolomrechts"><input name="componist" id="componist"  type="text"  maxlength="128"
value="<?php echo $componist; ?>"  /> Name first, then the initials! </div>
    
</div><!-- Einde formregel -->


<!-- ++ + + + + + FORMREGEL Compositie en of rol + + + + + + + -->
<div class="formregel">
<div class="formkolomlinks">Composition and or role</div>
<div class="formkolomrechts"><input name="titel" id="titel" type="text"  maxlength="128" 
value="<?php echo $titel; ?>" /></div>
    
</div><!-- Einde formregel -->



<!-- +++++++ FORMREGEL +++++++ -->
<div class="formregel">
<div class="formkolomlinks"><input name="updateRepSubmit" type="submit" value="Update repertoire" /></div>

    
</div><!-- Einde formregel -->
</fieldset>
</form>
<div class="clear"></div>
</div><!-- einde container -->
</div><!-- einde tot_wrap -->
</body>
</html>

 

edit: added


 

The functioin inputControl:

<?php
function inputControl($tekst)	{
$tekst = trim($tekst);				// verwijdert omringende spaties
$tekst = strip_tags($tekst);		//verwijdert html-tags
//if (!get_magic_quotes_gpc)  {		// controleert db-functie
	$tekst = addslashes($tekst); 	// voegt escape karakters toe

//}

return $tekst;						// retourneert de waarde zie je "" dan moet
									// je het op database niveau aanpassen
}

I see you try to get from both post and get, while the form is post method.

 

When you do it the post method, $_POST['UpdateRepSubmit'] must be set (at least according to your code), else it doesn't get the $_POST['componist']. you think you've set it with the submit button, if I'm not totally wrong, then you can't do that. You should set a hidden input instead. <input type="hidden" name="UpdateRepSubmit" value="1" />

 

 

 

if (isset($_POST['UpdateRepSubmit'])) {

  if (isset($_POST['componist'])){

    $componist = inputControl($_POST['componist']);

  }

  if (isset($_POST['titel'])){

    $titel = inputControl($_POST['titel']);

  }

}

 

also as I said earlier, don't: echo $componisten;

it is an array, so you must specify the key.

MMDE - you can pass a value using a submit button, provided it's got a name attribute.

 

yeah okay. As I said, I wasn't 100% sure.

 

But $componist is an empty string unless you got it from $_GET or $_POST, and from $_POST, you only get it if (isset($_POST['UpdateRepSubmit'])). You get $componisten from the db, but it's an array, and you treat it as a variable.

Is the code wrong?

I made it myself, but I see there are a lot of possibilities to programm your code.

Is there a specific style for american or dutch coding?

Properbly a silly question, but I still can't find out the best way to code. I learnt it thisway.

Is this ok?

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.