alen Posted December 15, 2006 Share Posted December 15, 2006 i made a code that's supposed to update the news when i submit.here is the structure of the code, http://anigma.sitees.com/edit.txtwhen i enter the "endre" button, it only returns to the main edit.php site.what's wrong here? Quote Link to comment Share on other sites More sharing options...
taith Posted December 15, 2006 Share Posted December 15, 2006 try that[code]<?error_reporting(E_ALL ^ E_NOTICE); mysql_connect("localhost","nancy","blabla"); mysql_select_db("nancy"); if(!isset($_GET["cmd"])){ $result = mysql_query("select * from news order by id"); while($r=mysql_fetch_array($result)){ echo "<p>endre nyheter:</p>"; echo "<a href='edit.php?cmd=edit&id=$r["title"]'>$r["id"]</a><br/>"; }}else{ if(!isset($_POST["submit"])){ $result = mysql_query("SELECT * FROM news WHERE id=$_GET['id']"); $myrow = mysql_fetch_array($result);?><form action="edit.php?cmd=edit" method="post"> <table> <tr> <td>tittel:</td> <td><input type="text" name="title" value="<?php echo $myrow["title"] ?>" size='40'></td> </tr> <tr> <td>forfatter:</td> <td><input type="text" name="author" value="<?php echo $myrow["author"] ?>" size='40'></td> </tr> <tr> <td>tekst:</td> <td><textarea name="news" cols='30' rows='5'><? echo $myrow["news"] ?></textarea></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="endre"></td> </tr> </table> </form><? }elseif($_POST["submit"]){ $result = mysql_query("UPDATE news SET title='$_POST["title"]', `news`='$_POST["news"]', `author`='$_POST["author"]' WHERE id=$id"); echo "query finished."; }}?>[/code] Quote Link to comment Share on other sites More sharing options...
alen Posted December 15, 2006 Author Share Posted December 15, 2006 now i just get:Parse error: parse error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\Server\public_html\news\edit.php on line 10 Quote Link to comment Share on other sites More sharing options...
alen Posted December 15, 2006 Author Share Posted December 15, 2006 nevermind I fixed it. Quote Link to comment Share on other sites More sharing options...
taith Posted December 15, 2006 Share Posted December 15, 2006 sorry... that wasnt tested... this should work...[code]<?error_reporting(E_ALL ^ E_NOTICE); mysql_connect("localhost","nancy","blabla"); mysql_select_db("nancy"); if(!isset($_GET["cmd"])){ $result = mysql_query("select * from news order by id"); while($r=mysql_fetch_array($result)){ echo '<p>endre nyheter:</p><a href="edit.php?cmd=edit&id='.$r[title].'">'.$r[id].'</a><br/>'; }}else{ if(!isset($_POST["submit"])){ $result = mysql_query("SELECT * FROM news WHERE `id`='$_GET[id]'"); $myrow = mysql_fetch_array($result);?><form action="edit.php?cmd=edit" method="post"> <table> <tr> <td>tittel:</td> <td><input type="text" name="title" value="<?php echo $myrow["title"] ?>" size='40'></td> </tr> <tr> <td>forfatter:</td> <td><input type="text" name="author" value="<?php echo $myrow["author"] ?>" size='40'></td> </tr> <tr> <td>tekst:</td> <td><textarea name="news" cols='30' rows='5'><? echo $myrow["news"] ?></textarea></td> </tr> <tr> <td></td> <td><input type="submit" name="submit" value="endre"></td> </tr> </table> </form><? }elseif($_POST["submit"]){ $result = mysql_query("UPDATE news SET title='$_POST[title]', `news`='$_POST[news]', `author`='$_POST[author]' WHERE id=$id"); echo "query finished."; }}?>[/code] Quote Link to comment Share on other sites More sharing options...
alen Posted December 15, 2006 Author Share Posted December 15, 2006 It didn't actually do what I wanted to.. But here's my solution:[code]<?error_reporting(E_ALL ^ E_NOTICE); mysql_connect("localhost","nancy","blabla"); mysql_select_db("nancy"); if(!isset($_GET["cmd"])) { $result = mysql_query("select * from news order by id"); while($r=mysql_fetch_array($result)) { $title=$r["title"]; $id=$r["id"]; echo "<p>endre nyheter:</p>"; echo "<a href='edit.php?cmd=edit&id=$id'>$title</a><br/>"; }}?><?if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit"){ if (!isset($_POST["submit"])) { $id = $_GET["id"]; $sql = "SELECT * FROM news WHERE id=$id"; $result = mysql_query($sql); $myrow = mysql_fetch_array($result); ?> <form action="edit.php" method="post"> <table> <tr> <td>tittel:</td> <td><input type="text" name="title" value="<?php echo $myrow["title"] ?>" size='40'></td> </tr> <tr> <td>forfatter:</td> <td><input type="text" name="author" value="<?php echo $myrow["author"] ?>" size='40'></td> </tr> <tr> <td>tekst:</td> <td><textarea name="news" cols='30' rows='5'><? echo $myrow["news"] ?></textarea></td> </tr> <tr> <td></td><br> <td><input type="hidden" name="cmd" value="edit"><input type="submit" name="submit" value="endre"></td> </tr> </table> </form><? } ?><? if ($_POST["submit"]) { $title = $_POST["title"]; $news = $_POST["news"]; $author = $_POST["author"]; $sql = "UPDATE news SET title='$title',news='$news',author='$author' WHERE id=$id"; $result = mysql_query($sql); echo "query finished."; }}?>[/code]It works fine. But when I echo "query finished", I can see the "endre nyheter" and the link to the news item. I want query finished. to come on a own page. How would I manage to do that? 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.