bizzyweb Posted December 10, 2010 Share Posted December 10, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/221200-getting-the-id-back-but-no-variables/ Share on other sites More sharing options...
Adam Posted December 10, 2010 Share Posted December 10, 2010 Could you explain what you mean a little more please? FYI or tags make your code a lot more readable, and more likely to get you help. Quote Link to comment https://forums.phpfreaks.com/topic/221200-getting-the-id-back-but-no-variables/#findComment-1145274 Share on other sites More sharing options...
bizzyweb Posted December 10, 2010 Author Share Posted December 10, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/221200-getting-the-id-back-but-no-variables/#findComment-1145275 Share on other sites More sharing options...
Adam Posted December 10, 2010 Share Posted December 10, 2010 Try debugging the reutrn values with a print_r within the while loop. Quote Link to comment https://forums.phpfreaks.com/topic/221200-getting-the-id-back-but-no-variables/#findComment-1145293 Share on other sites More sharing options...
MMDE Posted December 10, 2010 Share Posted December 10, 2010 <p>ID= <?php echo $rep_id; ?></p> <p> Componist = <?php echo $componisten; ?></p> correct me if I'm wrong, but isn't $componisten an array? =p Quote Link to comment https://forums.phpfreaks.com/topic/221200-getting-the-id-back-but-no-variables/#findComment-1145300 Share on other sites More sharing options...
bizzyweb Posted December 10, 2010 Author Share Posted December 10, 2010 The array prints on the screen. Indeed the echo statement has to be: echo $componist. But is doesn't give back anything..... Quote Link to comment https://forums.phpfreaks.com/topic/221200-getting-the-id-back-but-no-variables/#findComment-1145309 Share on other sites More sharing options...
MMDE Posted December 10, 2010 Share Posted December 10, 2010 the function inputControl please provide code! Quote Link to comment https://forums.phpfreaks.com/topic/221200-getting-the-id-back-but-no-variables/#findComment-1145321 Share on other sites More sharing options...
bizzyweb Posted December 10, 2010 Author Share Posted December 10, 2010 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 } Quote Link to comment https://forums.phpfreaks.com/topic/221200-getting-the-id-back-but-no-variables/#findComment-1145326 Share on other sites More sharing options...
PFMaBiSmAd Posted December 10, 2010 Share Posted December 10, 2010 Your form method='post'. Why are you using $_GET variables? Quote Link to comment https://forums.phpfreaks.com/topic/221200-getting-the-id-back-but-no-variables/#findComment-1145328 Share on other sites More sharing options...
MMDE Posted December 10, 2010 Share Posted December 10, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/221200-getting-the-id-back-but-no-variables/#findComment-1145329 Share on other sites More sharing options...
Adam Posted December 10, 2010 Share Posted December 10, 2010 MMDE - you can pass a value using a submit button, provided it's got a name attribute. Quote Link to comment https://forums.phpfreaks.com/topic/221200-getting-the-id-back-but-no-variables/#findComment-1145337 Share on other sites More sharing options...
MMDE Posted December 10, 2010 Share Posted December 10, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/221200-getting-the-id-back-but-no-variables/#findComment-1145341 Share on other sites More sharing options...
Adam Posted December 10, 2010 Share Posted December 10, 2010 Yeah. To be honest there was too much ambiguity in the description of the problem before, so I just didn't attempt an answer. Quote Link to comment https://forums.phpfreaks.com/topic/221200-getting-the-id-back-but-no-variables/#findComment-1145343 Share on other sites More sharing options...
bizzyweb Posted December 10, 2010 Author Share Posted December 10, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/221200-getting-the-id-back-but-no-variables/#findComment-1145371 Share on other sites More sharing options...
bizzyweb Posted December 12, 2010 Author Share Posted December 12, 2010 Is it possible to get an answer on my question? :'( Quote Link to comment https://forums.phpfreaks.com/topic/221200-getting-the-id-back-but-no-variables/#findComment-1146146 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.