(script) not posting in right category ?

hi , i have a script that includes forum functions , they had the topic list and the start a new topic on the same page , instead of that i made a new php file with start new topic functions so it shows on another page kinda like smf … it works fine apart from it post in a wrong category.

so would be happy if anyone could take a look at the code and tell me with is the wrong code :

category.php[php]<?php

$id = mysql_real_escape_string(mysql_real_escape_string($_GET[‘id’]));
$sidor_totalt = 1;

if (isset($_POST[‘new_thread’]))
{

$subject = mysql_real_escape_string($_POST[‘subject’]);
$text = mysql_real_escape_string($_POST[‘text’]);

if (trim(empty($subject)) or trim(empty($text)))
{ echo ""; }

else
{

mysql_query(“INSERT INTO forum_thread (categoryid, subject, posted, last_answer)
VALUES(’$id’, ‘$subject’, ‘$current_date’, ‘$current_date’)”) or die(mysql_error());

$threadid = mysql_insert_id();
$userid = $_SESSION[‘id’];
mysql_query(“INSERT INTO forum_answer (userid, threadid, text, date)
VALUES(’$userid’, ‘$threadid’, ‘$text’, ‘$current_date’)”) or die(mysql_error());

echo "";

}

} [/php]

newtopic.php [php]<?php

$id = mysql_real_escape_string(mysql_real_escape_string($_GET[‘id’]));
$sidor_totalt = 1;

if (isset($_POST[‘new_thread’]))
{

$subject = mysql_real_escape_string($_POST[‘subject’]);
$text = mysql_real_escape_string($_POST[‘text’]);

if (trim(empty($subject)) or trim(empty($text)))
{ echo ""; }

else
{

mysql_query(“INSERT INTO forum_thread (categoryid, subject, posted, last_answer)
VALUES(’$id’, ‘$subject’, ‘$current_date’, ‘$current_date’)”) or die(mysql_error());

$threadid = mysql_insert_id();
$userid = $_SESSION[‘id’];
mysql_query(“INSERT INTO forum_answer (userid, threadid, text, date)
VALUES(’$userid’, ‘$threadid’, ‘$text’, ‘$current_date’)”) or die(mysql_error());

echo "";

}

}

?>




 Starta en ny tråd

 Här kan du starta en ny tråd och disktera saker med andra på <?php echo $sitename; ?>.

 
 


 Rubrik:

<?php if (isset($subject)) { echo ' '; } else { echo ' '; } ?>

 Innehåll:

 <?php if (isset($text)) { echo $text; } ?>



 

[/php]

just for the record , when i post the url goes like this /page.php?action=forumcategory&id= instead of /page.php?action=forumcategory&id=4

Thank you !!

Does _GET[‘id’] get assigned an id ?
can you echo it out see what you get and reply

yh i test both [php] echo $_GET[‘id’];[/php] and [php] echo $id;[/php] and got the right category number

Maybe take the echo out.

[php]<?php echo $id; ?>[/php]

[php]<?php $id; ?>[/php]

Sorry I cant see why if you have the right number assiged to the $id why it will not work with echo.
try print $id; instead

see if the id is still assigned before you post so you know its right.

its not the problem , i just noticed thati n forumcategory.php its shows the id but inte the newtopic.php there is no id showing ? ,

Where do you get the id from? is it a post then try $_POST[‘id’] instead of GET

the thing is why does not the code work when i put it in a sperate file , when i have the codes in the same file then it works good but when i put the post function in another file then it wont work …

its not POST , it use _GET and this code works fine , so there is no coding errors iguess …

So what is being sent in the url to this page can you give me example

what is the url that sends you to :category.php
what is the url that sends you to :newtopic.php

Because $_GET is for getting the information from the url.
So if there is id= instead of id=12 then you will have nothing assigned to $_GET[‘id’].

You will need to look at the other page that sends you to the newtopic.php to find out why it is not sending the id.

i am kinda confused so … this is the whole code posting and category functions, it works fine while post and reading . there is all you need in this code

all.php[php]<?php

$id = mysql_real_escape_string(mysql_real_escape_string($_GET[‘id’]));
$sidor_totalt = 1;

if (isset($_POST[‘new_thread’]))
{

$subject = mysql_real_escape_string($_POST[‘subject’]);
$text = mysql_real_escape_string($_POST[‘text’]);

if (trim(empty($subject)) or trim(empty($text)))
{ echo ""; }

else
{

mysql_query(“INSERT INTO forum_thread (categoryid, subject, posted, last_answer)
VALUES(’$id’, ‘$subject’, ‘$current_date’, ‘$current_date’)”) or die(mysql_error());

$threadid = mysql_insert_id();
$userid = $_SESSION[‘id’];
mysql_query(“INSERT INTO forum_answer (userid, threadid, text, date)
VALUES(’$userid’, ‘$threadid’, ‘$text’, ‘$current_date’)”) or die(mysql_error());

echo "";

}

}

// ------------------------------------------------------------------ //
// Paging-funktionen här under kommer från www.webdesignskolan.se. //
// ------------------------------------------------------------------ //

// SIDNUMMER: om @GET är definierad används innehållet som sidnummer, annars används angivet sidnummer
if (isset($_GET[‘sida’])) {
$sida = mysql_real_escape_string(trim($_GET[‘sida’]));
}
else { $sida = 1; }

// ange antal rader från sökresultatet som ska visas per sida
$limit = 15;
// Antal sidlänkar som ska visas i navigeringen, exempel: | 1 2 3 4 5 |
$numLinks = 5;

// intervall på antal rader som ska hämtas från MySQL
$offset = ($sida - 1) * $limit;

// sökfrågan som hämtar information från den angivna tabellen - intervallet för visningen anges med LIMIT
$query = “SELECT * FROM forum_thread WHERE categoryid = '”. $id ."’ AND pinned = ‘0’ ORDER BY last_answer DESC LIMIT $offset, $limit";
$result = mysql_query($query) or die(mysql_error());

// räknar antalet rader och sparar resultatet i arrayen “antal_rader”
$result_count = mysql_query(“SELECT COUNT(*) AS antal_rader FROM forum_thread WHERE categoryid = '”. $id ."’ AND pinned = ‘0’") or die(mysql_error());
$numrows = mysql_fetch_array ($result_count);

// beräknar antal rader som ska visas per sida
if ($numrows[‘antal_rader’] > 0 ) {
$sidor_totalt = (ceil($numrows[‘antal_rader’] / $limit) );
}

#########################################################################################
// START AV FUNKTION FÖR NAVIGERING 1:
// << första < föregående | 1 2 3 4 5 | nästa > sista >>
#########################################################################################
function sidnavigering1($sida, $sidor_totalt) {
global $numLinks;
// beräknar startsidan
if ($sidor_totalt > $numLinks){
$startLink = $sida - floor($numLinks / 2);
if ($startLink >($sidor_totalt - $numLinks)){
$startLink = $sidor_totalt - $numLinks + 1;
}
}
else $startLink = 1;
// beräknar sista sidan
if ($startLink < 1) $startLink = 1;
$stopLink = $startLink + $numLinks - 1;
if ($stopLink > $sidor_totalt) $stopLink = $sidor_totalt;

//-------------------------------------------------------------------------------------
// visar “<< första < föregående " om INTE den första sidan visas
if ($sida > 1) {
echo “« <a href=“page.php?name=forumcategory&id=”. mysql_real_escape_string($_GET[‘id’]) .”&sida=1”>första “;
echo “‹ <a href=“page.php?name=forumcategory&id=”. mysql_real_escape_string($_GET[‘id’]) .”&sida=” . ($sida - 1) . “”>föregående ";
}
else echo ‘« första ‹ föregående’;

//-------------------------------------------------------------------------------------
// skriver ut sidlänkar i navigeringen
// 1 2 3 4 5 osv…
if($sidor_totalt > 0) {
echo ’ | ‘;
for ($i=$startLink; $i<=$stopLink; $i++){
if ($i == $sida){
echo ‘’.$i.’’;
}
else {
echo " <a href=“page.php?name=forumcategory&id=”. mysql_real_escape_string($_GET[‘id’]) ."&sida=$i">$i";
}
echo ’ ';
}
echo ’ | ';
}
//-------------------------------------------------------------------------------------
// visar " nästa > sista >> " om INTE den sista sidan visas
if ($sida < $sidor_totalt) {
echo " <a href=“page.php?name=forumcategory&id=”. mysql_real_escape_string($_GET[‘id’]) ."&sida=".($sida + 1)."">nästa ›";
echo " <a href=“page.php?name=forumcategory&id=”. mysql_real_escape_string($_GET[‘id’]) ."&sida=$sidor_totalt">sista »";
}
else echo ‘nästa › sista »’;
}
// SLUT FUNKTION NAVIGERING 1
#########################################################################################

#########################################################################################
// START AV FUNKTION FÖR NAVIGERING 2:
// << första < föregående | sidan 1 av 25 | nästa > sista >>
#########################################################################################
function sidnavigering2($sida, $sidor_totalt) {
//-------------------------------------------------------------------------------------
// visar “<< första < föregående " om INTE den första sidan visas
if ($sida > 1) {
echo “« <a href=“page.php?name=forumcategory&id=”. mysql_real_escape_string($_GET[‘id’]) .”&sida=1”>första “;
echo “‹ <a href=“page.php?name=forumcategory&id=”. mysql_real_escape_string($_GET[‘id’]) .”&sida=”.($sida - 1)."">föregående “;
}
else echo ‘« första ‹ föregående’;
//-------------------------------------------------------------------------------------
// Visar “| sidan 1 av 25 | "
echo " | “;
echo 'sidan ‘.($sida).’ av ’ .($sidor_totalt);
echo " | “;
//-------------------------------------------------------------------------------------
// visar " nästa > sista >> " om INTE den sista sidan visas
if ($sida < $sidor_totalt) {
echo " <a href=“page.php?name=forumcategory&id=”. mysql_real_escape_string($_GET[‘id’]) .”&sida=”.($sida + 1).””>nästa ›";
echo " <a href=“page.php?name=forumcategory&id=”. mysql_real_escape_string($_GET[‘id’]) ."&sida=$sidor_totalt">sista »";
}
else echo ‘nästa › sista »’;
}
// SLUT FUNKTION NAVIGERING 2
#########################################################################################

//////////////////////////////////////////////////////////////////////////
// HÄR VISAS MENYN FÖR NAVIGERING 1 , “newtopic” länk och userpath.
// << första < föregående | 1 2 3 4 5 | nästa > sista >>

sidnavigering1($sida, $sidor_totalt); echo’<img style="float:right;padding-right:20px;"src=“images/starttopic.png” />’;

//////////////////////////////////////////////////////////////////////////

echo ‘

’;
// HTML-tabellens formatering - tabellstart
echo “

”;
echo “”;

if (!isset($_GET[‘sida’]))
{

$pinned_sql = mysql_query(“SELECT * FROM forum_thread WHERE categoryid = '”. $id ."’ AND pinned = ‘1’ ORDER BY last_answer DESC") or die(mysql_error());

while ( $pinned = mysql_fetch_array ( $pinned_sql ))
{

if ($pinned[‘locked’] == 1)
{ $locked = ‘’; }
elseif ($pinned[‘locked’] == 0)
{ $locked = ‘’; }

echo "<tr bgcolor='#A4BB9A'><td>";
echo $locked .' <img src="images/stickytopic.gif" /><a href="page.php?name=forumtopic&id='. $pinned['id'] .'"><b>'. $pinned['subject'] .'</b></a>'; 
echo "</td><td><b>";  
echo $pinned['visits']; 
echo "</b></td><td><b>";  
echo $pinned['last_answer'];  
echo "</b></td></tr>";

}

}

// hämtar resultatrader från tabellen
while($row = mysql_fetch_array( $result )) {
// skriver ut innehållet i raderna till HTML-tabellen

if ($row[‘locked’] == 1)
{ $locked = ‘’; }
elseif ($row[‘locked’] == 0)
{ $locked = ‘’; }

echo "<tr><td>";
echo $locked .' <a href="page.php?name=forumtopic&id='. $row['id'] .'">'. $row['subject'] .'</a>'; 
echo "</td><td>";  
echo $row['visits']; 
echo "</td><td>";  
echo $row['last_answer'];  
echo "</td></tr>";

}

// HTML-tabellens formatering - tabellend
echo “

Tråd Visningar Senaste svaret
”;
echo “
”;

//////////////////////////////////////////////////////////////////////////
// HÄR VISAS MENYN FÖR NAVIGERING 2:
// << första < föregående | sidan 1 av 25 | nästa > sista >>
sidnavigering2($sida, $sidor_totalt);
//////////////////////////////////////////////////////////////////////////

?>




 Starta en ny tråd

 Här kan du starta en ny tråd och disktera saker med andra på <?php echo $sitename; ?>.

 
 


 Rubrik:

<?php if (isset($subject)) { echo ' '; } else { echo ' '; } ?>

 Innehåll:

 <?php if (isset($text)) { echo $text; } ?>



 

[/php]

could you please do it for me ? i mean seprate the posting code in another file ? it would be esaier …

Ok I will try not to confuse you.
rename these files the other way around
category.php
newtopic.php

See if you get the id in the newtopic.php this time and not in the category.php, if it does then it has nothing to do with the code you have shown me as its working right, its when you click from the forum to the thread the url does not contain the id.

newthread.php?threadid=123 <— this has the threadid and no id
instead of
category.php?id=234 <— this has the right id for the forum in the url so GET works

Which ever way it will be it wont have the right id you will need to either add session or figure out a way to add it to the url, so its sent to newthread.php , the same way its being sent to category.php.

so instead of get[id] with be session[‘id’] for your newthread.php

ohh i think i understand now :slight_smile: but thing why should i add session[‘id’] when i am wanting to have the id of the category … sorry btw i am learing that why i dont get it that fast

if you cant send the id of the category in the url then you will have to use sessions to do it instead.

Another way around sending the information from one page to another.

as you already have the code , could you please show what to change and what to add ? :slight_smile:

As you have $userid as the session id [php]$userid = $_SESSION[‘id’]; [/php]
You need to find the one for the foumid

you can try adding to category.php
[php]
Print_r ($_SESSION);
[/php]
tell me the results printed to the screen

its shows this Array ( [username] => admin [id] => 1 )

ok try adding it to the newtopic.php
How do you get to the newtopic.php ?
Do you get sent from the category.php to the newtopic.php or another way ?

You make it very hard, I ask you a question that only you can awswer and you do not answer me you ask another question.
Because I do not have the code I have code you have shown me but not the code I need to find out what is happening.

I aks for the url why wont you send the url that send you to the both pages just put www.example.com where the domain name is.

ohh sorry , i will try answering all your questions !

i added it on newtopic.php and its shows the same “Array ( [username] => admin [id] => 1 )”

to get to the newtopic.php file i use http://site.com/page.php?action=newtopic (i include the link in the category.php)

url to categorty http://site.com/page.php?action=forumcategory
url to newtopic http://site.com/page.php?action=newtopic

and is there anything more you need? :slight_smile:

Do the same for page.php

Maybe I am missing something in page.php but it has to send the ID somehow

[php]
Print_r ($_SESSION);
[/php]

again Array ( [username] => admin [id] => 1 )

Sponsor our Newsletter | Privacy Policy | Terms of Service