PDA

View Full Version : Linking page title to MySQL table


cocoonfx
11-16-2009, 08:58 AM
Hello chaps


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

The form has

page name
comments
date
url

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

www.test-cocoonfxmedia.co.uk/WMS/temp.php?title=3

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.

edbr
11-16-2009, 10: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

cocoonfx
11-16-2009, 11: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.

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

<?php

///your database connection here///

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


echo $row['comments'];


?>

Regards Paul

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

cocoonfx
11-17-2009, 09: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.

tux
11-17-2009, 03: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.

edbr
11-18-2009, 12:37 AM
no, it doesnt matter