beginann Posted January 1, 2010 Share Posted January 1, 2010 Problem: I have a database with members in a society. I want to search for one person only (from a form) - perhaps to edit his/hers address etc. Now I want the result to be shown in the form so I can alter the address there and then send it to the database again for updating. This i have tried: <?php //Söker funktionär med namn if(isset($sok)){ $query = "SELECT * FROM funktionarer WHERE namn LIKE '%$namn%'"; $result = mysql_query($query); if(!$result){ echo "<div class=tabell4><table><tr><td>Funktionären kunde inte hittas. MySQL rapporterar: " . mysql_error() ."</td></tr>"; echo "</table></div>"; } else { $line = mysql_fetch_assoc($result); $s_namn = $line['namn']; $s_adress = $line['adress']; $s_postnr = $line['postnr']; $s_ort = $line['ort']; $s_tel = $line['tel']; $s_email = $line['email']; } } // Stänger anslutningen till vår databas mysql_close($connection); ?> Form: <form method="post" action="<?=$PHP_SELF?>"> <table> <tr> <td width="128" class="text_12">Namn</td> <td width="131"><input type="text" name="namn" size="22" value="<?=$s_namn?>" /></td> </tr> <tr> <td class="text_12">Adress</td> <td><input type="text" name="adress" size="22" value="<?=$s_adress?>" /></td> </tr> <tr> <td class="text_12">Postnr</td> <td><input type="text" name="postnr" size="20" value="<?=$s_postnr?>" /></td> </tr> <tr> <td class="text_12">Ort</td> <td><input type="text" name="ort" size="20" value="<?=$s_ort?>" /></td> </tr> <tr> <td class="text_12">Telnr</td> <td><input type="text" name="tel" size="20" value="<?=$s_tel?>" /></td> </tr> <tr> <td class="text_12">E-mail</td> <td><input type="text" name="email" size="20" value="<?=$s_email?>" /></td> </tr> <tr> <td class="text_12"> </td> <td> </td> </tr> <tr> <td class="text_12"><input class="skicka_knapp3" type="submit" name="sok" value="Sök funktionär" /></td> <td> </td> </tr> </table> </form> Please help! Quote Link to comment https://forums.phpfreaks.com/topic/186843-how-do-i-get-the-results-from-a-mysql-queery-into-a-form/ Share on other sites More sharing options...
wildteen88 Posted January 1, 2010 Share Posted January 1, 2010 You'll need to add your form where I have highlighted $s_email = $line['email']; ADD YOUR FORM HERE } Quote Link to comment https://forums.phpfreaks.com/topic/186843-how-do-i-get-the-results-from-a-mysql-queery-into-a-form/#findComment-986729 Share on other sites More sharing options...
beginann Posted January 1, 2010 Author Share Posted January 1, 2010 Like this you mean (or did I misunderstand you because it doesn´t work...?) <?php //Söker funktionär med namn if(isset($sok)){ $query = "SELECT * FROM funktionarer WHERE namn LIKE '%$namn%'"; $result = mysql_query($query); if(!$result){ echo "<div class=tabell4><table><tr><td>Funktionären kunde inte hittas. MySQL rapporterar: " . mysql_error() ."</td></tr>"; echo "</table></div>"; } else { $line = mysql_fetch_assoc($result); $s_namn = $line['namn']; $s_adress = $line['adress']; $s_postnr = $line['postnr']; $s_ort = $line['ort']; $s_tel = $line['tel']; $s_email = $line['email']; <form method="post" action="<?=$PHP_SELF?>"> <table><tr> td width="128" class="text_12">Namn</td><td width="131"><input type="text" name="namn" size="22" value="<?=$s_namn?>" /></td></tr> <tr><td class="text_12">Adress</td><td><input type="text" name="adress" size="22" value="<?=$s_adress?>" /></td></tr> <tr><td class="text_12">Postnr</td><td><input type="text" name="postnr" size="20" value="<?=$s_postnr?>" /></td></tr> <tr><td class="text_12">Ort</td><td><input type="text" name="ort" size="20" value="<?=$s_ort?>" /></td></tr> <tr><td class="text_12">Telnr</td><td><input type="text" name="tel" size="20" value="<?=$s_tel?>" /></td></tr> <tr><td class="text_12">E-mail</td><td><input type="text" name="email" size="20" value="<?=$s_email?>" /></td></tr> <tr><td class="text_12"> </td><td> </td></tr> <tr><td class="text_12"><input class="skicka_knapp3" type="submit" name="sok" value="Sök funktionär" /></td><td> </td> </tr> </table> </form> } } // Stänger anslutningen till vår databas mysql_close($connection); ?> Quote Link to comment https://forums.phpfreaks.com/topic/186843-how-do-i-get-the-results-from-a-mysql-queery-into-a-form/#findComment-986734 Share on other sites More sharing options...
citricsquid Posted January 1, 2010 Share Posted January 1, 2010 <?php //Söker funktionär med namn if(isset($sok)){ $query = "SELECT * FROM funktionarer WHERE namn LIKE '%$namn%'"; $result = mysql_query($query); if(!$result){ echo "<div class=tabell4><table><tr><td>Funktionären kunde inte hittas. MySQL rapporterar: " . mysql_error() ."</td></tr>"; echo "</table></div>"; } else { $line = mysql_fetch_assoc($result); $s_namn = $line['namn']; $s_adress = $line['adress']; $s_postnr = $line['postnr']; $s_ort = $line['ort']; $s_tel = $line['tel']; $s_email = $line['email']; ?> <form method="post" action="<?=$PHP_SELF?>"> <table><tr> td width="128" class="text_12">Namn</td><td width="131"><input type="text" name="namn" size="22" value="<?=$s_namn?>" /></td></tr> <tr><td class="text_12">Adress</td><td><input type="text" name="adress" size="22" value="<?=$s_adress?>" /></td></tr> <tr><td class="text_12">Postnr</td><td><input type="text" name="postnr" size="20" value="<?=$s_postnr?>" /></td></tr> <tr><td class="text_12">Ort</td><td><input type="text" name="ort" size="20" value="<?=$s_ort?>" /></td></tr> <tr><td class="text_12">Telnr</td><td><input type="text" name="tel" size="20" value="<?=$s_tel?>" /></td></tr> <tr><td class="text_12">E-mail</td><td><input type="text" name="email" size="20" value="<?=$s_email?>" /></td></tr> <tr><td class="text_12"> </td><td> </td></tr> <tr><td class="text_12"><input class="skicka_knapp3" type="submit" name="sok" value="Sök funktionär" /></td><td> </td> </tr> </table> </form> <?php } } // Stänger anslutningen till vår databas mysql_close($connection); ?> Quote Link to comment https://forums.phpfreaks.com/topic/186843-how-do-i-get-the-results-from-a-mysql-queery-into-a-form/#findComment-986737 Share on other sites More sharing options...
gevensen Posted January 1, 2010 Share Posted January 1, 2010 i think it would be for example not value="<?=$s_namn?>" but value="<?php echo $s_namn; ?>" Quote Link to comment https://forums.phpfreaks.com/topic/186843-how-do-i-get-the-results-from-a-mysql-queery-into-a-form/#findComment-986744 Share on other sites More sharing options...
citricsquid Posted January 1, 2010 Share Posted January 1, 2010 i think it would be for example not value="<?=$s_namn?>" but value="<?php echo $s_namn; ?>" If the server supports it then <?=... is a workable replacement for <?php echo... albeit bad practice. Quote Link to comment https://forums.phpfreaks.com/topic/186843-how-do-i-get-the-results-from-a-mysql-queery-into-a-form/#findComment-986762 Share on other sites More sharing options...
beginann Posted January 1, 2010 Author Share Posted January 1, 2010 Now I have tried both examples, but nothing will appear in my form. I will talk to my webhotel and ask if the server support this or if there is a problem there. Quote Link to comment https://forums.phpfreaks.com/topic/186843-how-do-i-get-the-results-from-a-mysql-queery-into-a-form/#findComment-986766 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.