hello guys,
sorry I havn't posted in a while. I've been in hiding, toiling over php code for countless weeks now. Anyways heres my problem:
first, heres my database info:
the database is named: bookwriter
It has two tables: chapters and topics
The chapters table has the following columns:
ID : auto increment, primary key, not null, INT
chap_title : VARCHAR 250
And the topics table has the following colums:
ID: auto increment, primary key, not null, INT
topic_title:VARCHAR 250
topic_text:LONG TEXT
chap_ID: INT
the chap_ID column in the topics table contains the ID of the chapters table to indicate which topic belongs to each chapter.
What I want to do is be able to allow the user to submit their topic_title and topic_text into the database and choose the chapter to which the will belong to. They choose the chapter in the form of a dropdown box. Where my problem lies is updating the chap_ID with the chapters ID when its posted.
In other words what I want to do is allow them to do is enter a new topic_title, topic_text, and a chap_ID value (of the chapter ID) upon post. Heres what I have so far:
topic_form_act.php
code:
<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Title here!</title>
</head>
<body>
<?php
//connect to the database
$dbcnx = mysql_connect('localhost','username','password');
mysql_select_db('bookwriter');
//query the database
$chapterlist = mysql_query("SELECT chapters.ID, chap_title,
topic_title, topic_text, chap_ID
FROM chapters, topics" );}
?>
<form name="addtopic" method="post" action="topic_add_qry.php">
Add topic to which chapter?:
<select name="chap_ID">
<option value="">Chapter</option>
<option value="">- - - - - - - -</option>
<?php
//list the chapters in the database using a select dropdown box
while($chapters = mysql_fetch_array($chapterlist)) {
$chap_ID = $chapters['chapters.ID'];
$chap_title = $chapters['chap_title'];
$topic_title = $chapters['topic_title'];
$topic_text = $chapters['topic_text'];
echo("<option value='$chap_ID'>$chap_title</option>\n" );
}
?>
</select>
<br><br>
Topic Name: <input type="text" size="50" maxlength="100" name="topic_title">
<P>
Write your topic: <br>
<textarea cols="50" rows="10" name="topic_text"></textarea>
<P>
<input type="submit" value="submit" name"submit">
</form>
</body>
</html>
and topic_add_qry.php
code:
<?PHP
//connect to the database
$dbcnx = mysql_connect('localhost','username','password');
mysql_select_db('bookwriter');
//grap the post variables
if(isset($_POST['submit'])) {
$chap_ID = $_POST['chap_ID'];
$topic_title = $_POST['topic_title'];
$topic_text = $_POST['topic_text'];
//insert query to put them in the topics table
$sql = "INSERT INTO topics SET
chap_ID ='$chap_ID',
topic_title = '$topic_title',
topic_text = '$topic_text'";
}
if (@mysql_query($sql)) {
echo('The new topic has been added to the chapter');
}
else {
echo('could not add new topic:' . mysql_error());
}
?>
also, my chapters in the dropdown box are doubling (listing twice) and upon post I get the following error :
quote:
could not add new topic:Query was empty
any ideas? I'm honestly just completly stumped at this point.
[This message has been edited by jive (edited 06-25-2003).]
[This message has been edited by jive (edited 06-25-2003).]