Steppio Posted March 26, 2007 Share Posted March 26, 2007 I'm trying to add Delete/Edit links to the base news articles, but i have 2 problems, my code for the links are as follows: <td class="dboxleft"> </td> <?php echo "<td class='dboxmain' colspan='3' style='". get_news_bg($user) ."'>$news"; if (isset($_SESSION['valid_user'])) { echo "<br /><a href='deleteid.php?id=$id'>Delete/</a>"; echo "<a href='editnews.php?head=$head'>Edit</a>"; } ?> </td> My first problem is that i would like to add another variable to the link called $news, so i figured the code would look something like this?: echo "<a href='editnews.php?head=$head;news=$news'>Edit</a>"; However when i tried this it prints the entire news article as the link, any ideas? Secondly when i use $_GET for the news and head variables on the editnews.php page, only the first word comes out for the title and nothing comes out for the news. My code is below: <?php require('head.inc'); ?> <center> <?php $head = $_GET['head']; $news = $_GET['news']; ?> <form class="AddNews" method="post" action="update_news.php?<?php echo strip_tags(SID); ?>"> <br><center> Add an article: <br> Title: <input type="text" class="sub1" name="add_title" size="40" value=<?php echo "$head;>" ?><br> Content: <textarea cols="70" rows="8" class="sub1" name="add_news"><?php echo $news;?></textarea><br> <input type="submit" class="sub" value="Update"> </form> <br> </td> </tr> <?php require('foot.inc'); ?> For example, 1 of my titles is 'Sooty's downward spiral', but only Sooty comes through in the input text field. If you can help me with this problem i would be incredibly grateful as i'm an idiot and this no doubt simple premise is beyond me. Thanks. Quote Link to comment Share on other sites More sharing options...
papaface Posted March 26, 2007 Share Posted March 26, 2007 Use code tags. One thing, this: echo "<a href='editnews.php?head=$head;news=$news'>Edit should be: echo "<a href='editnews.php?head=$head&&news=$news'>Edit</a> Quote Link to comment Share on other sites More sharing options...
per1os Posted March 26, 2007 Share Posted March 26, 2007 echo "<a href='editnews.php?head=$head&news=$news'>Edit</a> Only need one & =) Quote Link to comment Share on other sites More sharing options...
papaface Posted March 26, 2007 Share Posted March 26, 2007 You can use two. I prefer to use two. Its a personal preference. Quote Link to comment Share on other sites More sharing options...
Steppio Posted March 26, 2007 Author Share Posted March 26, 2007 OK i tried a different approach because i didnt think it a good idea to send entire news articles in the link, so instead i'm sending the ID of the article in the head, and on the editnews.php page i'm trying to use the ID with a custom function to retrieve the header and news and put them into a text input box and a textarea box. My custom function code is below: function edit_news_id($id) { $conn = db_connect(); $result = $conn->query("SELECT news, newshead FROM news WHERE id='$id'"); if (!$result){ throw new Exception('Could not execute query'); } } And the link code: echo "<a href='editnews.php?id=$id'>Edit</a>"; And the page code: <?php require('head.inc'); ?> <center> <?php $id = $_GET['id']; edit_news_id($id); echo $news; echo $head; ?> <form class="AddNews" method="post" action="add_news.php?<?php echo strip_tags(SID); ?>"> <br><center> Add an article: <br> Title: <input type="text" class="sub1" name="add_title" size="40" value=<?php echo "$head;>" ?><br> Content: <textarea cols="70" rows="8" class="sub1" name="add_news"><?php echo $news;?></textarea><br> <input type="submit" class="sub" value="Update"> </form> <br> </td> </tr> <?php require('foot.inc'); ?> The problem is that it's returning nothing, i only used the echo $news and echo $head commands to see if there was any result coming from the function, but there isnt. Could i use a while loop above the call to the function to return the results? Quote Link to comment Share on other sites More sharing options...
Steppio Posted March 26, 2007 Author Share Posted March 26, 2007 OK i've changed it around again and this time everything is working OK except for the title, it still only comes out as 1 word, for example: 'New news article 4' comes out as: 'New' the code for the input box is: Title: <input type="text" class="sub1" name="add_title" size="40" value=<?php echo "$head>"; ?><br> any ideas? Quote Link to comment Share on other sites More sharing options...
Steppio Posted March 26, 2007 Author Share Posted March 26, 2007 Silly me, was just me getting the paranthesis wrong again, sorted now thanks for all your help. 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.