Jump to content

[SOLVED] A small problem with links


Steppio

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.