Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Create pages like www.somesort.com/ member.php?action=add_article


  • Please log in to reply
16 replies to this topic

#1 yonghan

yonghan

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts

Posted 15 February 2009 - 12:20 AM

Hi all,i need help please..Suppose i've created 4 pages which is add_article,delete_article,manage_article..How do i call the pages using get??So it will display like www.somesort.com/member.php?action=add_article
For example like this forum,when wanna post a new thread..It will go to forum.codecall.net/newthread.php?do=newthread&f=16..Please help me..Thanks a lot...

Edited by yonghan, 15 February 2009 - 12:33 AM.
Some words are wrong

  • 1

#2 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 15 February 2009 - 12:33 AM

I am not completely sure what you are asking. You can use forms with the GET method to submit requests to a php page. Then using the $_GET['var'] superglobal, you can evaluate the request.
  • 0

#3 Brandon W

Brandon W

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2092 posts
  • Location:Ipswich, Australia
  • Programming Language:C, Java
  • Learning:Java, C++, JavaScript

Posted 15 February 2009 - 02:46 AM

I think he means through SQL.... If he doesn't, then I don't have much of a clue. But if he is, then check out my help thread. I asked a very similar question;
http://forum.codecal...u-do-these.html

Kind of made no sense to me before, but now I read over it again. It does make sense :)
  • 0
I've returned...

#4 yonghan

yonghan

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts

Posted 15 February 2009 - 03:25 AM

Nope..i'm not using mysql..What i mean is this way..Suppose i got add_article.php,delete_article.php..When the member able to login to member.php and click on the link to add_article.php,the address will be normally like www.somesort.com/member.php/add_article.php
How do i make the address become www.somesort.com/member.php?action=add_article
Thanks a lot...
  • 0

#5 yonghan

yonghan

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts

Posted 15 February 2009 - 03:37 AM

Sorry guys..i mean normally will be www.somesort.com/add_article.com
What i'm trying to do is to make www.somesort.com/add_article.com become www.somesort.com/member.php?action=add_article
Thanks..
  • 0

#6 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 15 February 2009 - 03:51 AM

Okey, I'll give a try to explain it in basics.

an URLWiki can be divided into four parts.
  • Protocol (http://)
  • Hostname (www.somedomain.com)
  • Filename [optional] (/index.php)
  • Parameters [optional] (?action=add&item=3&amount=5)

Protocol & Hostname I leave now, as the question is about the rest.

Filename is which html och scriptfile you want the content/result from.

Parameters is simply data to your script for further usage. We divide the Parameter list into some parts.

  • Parameter Start (?)
  • Parameters (action=add) (item=3) and (amount=5)
  • Parameter dividor (&)

To let the webserver understand the URL, we need special signs to mean stuff. a question mark says that from now, we will list parameters.
then the parameter comes as "variable=value" where first string is the variable name and the second the value that the variable shall be assigned.

the variable names is fully customizable and can be whatever you want, and the values as well.

To be able to send several variables in the URL, we need to find a way to separate them, and that is by the "&" sign.

Into PHP

Now when we have understood the layout of the url, we want to look into PHP and what happens. PHP engine reads the url and creates a variable array for you automatically and you don't have to think about it. the variable is named $_GET and is an array of the included values from the url.

if we use the example above, what PHP automatically do is:


$_GET["action"] = "add";
$_GET["item"] = "3";
$_GET["amount"] = "5";


when PHP has done this, you can use this as any variable within PHP. A good thing is not to modify this variable by your script, as you might need the original values later, so just use it.

Example of use:


switch ($_GET["action"]) {
case "add": {
// here we add whatever to the data, maybe like this
mysql_query ("INSERT INTO mytable (col1, col2) VALUES ('".$_GET["item"]."', '".$_GET["amount"]."')");
// this data should be protected from SQL injections (it isn't now), read tutorial about that.
break;
}
case "del": {
// here we do whatever del should do
mysql_query("DELETE FROM mytable WHERE col1='".$_GET["item"]."'");
break;
}
}



How to generate an URL with parameters from html

This is how you let the user fill in values to your URL in HTML


<form method="GET" action="index.php">
You want to buy item 3?
<input type="hidden" name="item" value="3">
Enter amount:
<input type="text" name="amount" value="">
Send the order by clicking here:
<input type="submit" name="action" value="add">
</form>


we do the item parameter hidden, as you might not want the user to change it.
we put a normal textbox to let the user enter the amount and then a submit button that gives direction on what action the user does. When the user clicks the "add" button, the browser automatically loads the new url combined from these controls.
  • 0

#7 yonghan

yonghan

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts

Posted 15 February 2009 - 04:36 AM

Thanks orjan,i quite understand now about using the get method..Is it the same way if i want to call other php files??Suppose i got add_article.php,how i make the url become member.php?action=add_article and not plain add_article.php??Thanks a lot...
  • 0

#8 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 15 February 2009 - 04:58 AM

You just change the form you're using to the appropriate values, and make sure you treat the parameters correctly in the new target file.

the targetfile is in the form tag, with the action="index.php" or maybe in your case action="members.php"
  • 0

#9 yonghan

yonghan

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts

Posted 15 February 2009 - 08:32 AM

Hi orjan,what i'm trying to do is create a link without using forms.Is it possible?Here's what i'm trying to do.I got member.php,the member can post request prayer etc.Like this forum.When i was logged in,i can post new thread.If i'm not wrong,the url will be something like forum.codecall.net/...?do=newthread&... I forgot the full url..Thanks a lot.
  • 0

#10 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 15 February 2009 - 09:26 AM

of course you can do that, instead of a form, you just do a link:

<a href="http://www.somedomain.com/index.php?action=add&item=3&amount=5">Add 5 pcs of #3</a>


But you can't handle user entered text or a selection of a select box without a form, but you can submit forms with javascript instead of a button if you'd like.
  • 0

#11 yonghan

yonghan

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 103 posts

Posted 15 February 2009 - 06:12 PM

That means i still can use the get method without using form??Sorry,i still don't understand. :D

I still have no idea how to do it.. :D

Hi orjan..i've found out on ozzu.com a question similiar like mine.And a guy there answer using this code :

$id = $_GET['id'];

switch ( $id )
{
case "introduction":
include_once ( "introduction.php" );
BREAK;

case "general":
include_once ( "general.php" );
BREAK;

case "overview":
include_once ( "overview.php" );
BREAK;

default:
include_once ( "main.php" ); // default option comes into play if none of the other cases is met
BREAK;
}

Hi,i attached my codes..I got error message : Fatal error: Cannot redeclare do_kepala() (previously declared in C:\wamp\www\Rekan Doa\output_fns.php:5) in C:\wamp\www\Rekan Doa\output_fns.php on line 18..If you don't mind,please help me to take a look at my codes...Thanks a lot...

Attached Files


Edited by WingedPanther, 16 February 2009 - 08:24 AM.
Quadruple post

  • 0

#12 Brandon W

Brandon W

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2092 posts
  • Location:Ipswich, Australia
  • Programming Language:C, Java
  • Learning:Java, C++, JavaScript

Posted 16 February 2009 - 12:40 AM

Calm down mate, we will help you when we can. Next time, there is an edit button to make it easier for us.

Also, that code posted is what orjan has explained in great detail. I just downloaded your code.
You forgot a ";" after you echoed the title.
On line 126, you forgot to close a span tag. Well you forgot the ">" at the end.
On line 307, 316, 335, 339 and 342 you have unmatched div tags. I don't know where you want to close them so you can do that.
After every time you close a PHP function you went;
};
Not quite necessary, so I removed the ";".

Also, I can't remember which line you did it on but there was code like this;
<?php
function something() {
    if(!isset($var) {
        // CODE HERE
    }
?>
<?php
}

//More PHP code

?>

Not much of a point for closing the PHP tags and re-opening them again, so I removed that.

I will attach the new code now, if any errors persist, post them here :)

EDIT:
NOTE: This was all done in the output_fns.php file. I did not check through the other files, as I said, any more errors, just say and we shall help you :)

Attached Files


Edited by Brandon W, 16 February 2009 - 12:42 AM.
Added Attachment

  • 0
I've returned...




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download