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!

I changed line 12 like u said but it still isn't working.

Well mate... I don't know where to start..
You are trying to do strange things with your code :)

the notices you posted are just alerts, they don't stop the code from runnig...
Those notices exist because you are not creating the var $topic before that point on the code...
Please paste this on line 6 "$topic = false;" and this on line on line 10 "if( empty( $topic ) ){ echo 'no topic';die();}" on the insertcomment.php

by the way you should convert the topic to a sef like name ;)

I hope that code is not for a real site / production site :)

best regards

I changed line 12 like u said but it still isn't working.

"isn't working" does not convey anything useful!

Yea I know the coding is kinda jacked up. It's just the end result of trial and error... Lots of errors lol. I'll keep y'all posted on the progress.

$topic is shows up as blank.. even though the id is in the url... I dont know why its not retrieving it from the url...

$topic is shows up as blank.. even though the id is in the url... I dont know why its not retrieving it from the url...

post the url and how you do retrieve the id!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.