PDA

View Full Version : Help needed please....Forums Code..


JackSparrow
04-27-2005, 11:30 PM
I am currently trying to code a forum onto my site. I have taken a source script and ammended it to suit what i need however it is not working as it should and i cant pinpoint the fault. Whenever i click to add a new topic it just sort of reloads the current page without doing anything or adding anything nor displaying any errors.

Here is the function code i have for adding a new topic:
function addtopic () {
global $topicname;
$new_topicname = addslashes($topicname);
$topic_query = mysql_query("INSERT INTO topics VALUES ('NULL','$new_topicname')");
if (mysql_error() != "") {
showheader("MySQL Error ".mysql_error());
?>
<br><p><center><b><FONT SIZE="-1" FACE="Trebuchet MS,Arial,Helvetica">There was a MySQL Error -- <?php echo mysql_error() ?></b></center></p>
<?php
showfooter();
exit;
}


and here is the addtopic page code:

<?php
require( './functions.php');

showheader("Here are your Topics");
?>

<TABLE BORDER=0 WIDTH=100% CELLSPACING=3 CELLPADDING=5>
<TR>
<TD>
<FONT COLOR="#000000" FACE="Arial,Verdana,Helvetica" size=-1>
<b>Topics: </b>
<BR>
<P>
<a href="add-topic.php"><FONT COLOR="#000000">Make a Topic</a>
</TD>
</TR>
</TABLE>
<P>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%>
<TR VALIGN=TOP ALIGN=LEFT>
<TD WIDTH=100%>
<TABLE BORDER=0 BGCOLOR="#000000" CELLSPACING=1 CELLPADDING=1 WIDTH=100%>
<TR>
<TD BGCOLOR="#C0C0C0" WIDTH=100%>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=5 WIDTH=100%>
<TR>
<TD>
<P><B><FONT COLOR="#000000" FACE="Trebuchet MS,Arial,Helvetica">Topics</FONT></B>
</TD>
</TR>
</TABLE>
</TD>
</TR>
<?php
$topic_query = mysql_query("SELECT * FROM topics ORDER BY ID");
while ($topic = mysql_fetch_array($topic_query)) {
?>
<TR>
<TD WIDTH=82% BGCOLOR="#FFFFFF" HEIGHT=28 VALIGN=TOP>
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=5 WIDTH=100%>
<TR>
<TD>
<P><FONT SIZE="+1" FACE="Trebuchet MS,Arial,Helvetica"><a href="view.php?topicID=<?php echo $topic['ID'] ?>"><?php echo $topic['TopicName'] ?></a></FONT>
</TD>
</TR>
</TABLE>
</TD>
</TR>
<?php
}
if (mysql_num_rows($topic_query) < 1) {
?>
<TR height=300>
<TD WIDTH=100% BGCOLOR="#FFFFFF" HEIGHT=28 VALIGN=TOP>
<CENTER><FONT SIZE="-1" FACE="Trebuchet MS,Arial,Helvetica">
<BR><B>There Are No Topics</B><BR><BR></CENTER>
</TD>
</TR>
<?php } ?>
</TABLE>
</TD></TR>
</TABLE>
<?php
showfooter();
?>

Any help on this would be massively appreciated as im totally baffled to why it wont work.

Thanks

Tangerine Dream
04-30-2005, 10:59 PM
Whenever i click to add a new topic it just sort of reloads the current page without doing anything or adding anything nor displaying any errors.
Hi, you should isolate the problem first. Check whether addtopic() function works, i.e new topic' row was inserted into 'topics' using phpMyAdmin or query tool

JackSparrow
05-02-2005, 04:20 PM
No it doesnt work, nothing is inserted into the database whatsoever
=(

Tangerine Dream
05-02-2005, 06:44 PM
Check whether $topicname global variable was initialized. Also try this:


$topic_query = mysql_query("INSERT INTO topics VALUES (NULL,'$new_topicname')");
if (!$topic_query) {
showheader("MySQL Error ".mysql_error());


instead of this:


$topic_query = mysql_query("INSERT INTO topics VALUES ('NULL','$new_topicname')");
if (mysql_error() != "") {
showheader("MySQL Error ".mysql_error());


if you want to insert NULL, but not 'NULL' for char or 0 for numeric column

JackSparrow
05-02-2005, 07:22 PM
Ive changed the code and its doing exactly the same thing, still no entries into the databases. How do i check if the global function has initialised?? or is there seomthing i could replace that part of the code with to make it simpler?

thanks

Tangerine Dream
05-03-2005, 11:43 AM
function addtopic () {
global $topicname;
$new_topicname = addslashes($topicname);

// TEST: output topic name
echo $new_topicname;

$topic_query = mysql_query("INSERT INTO topics VALUES (NULL,'$new_topicname')");

JackSparrow
05-09-2005, 04:31 PM
Still doing the same, no entries into the database, and no error messages, just appears to refresh the page.

Any other ideas?

Tangerine Dream
05-09-2005, 11:28 PM
Looks like $new_topicname is NULL or "". You should find out what's wrong with $topicname initialization