Help - Search - Members - Calendar
Full Version: trying to creating a forum php/mysql/dwmx04 :(
Weborum Webmaster Forum > Web Page Design > PHP
steve g
hello all, have only just joined today and guess what....? am stuck..hoping that someone on here might be able to help me

AM new to dreamweaver,php and mysql but have used different programming languages and was only an access person before.

right,

am trying to create a forum (stupidly)

have 4 tables (forums,posts, topics and users)

it is designed to look like vbulletin, bb etc...

i have lots of problems with it but this is one...

if the topics table has topic_Id as pk auto increment, and the relationship is 1 to many with posts...the topic_id goes to the posts table foreign key.....

so i have a form to create a new topic

this has a topic title and a post message each of these has to go to their respective tables and fields...

it is coming up with an error saying that topic title cannot be null although i am entering a topic title....

not sure whats going wrong the posts table has a post id thats also auto inc'd

so i am trying to insert to two tables with one form yet it won't work

do i need to get the topic id field once incremented in the topics table to also increment the topic id (foreign) in the posts table it is only a foreign key not a partial key..

sorry very long winded post that might not make much sense...

any help is greatl apprciated smile.gif

aviansuicide
You need to show us the code. And, fyi..a forum is by no means an 'easy' script..so I can't suggest you doing it if your:

A)using dreamweaver
B)new to php
C)used to newbie friendly apps such as access


But eh..post the code..and I'll try to help you.
steve g
yeh....have found that out.. sad.gif but have assigned myself to do it as a project, so have to try and do what i can....was not one of my better decisions..

first i will show my post a message form as this is also causing me problems but should be a little easier to start with... i have messed around with it though...only in the insert method...the rest of it is untouched

<?php require_once('Connections/ConnectForum.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "post")) {
$insertSQL = sprintf("INSERT INTO Posts (
post_Id, topic_Id, post_Message, creation, username) VALUES (",%s)"
GetSQLValueString($_POST['textarea'], "text"));

mysql_select_db($database_ConnectForum, $ConnectForum);
$Result1 = mysql_query($insertSQL, $ConnectForum) or die(mysql_error());

$insertGoTo = "" . $row_rsPostaReply['post_Message'] . "";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

$colname_rsPostaReply = "1";
if (isset($_GET['topic_Id'])) {
$colname_rsPostaReply = (get_magic_quotes_gpc()) ? $_GET['topic_Id'] : addslashes($_GET['topic_Id']);
}
mysql_select_db($database_ConnectForum, $ConnectForum);
$query_rsPostaReply = sprintf("SELECT post_Message, username FROM Posts WHERE topic_Id = %s", $colname_rsPostaReply);
$rsPostaReply = mysql_query($query_rsPostaReply, $ConnectForum) or die(mysql_error());
$row_rsPostaReply = mysql_fetch_assoc($rsPostaReply);
$totalRows_rsPostaReply = mysql_num_rows($rsPostaReply);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="<?php echo $editFormAction; ?>" method="POST" name="post" id="post">
<table width="464" border="1" cellspacing="2" cellpadding="2">
<tr>
<td width="35">&nbsp;</td>
<td width="415">post reply </td>
</tr>
<tr>
<td>Post Body </td>
<td><textarea name="textarea" cols="75" rows="10"></textarea></td>
</tr>
<tr>
<td height="23">&nbsp;</td>
<td><div align="center">
<input type="submit" name="Submit" value="Submit">
</div></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="post">
</form>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($rsPostaReply);
?>

the table of posts has the field that are in the insert method

topic_Id is a foregin key which is an autoincrement field in its table

creation is a datetime field

username is also a foreign key from the Users table

post_Message is of type tiny Blob

and post_Id is the posts tables primary key

the form has only one field which is post message, i think that to insert into the database it also needs to know the other fields which i have added but not the values that need to go into them, as some are foreign keys and also i'm not sure if to use now(), or currentdate(0 etc to get it to add to the dateTime field whatever is the date and time now

thanks for any light that may be shed on this smile.gif


steve g
the problem is that there's that much info out there that i'm just getting overloaded with information....which then leads to more confusion...which then ends up with me doing nothing.....i just want it to do a few basic things like posting a message and a new topic and i'll be happy then will probably just download a message board instead as this is not the easiest thing to do...

could have implemented it with less tables and more attributes in each of them which would have been eaier....wish i had now but is too late for that.

oh well learn from your mistakes.... baaasmiley.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.