wazda21 Posted January 27, 2010 Share Posted January 27, 2010 Hello all, I have this php code and I would like to write it to my datebase (tables already exists). Then I want to show the input in a new screen. Anyone any idea how I'll be able to fix it? (I'm sorry but the info in between are in dutch) Thx <?php if($_SERVER['REQUEST_METHOD']=="POST"){ // het formulier werd verzonden //maak een verbinding met de database mysql_connect("localhost","wsb","macuser"); mysql_select_db("wsb"); //bestand uploaden //is het bestand succesvol geupload? if (isset($_FILES['idoc']) && $_FILES['idoc']['error'] == UPLOAD_ERR_OK){ //bepaalde bestandstypes hebben we liever niet op onze server $illegal_extensions = array("php","exe","asp","php5","phtml"); $filename = strtolower($_FILES['idoc']['name']); $ext = (end(explode(".",$filename))); if(!in_array($ext,$illegal_extensions)){ //de locatie waar het bestand geupload wordt moet beschrijfbaar zijn door de webserver //rechten instellen op schrijven voor iedereen op deze map $target_path = "./uploads/"; $target_path = $target_path . basename( $_FILES['idoc']['name']); //het geuploade bestand verplaatsen naar de juiste locatie //let op: een bestaand bestand met dezelfde naam zal overschreven worden if(move_uploaded_file($_FILES['idoc']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['idoc']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } } else{ echo "Ongeldig bestandsformaat"; } } //voeg het bericht toe aan de database //amerikaans datumnotatie: YYYY/MM/DD //de meeste servers zijn zo ingesteld //indien nodig de datumnotatie aanpassen naar de europese standaard /* SQL om de tabel aan te maken: CREATE TABLE `berichten` ( `berichtID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `taal` TEXT NOT NULL , `titel` TEXT NOT NULL , `auteur` TEXT NOT NULL , `doc` TEXT NOT NULL , `datum` DATE NOT NULL , `website` TEXT NOT NULL , `nieuwsbrief` TEXT NOT NULL , `totdatum` INT NOT NULL , `inhoud` LONGTEXT NOT NULL ); */ $query = mysql_query("insert into berichten (taal,titel,auteur,doc,datum,website,nieuwsbrief,totdatum,inhoud) values ( '".($_POST['taal'])."', '".($_POST['ititel'])."', '".($_POST['iauteur'])."', '".($filename)."', '".($_POST['idatumjaar']."/".$_POST['idatummaand']."/".$_POST['idatumdag'])."', '".($_POST['iwebsite'])."', '".($_POST['ibron'])."', '".($_POST['itotjaar']."/".$_POST['itotmaand']."/".$_POST['itotdag'])."', '".($_POST['iinhoud'])."' ) "); //mysql_real_escape_string om te vermijden dat er kwetsbare code meegestuurd wordt in het formulier //toon een bericht dat de invoer gelukt is ?> <h2>Bericht toegevoegd</h2> <p>Uw bericht werd toegevoegd aan de website.</p> <?php } else { // het formulier werd nog niet verzonden en wordt dus getoond ?> <h2>Nieuw bericht</h2> <form name="form1" action="insert.php" method="post" enctype="multipart/form-data" onsubmit="MM_validateForm('Auteur','','R','Titel nl','','R','Inhoud nl','','R');return document.MM_returnValue"> <table width="100%" align="center" cellpadding="1"> <tbody><tr valign="baseline"> <td colspan="2" align="right"><div align="left">Zorg ervoor om elk tekstvak met een sterretje naast zeker in te vullen.<br> Gebruik de opmaakknoppen boven het inhoud-tekstvak om de tekst op te maken. Maak eerst een selectie van uw tekst en klik dan op het icoontje dat u wil toewijzen. </div></td> </tr> <tr valign="baseline"> <td colspan="2" align="right"> <div align="left"> <input name="Submit" class="knop" value="Publiceren" type="submit"> <input value="Terug " onclick="history.back()" class="knop" name="button" type="button"> </div></td> </tr> <tr> <td align="right" height="15"> <div align="left"> <strong>Taal : </strong></div></td> <td width="77%" align="right" height="15"><div align="left"><strong> <select name="taal" id="taal"> <option selected="selected" value="nl">Nederlands</option> <option value="fr">Français</option> </select> </strong></div></td> </tr> <tr valign="baseline"> <td align="right" height="15"> <div align="left"> <strong>Titel : </strong></div></td> <td width="77%" align="right" height="15"><div align="left"><strong> <input name="ititel" id="Titel nl" size="50" maxlength="100" type="text"> <font color="#ff0000">(*) </font> </strong></div></td> </tr> <tr valign="baseline"> <td align="right"> <div align="left"><strong>Auteur : </strong></div></td> <td align="right"> <div align="left"><strong> <input name="iauteur" id="Auteur" size="50" maxlength="50" type="text"> <font color="#ff0000">(*) </font> </strong></div></td> </tr> <tr valign="baseline"> <td align="right"><div align="left"><strong>Foto, pdf-doc,... </strong></div></td> <td width="77%"> <input name="idoc" class="knop" id="idoc" size="32" maxlength="200" type="file"> <br> <font color="#ff0000" size="1">geen enkelvoudige aanhalingstekens gebruiken in de bestandsnaam!</font></td> </tr> <tr valign="baseline"> <td align="right"><div align="left"><strong>Datum:</strong> </div></td> <td align="right"><div align="left"> <div align="left"> <select name="idatumdag" id="idatumdag" onchange="bereken()"> <option value="1">01</option> <option value="2">02</option> <option value="3">03</option> <option value="4">04</option> <option value="5">05</option> <option value="6">06</option> <option value="7">07</option> <option value="8">08</option> <option value="9">09</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25" selected="selected">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select name="idatummaand" id="idatummaand" onchange="bereken()"> <option value="1" selected="selected">01</option> <option value="2">02</option> <option value="3">03</option> <option value="4">04</option> <option value="5">05</option> <option value="6">06</option> <option value="7">07</option> <option value="8">08</option> <option value="9">09</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> </select> <select name="idatumjaar" id="idatumjaar" onchange="bereken()"> <option value="2004">2004</option> <option value="2005">2005</option> <option value="2006">2006</option> <option value="2007">2007</option> <option value="2008">2008</option> <option value="2009">2009</option> <option value="2010" selected="selected">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> <option value="2013">2013</option> <option value="2014">2014</option> </select> <input name="idatum" id="idatum" value="25/1/2010" type="hidden"> </div></div></td> </tr> <tr valign="baseline"> <td align="right"><div align="left"><strong>Op website: </strong></div></td> <td align="right"><div align="left"><strong> <select name="iwebsite" id="iwebsite"> <option value="Ja">Ja</option> <option value="Neen" selected="selected">Neen</option> </select> </strong></div></td> </tr> <tr valign="baseline"> <td align="right"><div align="left"><strong>Nieuwsbrief: </strong></div></td> <td align="right"><div align="left"><strong> <select name="ibron" id="ibron"> <option value="Ja">Ja</option> <option value="Neen" selected="selected">Neen</option> </select> </strong></div></td> </tr> <tr valign="baseline"> <td width="23%" align="right"> <div align="left"><strong>Publiceren tot: </strong></div></td> <td align="right"> <div align="left"> <div align="left"> <select name="itotdag" id="itotdag" onchange="bereken()"> <option value="1">01</option> <option value="2">02</option> <option value="3">03</option> <option value="4">04</option> <option value="5">05</option> <option value="6">06</option> <option value="7">07</option> <option value="8">08</option> <option value="9">09</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25" selected="selected">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select name="itotmaand" id="itotmaand" onchange="bereken()"> <option value="1" selected="selected">01</option> <option value="2">02</option> <option value="3">03</option> <option value="4">04</option> <option value="5">05</option> <option value="6">06</option> <option value="7">07</option> <option value="8">08</option> <option value="9">09</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> </select> <select name="itotjaar" id="itotjaar" onchange="bereken()"> <option value="2004">2004</option> <option value="2005">2005</option> <option value="2006">2006</option> <option value="2007">2007</option> <option value="2008">2008</option> <option value="2009">2009</option> <option value="2010">2010</option> <option value="2011" selected="selected">2011</option> <option value="2012">2012</option> <option value="2013">2013</option> <option value="2014">2014</option> </select> <input name="itot" id="itot" value="25/1/2011" type="hidden"> </div></div></td> </tr> <tr valign="baseline"> <td colspan="2" align="right" height="10"> <div align="left"><font size="1"> </font></div> <div align="left"> <strong>Inhoud</strong> <font color="#ff0000">(*) <span class="style1">(gelieve in de eerste 200 lettertekens van de tekst geen opmaak te voorzien. Dit kan onvoorziene gevolgen hebben in het overzicht van de berichten. <br> Om een nieuwe regel te beginnen zonder tussenruimte: SHIFT-ENTER drukken in plaats van ENTER (SHIFT = pijltje omhoog om een hoofdletter te maken, net boven de CTRL-toets)</span></font></div></td> </tr> <tr valign="bottom"> <td colspan="2" align="right"> <div align="left"> <textarea name="iinhoud" cols="70" rows="20" id="Inhoud nl"></textarea> </div></td> </tr> </tbody></table> <!-- <input type="hidden" name="iid" value="" size="32"> --> <input name="iuserid" value="demo" size="12" maxlength="12" type="hidden"> </form> <?php } ?> <!-- InstanceEndEditable --></td> </tr> </tbody></table> <p> </p> <!-- InstanceEnd --></body></html> Quote Link to comment https://forums.phpfreaks.com/topic/190032-how-to-insert-and-to-call-out-of-mysql/ Share on other sites More sharing options...
kickstart Posted January 27, 2010 Share Posted January 27, 2010 Hi What is the error you appear to be having. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/190032-how-to-insert-and-to-call-out-of-mysql/#findComment-1002701 Share on other sites More sharing options...
wazda21 Posted January 27, 2010 Author Share Posted January 27, 2010 Hi Keith, I'm trying to include the output file (output.php) into a new webpage, but all the webbrowser shows is a blanc page, with any content. I don't get it...? <?php include("output.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/190032-how-to-insert-and-to-call-out-of-mysql/#findComment-1002728 Share on other sites More sharing options...
wazda21 Posted January 28, 2010 Author Share Posted January 28, 2010 Btw, here's the code of the output.php <? $username="wsb"; $password="macuser"; $database="wsb"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM berichten ORDER BY titel DESC"; $result=mysql_query($query); $num=mysql_num_rows($result); $ret = mysql_query($query) or die(mysql_error()); mysql_close(); $i=0; while ($i < $num) { $taal=mysql_result($result,$i,"taal"); $titel=mysql_result($result,$i,"titel"); $auteur=mysql_result($result,$i,"auteur"); $doc=mysql_result($result,$i,"doc"); $datum=mysql_result($result,$i,"datum"); $website=mysql_result($result,$i,"website"); $nieuwsbrief=mysql_result($result,$i,"nieuwsbrief"); $totdatum=mysql_result($result,$i,"totdatum"); $inhoud=mysql_result($result,$i,"inhoud"); echo "<br><h2><font face=Arial color=#3366FF>$titel</font></h2> <font face=Arial size=2 color=#999999>$inhoud</font></br> <br><i><font face=Arial size=1 color=#222222>$auteur</font></i></br>"; $i++; } ?> <? echo $variablename; ?> Quote Link to comment https://forums.phpfreaks.com/topic/190032-how-to-insert-and-to-call-out-of-mysql/#findComment-1002743 Share on other sites More sharing options...
fenway Posted January 28, 2010 Share Posted January 28, 2010 This seems like a php question. Quote Link to comment https://forums.phpfreaks.com/topic/190032-how-to-insert-and-to-call-out-of-mysql/#findComment-1002792 Share on other sites More sharing options...
kickstart Posted January 28, 2010 Share Posted January 28, 2010 Hi Has anything been inserted to the database? Output.php is pretty simple and I would expect it to put something out (might be worth putting something like echo 'hello'; at the top of it just to make sure it is being called. Most likely issue appears to me to be that your insert is failing. Also, use mysql_real_escape_string to avoid problems with sql injection attacks. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/190032-how-to-insert-and-to-call-out-of-mysql/#findComment-1002964 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.