t.bo Posted July 12, 2006 Share Posted July 12, 2006 Hello everybody, I'm a noob with PHP but slowly im workin my way around. I have a problem though. I need to have a form where you can create a new link on a page that links to another page with text that you also have to input in the form. I also need a delete function.I cant find it on the internet and tutorials are not helping me.Can anyone help me out, guide me trhough the process or send me to a good URL with a bit of the code?Thanks in advanceT.bo Quote Link to comment Share on other sites More sharing options...
brown2005 Posted July 12, 2006 Share Posted July 12, 2006 sorry i dont understand wat u mean, got any examples, or can u explain a bit more.might be me, as im half asleep.. lol Quote Link to comment Share on other sites More sharing options...
hackerkts Posted July 12, 2006 Share Posted July 12, 2006 Read the FAQ, find $_GET Quote Link to comment Share on other sites More sharing options...
t.bo Posted July 12, 2006 Author Share Posted July 12, 2006 Well im makeing this site [url=http://www.euroclinix.com]http://www.euroclinix.com[/url]When you go to "behandelingen" (wich means treatments) you see all the possible links to treatments above. (botox, ...)But now I want to make it possible to make new treatments with their new page and display the new link next to the other treatments.Hope this helps cuz I really need this one.greetz Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 12, 2006 Share Posted July 12, 2006 Its up to you, you could try looking around for a pre-built CMS (Content management system) or try to make your own smaller version, either way your going to need a database.you are basically going to have a database table containing a treatment title, the contents of the page about the treatment and any other info. You would then have a page that would pull all the titles from a database and show a link to them.Alternatively, you could investigate using file uploading if you are wanting people to upload their own html files, and then you would probably only need to store the url of the file and the title in a database.However you do it, its not going to be all that simple, perhaps it might be better trying out some other php tutorials to get a better understanding of it first. Quote Link to comment Share on other sites More sharing options...
t.bo Posted July 12, 2006 Author Share Posted July 12, 2006 Thank u for the reply!!Im one step further now.But I have problem with making the correct links, it should be something like this <a href="index.php?content=treatment&id="$id">That should make a link but how can I display the content that matches the id when the link is clicked? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 12, 2006 Share Posted July 12, 2006 $content = $_GET[content];$id = $_GET[id];$sql = mysql_query("SELECT * FROM `table` WHERE `content`='$content' and `id`='$id'");then grab the information you need and display it. Quote Link to comment Share on other sites More sharing options...
t.bo Posted July 12, 2006 Author Share Posted July 12, 2006 Damn,its still kinda hard for me...If I grab the info like u said. Put it in the variables...okBut then I dont know how I can make the link work<a href="?id=$id>link to treatment<a>when I click the link the content should be $content.How can i do that? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 12, 2006 Share Posted July 12, 2006 Do you already have a database with the content for each treatment each with a corresponding id? Quote Link to comment Share on other sites More sharing options...
t.bo Posted July 13, 2006 Author Share Posted July 13, 2006 Yes exactly , so its just giving problems for a correct output... Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 13, 2006 Share Posted July 13, 2006 Well you have to query the database to get the IDs that you want e.g.[code]<?$sql = mysql_query("SELECT * FROM `yourtable'");while($row = mysql_fetch_assoc($sql)){$title = $row['titlefield'];$id = $row['idfield'];echo "<a href='page.php?id=$id'>$title</a>";}?>[/code]And then on "page.php":[code]<?$id = $_GET[id];$sql = mysql_query("SELECT * FROM `yourtable` WHERE and `idfield`='$id'");then grab the information you need and display it.?>[/code]You will have to modify the table and field names. Quote Link to comment Share on other sites More sharing options...
t.bo Posted July 13, 2006 Author Share Posted July 13, 2006 thanks Im gonna try it laterHope it worksgrtz Quote Link to comment Share on other sites More sharing options...
t.bo Posted July 13, 2006 Author Share Posted July 13, 2006 Damn it didn't work.The variables stay empty I think.This is the table : CREATE TABLE `yourtable` ( `idfield` int(11) NOT NULL auto_increment, `titlefield` varchar(250) NOT NULL, `content` text NOT NULL, PRIMARY KEY (`idfield`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;The table already has inputs...This is the php :Page with the links :[code]<?include('dbconnect.php');$sql = mysql_query("SELECT * FROM `yourtable'");while($row = mysql_fetch_assoc($sql)){$title = $row['titlefield'];$id = $row['idfield'];echo "<a href='page.php?id=$id'>$title</a>";}?>[/code]Page.php :[code]<?include('dbconnect.php');$id = $_GET[id];$sql = mysql_query("SELECT * FROM `yourtable` WHERE and `idfield`='$id'");$content = $_GET[content];echo "$content";?>[/code]I probably made a mistake with page.php but the page with the links should work a,d it does not...Dbconnect is correct though Quote Link to comment Share on other sites More sharing options...
t.bo Posted July 14, 2006 Author Share Posted July 14, 2006 Can anyone help me out?I really need this one.Greetz and thanks in advance. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 14, 2006 Share Posted July 14, 2006 isn't content supposed to come from the database? if so:$content = mysql_result($sql,'0',"content");echo "$content"; Quote Link to comment Share on other sites More sharing options...
t.bo Posted July 14, 2006 Author Share Posted July 14, 2006 Hmm still doesnt work..Is it possible that there is a problem with the ", ' and ` tags? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 14, 2006 Share Posted July 14, 2006 Add an or die statement:$sql = mysql_query("SELECT * FROM `yourtable` WHERE and `idfield`='$id'") or die(mysql_error());$content = $_GET[content];echo "$content"; Quote Link to comment Share on other sites More sharing options...
t.bo Posted July 14, 2006 Author Share Posted July 14, 2006 Ok now I get :You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'and `idfield`='1'' at line 1 Quote Link to comment Share on other sites More sharing options...
t.bo Posted July 14, 2006 Author Share Posted July 14, 2006 Ok I GOT IT ;D[code]<?include('dbconnect.php');$id = $_GET[id];$sql = mysql_query("SELECT * FROM yourtable WHERE idfield='$id'") or die(mysql_error());$r=mysql_fetch_array($sql);$content = mysql_result($sql,'0',"content");echo "$content";?>[/code]Works perfect. Thanks for everything Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 14, 2006 Share Posted July 14, 2006 You beat me too it. Glad to help Quote Link to comment Share on other sites More sharing options...
t.bo Posted July 14, 2006 Author Share Posted July 14, 2006 My input and output code works perfect... But now the DELETE code :[code]<? include('dbconnect.php');if(!isset($cmd)) { $result = mysql_query("select * from yourtable") or die(mysql_error()); while($r=mysql_fetch_array($result)) { $title=$r["titlefield"]; $id=$r["idfield"]; echo "<a href='treatedit.php?cmd=delete&idfield=$id'>$title - Delete</a>"; echo "<br>"; }}?><?if($cmd=="delete"){ $sql = "DELETE FROM yourtable WHERE idfield='$id'"; $result = mysql_query($sql) or die(mysql_error()); echo "treat deleted";}?>[/code]It displays the correct links and gives the correct output (treat deleted). But it does not actually delete :-sCan U help once again :-)Thanks in advance Quote Link to comment Share on other sites More sharing options...
t.bo Posted July 15, 2006 Author Share Posted July 15, 2006 Can anyone help me out?I think there is a problem with the idfield & $id but I cant see it...Thanks in advance Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 15, 2006 Share Posted July 15, 2006 Where is it getting the $id from? Was this supposed to come from a url? If so you will probably need to do:$id = $_GET['id'] Quote Link to comment Share on other sites More sharing options...
t.bo Posted July 15, 2006 Author Share Posted July 15, 2006 Ok thanks again...Should this piece of code be put in the beginning of the code or already in the delete section?grtz Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted July 15, 2006 Share Posted July 15, 2006 you might as well place it at the top of your file. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.