View Full Version : Linking page title to MySQL table

11-16-2009, 07:58 AM
Hello chaps

I have built a form which creates a new php page.

The form has

page name

When you click on the create page button the page creates taking the information from the form using the id number.

i.e on row 3 page name = test3 comments = blah blah date = today


How do i get the temp.php?title=3 to pull only the data from that field?

I have tried sessions and I get error messages, I have tried the following.

$title = $_GET('title');

if ($row['id'] == $title){

<p> <?PHP echo $row['comments'];</p>

Etc... etc..

Just can't work out this little bit. I am sure it dead easy.

11-16-2009, 09:07 AM
is that a typo
<p> <?PHP echo $row['comments'];</p> not <p> <?PHP echo $row['comments']; ?></p>
if you echo $title and get 3 then next step is to check your celect statement SELECT * from table where id = $title

11-16-2009, 10:21 AM
Me and my typos...

I have also tried

$query = sprintf("SELECT * From cms where id='$title'")

And this bring a blank page back. I will post the actual code tonight when i am back at my workstation.

11-16-2009, 05:12 PM
Not sure if this is what you mean, let me know if not and I'll try help some more.


///your database connection here///

$title = $_GET('title');
$query = sprintf("SELECT * FROM your_table WHERE ID = '$title'");
$result = @mysql_query($query);
$row = @mysql_fetch_array($result);

echo $row['comments'];


Regards Paul

11-17-2009, 02:06 AM
just an ( obvious) after thought your form is using get method not POST?

11-17-2009, 08:45 AM
Hi guys the Tux sent through worked. I had the WHERE statment in lowercase and also on the form for some reason I had another Select query so this most of caused a conflict. However it is working how it should. On to the next phase of my little project.

11-17-2009, 02:50 PM
Glad its working. Not sure it matters if you have the WHERE statement upper or lower. I do it that way coz I think its neater.

I will try it next time and see if my script messes up.

11-17-2009, 11:37 PM
no, it doesnt matter