frilund Posted September 15, 2013 Share Posted September 15, 2013 <html> <head> <meta charset="iso-8859-1" /> <title> Hjem </title> </head> <body> <?php include 'config.php'; session_start(); if(!session_is_registered(mitbrugernavn)){ ?> <form action="tjek.php" method="post"> Brugernavn: <input type="text" name="mitbrugernavn"> </p> Kodeord: <input type="password" name="mitkodeord"> </p> <input type="submit" value="Login"> </form> <?php } else { ?> </p> Du er nu logget ind! Velkommen <? print $_SESSION['mitbrugernavn']; ?> </p> <li> <a href="logout.php"> Log ud </a> </li> </p> <li> <a href="opret.php"> Opret ny konto </a> </li> <li> <a href="medlemmer.php">Oprettede kontoer</a> </li> </p> <? $con = mysql_connect("localhost","HIDDEN","HIDDEN"); if (!$con) { die('Kunne ikke tilslutte: ' . mysql_error()); } mysql_select_db("HIDDEN", $con); $result = mysql_query("select count(*) FROM medlemmer"); $row = mysql_fetch_array($result); $total = $row[0]; echo "Antal medlemmer: " . $total; } ?> </p> </p> <?php $aktion= $_GET['action']; if($aktion == "slet"){ mysql_query("DELETE FROM news WHERE name=$nName"); echo "Nyheden er nu slettet"; echo ('<meta http-equiv="refresh" content="3;url=tilfoj-nyheder.php">'); } else { echo "Kunne ikke slette nyheden"; } $loadNews = mysql_query("SELECT * FROM news ORDER BY id DESC") or die(mysql_error()); if(mysql_num_rows($loadNews) == 0) { echo "Der er ikke blevet tilføjet nogle nyheder."; } else { while($showNews = mysql_fetch_array($loadNews)) { $nName = stripslashes($showNews["name"]); $nAuthor = stripslashes($showNews["author"]); $nText = nl2br(stripslashes($showNews["text"])); $nDate = $showNews["date"]; ?> <div> <div align="center" style="border-style:solid; margin:3px; width:400px; height:auto;"> <b> <?php print "$nName"; ?> </b><br /> <i>Skrevet af <? print "$nAuthor ,"; ?> d. <?php print "$nDate"; ?> </i><br /> <? print "$nText"; ?> <br /><br /> </div> </br> <? if(session_is_registered(mitbrugernavn)){ ?> <form action='?action=slet' method="POST"> <input type="submit" value="slet"> </form> <? } ?> </div> <? } } if(session_is_registered(mitbrugernavn)){ echo "<a href=\"tilfoj-nyheder.php\" title=\"Tilføj nyhed\">Tilføj nyhed</a>"; } ?> </body> </html> Hello! I am trying to make a delete button for my news, but I have no idea how it works. The code for the button starts at line 68. PS. Im new here correct me if posting this wrong! Thanks in advance! Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 15, 2013 Share Posted September 15, 2013 (edited) this reply has nothing to do with your question, but the code you have is so out of date i'm surprised it even runs. here's a list of problems in it - 1) the session_start() statement needs to come before you output any characters to the browser 2) session_is_registered was depreciated 10-11 years ago and has been removed as of php5.4. you should test if the $_SESSION variable isset() instead. 3) the mysql_ database library functions are depreciated starting in php5.5. all new code should be written using mysqli or PDO database libraries. 4) if you find yourself using stripslashes() when you retrieve data from a database, either the data was improperly escaped when it was inserted or magic_quotes_runtime is on and should be turned off (all magic_quotes_ functionality is removed as of php5.4.) wherever you found this code or learned php, the information is out of date. it would be best if you started over using current and up-to-date php standards. Edited September 15, 2013 by mac_gyver Quote Link to comment Share on other sites More sharing options...
Barand Posted September 15, 2013 Share Posted September 15, 2013 When using string values in a query they should be enclosed in single quotes otherwise SQL treats them as column names. WHERE name = $nName should be WHERE name = '$nName' Quote Link to comment Share on other sites More sharing options...
frilund Posted September 15, 2013 Author Share Posted September 15, 2013 #3 Didn't work sadly but thanks anyway Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 15, 2013 Share Posted September 15, 2013 there's no code setting the $nName variable that is being used in the DELETE query. sorry, but as suggested, your best bet is to start over with current php programming information and actually write the code to do what you want it to do. Quote Link to comment 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.