Ok I am stumped so bad. I am using a form to insert a topic and comment into a table and if the topic is new it creates a new table specific to that topic. So I pass the topic name through the url and Im trying to retrieve it in another page. I see the id passed in the url and I try getting it using $topic =$_GET['id'];
. I use the topic to insert the into another table.
Here are the different pages. They are all butchered up with me trying to solve this problem.
inserttopic.php
</head>
<body>
<?php
include 'config2.php';
include 'opendb.php';
include 'dbntable.php';
if(!isset($_GET)) {
$topic =$_GET['id'];
echo "Get". $topic ;
}else{
$topic=$_POST['topic'];
echo "Post". $topic ;
}
$comment=$_POST['comment'];
$username=$_POST['username'];
$timestamp= date("g:ia");
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
//below experimental-search for topic in column.
//If no match create new table, if match ask user to be more specific or comment on current topic.
$search = "SELECT * FROM $tablename WHERE topic = '$topic' ORDER BY city ASC";
$yes=mysql_query($search);
if($yes)
{
echo "Topic already exists. Please be more specific with your topic.";
mysql_query("INSERT INTO $topic (comment, username, timestamp)
VALUES ('$comment','$username','$timestamp')");
header( 'Location: http://localhost/San%20Antonio/test.php?id='.$topic.'' ) ;
}else{
$create="CREATE TABLE $topic (
id INT(30) NOT NULL AUTO_INCREMENT PRIMARY KEY,
comment VARCHAR(1000),
username VARCHAR(30),
timestamp VARCHAR(30))";
mysql_query($create);
mysql_query("INSERT INTO $tablename (topic, comment, username, timestamp)
VALUES ('$topic','$comment','$username','$timestamp')");
mysql_query("INSERT INTO $topic (comment, username, timestamp)
VALUES ('$comment','$username','$timestamp')");
header( 'Location: http://localhost/San%20Antonio/test.php?id='.$topic.'' ) ;
Echo "this is the topic = ".$topic;
};
echo $topic;
?>
</body>
</html>
Here's the URL thats passed
http://localhost/San%20Antonio/test.php?id=Kobe
insertcomment.php
<?php
include 'config2.php';
include 'opendb.php';
include 'dbntable.php';
if(isset($_GET['id'])){
$topic =$_GET['id'];
}
$comment=$_POST['comment'];
$username=$_POST['username'];
$timestamp= date("g:ia");
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
//below experimental-search for topic in column.
//If no match create new table, if match ask user to be more specific or comment on current topic.
echo "Topic already exists. Please be more specific with your topic.";
mysql_query("INSERT INTO $topic (comment, username, timestamp)
VALUES ('$comment','$username','$timestamp')");
echo "This is the topic = ".$topic;
?>
</body>
</html>
Errors
Notice: Undefined variable: topic in C:\wamp\www\metrocritix\San Antonio\insertcomment.php on line 33
Notice: Undefined variable: topic in C:\wamp\www\metrocritix\San Antonio\insertcomment.php on line 35
Please help!