Jump to content

Probably a really simple, stupid question. Building url from variables?


Calcartman

Recommended Posts

Hi everybody!
*hi dr. nick* (sorry, couldn't help it)

*skip down for the question*

This is going to sound really stupid, in all likelyhood.
I just got a birthday present, a [url=http://www.nabaztag.com]Nabaztag[/url]
Bottom line is that it is an ambient style device, which has an API you can send messages, ear movements, light flashes, etc through.
I am attempting to build a small form for my website, and ideally my myspace/forumsigs/etc as well.
My experience with PHP is very limited, and I have only done very basic forms in html (mailtos).
I have a couple years of C++ and a semester of Java in my past, but that's 4 years ago.

I have made a simple form with a name and message box, using POST, and created a PHP page to turn those submissions into variables, like this:
$name = $_POST['name'];
$message= $_POST['message'];

Now heres the problem. the API that is used must go through the website of nabaztag. They give you all the information. So the url I need to create will end up looking like this (its long):

http://www.nabaztag.com/vl/FR/api.jsp?sn=00039D4028F9&token=1162428034&tts=a%20message%20from[b]'name'[/b]%20[b]message[/b]

There are other parameters which are added after (posleft=, posright= are both ints under 16, and all the variables are going to end up as ints or text, all of which will need to be added to the url.).

So, i guess the brunt of my question is:
I have a form to submit my data, how can i create a url using bits of that data, and redirect the user to it?

Thanks for any and all help!

-Cal

PS: send my bunny a message :P
Link to comment
Share on other sites

Maybe, but i don't think i need a for loop, do I?
But how do I make it redirect to the new created url?
I am not knowledgeable in php at all, everything I know I learned from research last night online.

I don't really understand how that for loop works, what are $key and $value representing?

It's not a very complicated Idea, I just need a small bit of code to recieve a name and message, and then add them to a URL, and redirect to the new completed url.
Would writing my code like this make sense:

$addr = "http://www.nabaztag.com/vl/FR/api.jsp?sn=00039D4028F9&token=1162428034&tts=a message from "

$name = $_POST['name'];
$message = $_POST['message'];
$addr + $name + "says " + $message;

That is basically how I would have written it in c++, but like I said, I don't know PHP.
Would this give me the variable $addr with the url stored and added too? And how can I redirect to it?

Thanks for your help!
Link to comment
Share on other sites

Like this?
[code]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?PHP
$name = "Submitted name";
$message = "Submitted message";
$link = "Click Me";

$addr = "http://www.nabaztag.com/vl/FR/api.jsp?sn=00039D4028F9&token=1162428034&tts=a message from";

$html = '<a href="'.$addr.$name.$message.'">'.$link.'</a>';

print $html;
?>
</body>
</html>


[/code]
Link to comment
Share on other sites

As best I can tell, this is what you're describing.
[code]
$address = "http://www.nabaztag.com/vl/FR/api.jsp?sn=00039D4028F9&token=1162428034&tts=a%20message%20from'" . $name . "'%20" . $message . "'";

//this will redirect the browswer to the page specified.
header("Location:  " . $address);
[/code]
Link to comment
Share on other sites

Alpine, I cant quite follow what that html query does, but it seems a lot more complicated than this should be? Maybe not, but i'd think its easy cause I could probably write it in c++.

Flow chart:

User Inputs Name -> User Inputs Message -> Submit -> Redirect to http://www.nabaztag.com/vl/FR/api.jsp?=(a whole bunch of submitted fields, and a few I put in static to address it to my bunny).

Basically, i need to put in a name and message, and i want it to send the url (which is how the API thing works) that has a whole bunch of things that look like &posleft=X&posright=Y&tts=NAME+messageABC.........

I don't know if that makes sense?
The way their program to communicate with the bunny works, is through a GET-type url.

I just don't know how to do it, and I am the first to admit I am not a programmer. I do computer networking, hardware, and software for orthodontist offices.

NoPHPPhD:

I think that is exactly what I need, with one problem!
Will this work?
(I don't know how else to call and get the variables POSTED by my html form, is there another way?)

[code]
$name = $_POST['name'];
$message = $_POST['message'];
[/code]
^^ that gets the variables, right?

[code]
$link = "Click Me";

$addr = "http://www.nabaztag.com/vl/FR/api.jsp?sn=00039D4028F9&token=1162428034&tts=a message from";
$html = '<a href="'.$addr.$name.$message.'">'.$link.'</a>';

print $html;
[/code]

Will that print a button that says "click me", and goes to the url + the name and message?
The only thing i need to change then, is find a way to add a couple spaces in between the middle of the name and message.

How would i then add "&posleft=X" and "&posright=Y" to the url?
Just make more variables and string em together like that?

[code]
$leftear= $_POST['left'];
$rightear= $_POST['right'];
$posleft= "&posleft=" + $leftear;
$posright= "&posright=" + $rightear;
[/code]
and just add .$posleft.$posright to the string?


Thanks a ton for all your help guys! I'm in school right now or I would be testing all this out.

If you're interested this is a video of my bunny from last night, my girlfriend sent the song (not my choice) through their website.

I would love to be able to code something that would allow sending of mp3s as well, but I don't know that much about it (YET!).

http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid=1372033579

-Cal
Link to comment
Share on other sites

[quote author=doni49 link=topic=113560.msg461843#msg461843 date=1162490413]
As best I can tell, this is what you're describing.
[code]
$address = "http://www.nabaztag.com/vl/FR/api.jsp?sn=00039D4028F9&token=1162428034&tts=a%20message%20from'" . $name . "'%20" . $message . "'";

//this will redirect the browswer to the page specified.
header("Location:  " . $address);
[/code]

[/quote]

Assuming I understand correctly, thats perfect!
How will the output of the URL come?

Say I submit "Frank" and "How is it going?"
will my end result be:
[code]
$name= $_POST['Frank'];
$message = $_POST['How is it going?'];

$address = http://www.nabaztag.com/vl/FR/api.jsp?sn=00039D4028F9&token=1162428034&tts=a%20message%20from'" . $name . "'%20" . $message . "'";

Will those spaces in the name and message part (as well as the periods) come out in the url? or will it come out as:
....&tts=a message from Frank%20How is it going?

Thanks for the help guys! I promise I'm not usually this slow!

[/code]
Link to comment
Share on other sites

[quote author=NoPHPPhD link=topic=113560.msg461919#msg461919 date=1162496897]
I would say your best bet from here is to load up WAMP and put the page up there to test and make sure it does exactly what you want.
[/quote]

Wamp?

I don't know what that is, but i'll do anything I can to figure this out!

Right now my form and page are up at http://cookiemonsterbmw.com/rabbitlicious.html,
and my php page is at http://cookiemonsterbmw.com/send.php

Im about to go into class, but I managed to get them up!
Link to comment
Share on other sites

Its still not working right?
heres my php code!

[code]
<?php
$name = $_POST['name'];
$message = $_POST['message'];
$leftear= $_POST['left'];
$rightear= $_POST['right'];
$posleft= "&posleft=" + $leftear;
$posright= "&posright=" + $rightear;

$address = "http://www.nabaztag.com/vl/FR/api.jsp?key=48822447sn=00039D4028F9&token=1162428034&tts=a%20message%20from".$name."%20".$message.";

//this will redirect the browswer to the page specified.
header("Location:  " . $address);?>
[/code]

Link to comment
Share on other sites

Okay, so here is my problem:

User goes to rabbitlicious.html
User fills out form with Name and Message, sent to action send.php using POST
Send.php redirects user to address, but not address with fields added on.
It stops at A message From......

So im back to my issue.

How can I take what the user enters, and insert it into the url?
Link to comment
Share on other sites

[quote author=Calcartman link=topic=113560.msg461882#msg461882 date=1162494075]
[quote author=doni49 link=topic=113560.msg461843#msg461843 date=1162490413]
As best I can tell, this is what you're describing.
[code]
$address = "http://www.nabaztag.com/vl/FR/api.jsp?sn=00039D4028F9&token=1162428034&tts=a%20message%20from'" . $name . "'%20" . $message . "'";

//this will redirect the browswer to the page specified.
header("Location:  " . $address);
[/code]

[/quote]

Assuming I understand correctly, thats perfect!
How will the output of the URL come?

Say I submit "Frank" and "How is it going?"
will my end result be:
[code]
$name= $_POST['Frank'];
$message = $_POST['How is it going?'];

$address = http://www.nabaztag.com/vl/FR/api.jsp?sn=00039D4028F9&token=1162428034&tts=a%20message%20from'" . $name . "'%20" . $message . "'";

Will those spaces in the name and message part (as well as the periods) come out in the url? or will it come out as:
....&tts=a message from Frank%20How is it going?

Thanks for the help guys! I promise I'm not usually this slow!

[/code]
[/quote]

If [b]$name[/b] is "Frank" and [b]$message[/b] is "How is it going", then $address will contain the following URL:
[url=http://www.nabaztag.com/vl/FR/api.jsp?sn=00039D4028F9&token=1162428034&tts=a%20message%20from'Frank'%20'How%20is%it%going?']http://www.nabaztag.com/vl/FR/api.jsp?sn=00039D4028F9&token=1162428034&tts=a%20message%20from'Frank'%20'How%20is%it%going?'[/url]

the header function will load that URL in the browser.  The period and the quotes enable concatenation.

Example:

//The following will send "[b]Hi, How are you?[/b]" to the browser.
$a = "Hi!";
$b = "How are you?"
echo $a . "  " . $b;

//The following will send "[b]Hi, How are you?  My name is Don.[/b]" to the browser. 
$c .= $a . "  " . $b . "  " . "My name is Don.";
echo $c;

For more info on this:
[url=http://us2.php.net/manual/en/language.operators.string.php]http://us2.php.net/manual/en/language.operators.string.php[/url]

Also, WAMP is [b]W[/b]indows [b]A[/b]pache [b]M[/b]ySQL [b]P[/b]HP

Lamp is [b]L[/b]inux [b]A[/b]pache [b]M[/b]ySQL [b]P[/b]HP
Link to comment
Share on other sites

[quote author=doni49 link=topic=113560.msg462144#msg462144 date=1162517058]
[quote author=Calcartman link=topic=113560.msg461882#msg461882 date=1162494075]
[quote author=doni49 link=topic=113560.msg461843#msg461843 date=1162490413]
As best I can tell, this is what you're describing.
[code]
$address = "http://www.nabaztag.com/vl/FR/api.jsp?sn=00039D4028F9&token=1162428034&tts=a%20message%20from'" . $name . "'%20" . $message . "'";

//this will redirect the browswer to the page specified.
header("Location:  " . $address);
[/code]

[/quote]

Assuming I understand correctly, thats perfect!
How will the output of the URL come?

Say I submit "Frank" and "How is it going?"
will my end result be:
[code]
$name= $_POST['Frank'];
$message = $_POST['How is it going?'];

$address = http://www.nabaztag.com/vl/FR/api.jsp?sn=00039D4028F9&token=1162428034&tts=a%20message%20from'" . $name . "'%20" . $message . "'";

Will those spaces in the name and message part (as well as the periods) come out in the url? or will it come out as:
....&tts=a message from Frank%20How is it going?

Thanks for the help guys! I promise I'm not usually this slow!

[/code]
[/quote]

If [b]$name[/b] is "Frank" and [b]$message[/b] is "How is it going", then $address will contain the following URL:
[url=http://www.nabaztag.com/vl/FR/api.jsp?sn=00039D4028F9&token=1162428034&tts=a%20message%20from'Frank'%20'How%20is%it%going?']http://www.nabaztag.com/vl/FR/api.jsp?sn=00039D4028F9&token=1162428034&tts=a%20message%20from'Frank'%20'How%20is%it%going?'[/url]

the header function will load that URL in the browser.  The period and the quotes enable concatenation.

Example:

//The following will send "[b]Hi, How are you?[/b]" to the browser.
$a = "Hi!";
$b = "How are you?"
echo $a . "  " . $b;

//The following will send "[b]Hi, How are you?  My name is Don.[/b]" to the browser. 
$c .= $a . "  " . $b . "  " . "My name is Don.";
echo $c;

For more info on this:
[url=http://us2.php.net/manual/en/language.operators.string.php]http://us2.php.net/manual/en/language.operators.string.php[/url]

Also, WAMP is [b]W[/b]indows [b]A[/b]pache [b]M[/b]ySQL [b]P[/b]HP

Lamp is [b]L[/b]inux [b]A[/b]pache [b]M[/b]ySQL [b]P[/b]HP
[/quote]


I understand, but the code above simply did not work.
It loaded the URL, but it ended it at "a message from", meaning either the variables were empty or simply not working.
Did i load the variables correctly?
Link to comment
Share on other sites

Try posting three pieces of info here and I'll see what I can decipher (or maybe someone else'll figure it out before me):

1) the entire code of the first page.

2) the entire code of the send.php file.

3) show me EXACTLY what the URL is that you're trying send your user to.
Link to comment
Share on other sites

Ok I just visited your page and did a "View>Source".  I [b]THINK[/b] I see your problem.

Variables are case sensitive.  Your text area's name is "Message".  So you need to retrieve it's value using [b]$_POST['Message'][/b].  You need to retrieve the name using [b]$_POST['Name'][/b].
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.