Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

this should be easy...

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

this should be easy...

Postby shewien » Fri Sep 27, 2002 3:31 pm

This should be easy, but I can't come up with the answer.

My visitor clicks on 1 out of 10 different hyperlinks that al lead to the same form they have to fill out. On the top of the form I want to state: "you chose link1 (or 2 or 3...)". And after submitting the form, 'link1' should be inserted in my table, just like the fields the visitor manually entered.

Can someone give me a clue?
User avatar
shewien
New php-forum User
New php-forum User
 
Posts: 13
Joined: Wed Sep 25, 2002 6:13 am

Postby DoppyNL » Fri Sep 27, 2002 11:58 pm

If all links come from a different page, you could use
$_SERVER['HTTP_REFERER']
wich contains the url of the refering page, in most cases, but most of the times it works.

you could also add a (different) parameter to each link like:
"http://www.domain.com/mypage.php?frompage=whatever"


Greetz Daan
DoppyNL
 

the links refer to a table

Postby shewien » Sat Sep 28, 2002 1:07 am

No, the links refer to an sql table I created.
The links are in fact thumbnails. It should work like this:

"Elect our new class president, please click on a picture and fill out your election form"
So there are several pics of elegable class presidents. If you click on either of them, you end up in a form, which states the name of the person you chose. You fill in your name and click on submit. Now my sql table "votes" should receive both the name of the chosen class president and the name of the person who voted.

Sorry for not being so clear the first time.
User avatar
shewien
New php-forum User
New php-forum User
 
Posts: 13
Joined: Wed Sep 25, 2002 6:13 am

Postby DoppyNL » Sat Sep 28, 2002 1:14 am

simply add a parameter to each link (behind the picture) to identify the person they want to vote on, like this:
Code: Select all
<a href="formpage.php?person=1"><img=blablabla></a>


in the form page you now got the posted variable "person" wich you can check to determine wich person they want to vote on and make you're form accordingly.

Greetz Daan
DoppyNL
 

OK, now what

Postby shewien » Sat Sep 28, 2002 2:18 am

OK, I inserted the parameter like you said:
<a href="formpage.php?person=1"><img=blablabla></a>

I am sorry for being this ignorent about all this, but what do I do next?
Once I clicked on the img, I am in the form. If person1=John Doe ,how can I state: "you chose John Doe, now fill in your name and submit."
User avatar
shewien
New php-forum User
New php-forum User
 
Posts: 13
Joined: Wed Sep 25, 2002 6:13 am

Postby Jay » Sat Sep 28, 2002 2:25 am

On the form page you'll recieve a variable which will be $_GET['person']. You can use your own script now to work out who the person is based on this variable, and you can also write a 'hidden' tag in your form so it'll submit it with the rest of the data!
Jay
 

still in the dark

Postby shewien » Sat Sep 28, 2002 3:57 pm

I am so sorry, but I am afraid you will have to spell it out for me.

The sql table I created has only one column, with the names of the eligable class presidents. For instance, John Doe is the 2nd person in the table.
On top of the (html-)form I want to state: "You chose John Doe."

I have already attached : <a href="formpage.php?person=1"><img=blablabla></a>
to each thumbnail. Now what to do??
User avatar
shewien
New php-forum User
New php-forum User
 
Posts: 13
Joined: Wed Sep 25, 2002 6:13 am

Re: still in the dark

Postby DoppyNL » Sat Sep 28, 2002 11:03 pm

shewien wrote:I have already attached : <a href="formpage.php?person=1"><img=blablabla></a>
to each thumbnail.

you must not attach this code, but alter it a bit and replace the original...
should be something like this:
Code: Select all
<a href="formpage.php?person=1"><img src="picture_john_doe.jpg"></a>


on the form page you now know that the person wants to vote on person 1, in other words John Doe, use that to build you're form!
on that page you will have to pass that data to the next page, wich enters the data into the database.
You can use a hidden field for that.

On the last page (wich enters the data into the database) you will have to make you're query to enter the data.
for wich you will have to use the variables you passed from the form.

How that query looks depends entirely on what fields you got in you're table.

Greetz Daan
DoppyNL
 

but how...

Postby shewien » Sun Sep 29, 2002 12:19 pm

Daan, you said: "use that to build you're form! "
BUT HOW ??!!! That's my whole problem.
User avatar
shewien
New php-forum User
New php-forum User
 
Posts: 13
Joined: Wed Sep 25, 2002 6:13 am

Postby Jay » Sun Sep 29, 2002 11:44 pm

What you need is 2 databases:
One will hold the candidate information (id and name) and the other will hold information on the votors (name, vote, etc).

On the first page list all the candidates using the code you're using:
<a href="formpage.php?person=X"><img src="picture_john_doe.jpg"></a>
replacing X for the ID of that person.

When someone clicks on it, they'll get taken to a form page. Use the $_GET['person'] value to work out who they voted for ("select name from candidates where ID=".$_GET['person']) and you can use this to display "You have selected John Doe" or whatever. Also, include this in a hidden field in your form (<input type='hidden' name='vote' value='X'>) so when the user submits his details, the vote will be registered as well!
Jay
 

error

Postby shewien » Mon Sep 30, 2002 3:01 am

OK, i did like you said. This is the particular part of my form:

<td width="100%" height="25" align="center" colspan="2"><font size="5">You chose <?php ("select name from candidates where nr=".$_GET['name']); ?>.</font>

When running the form I get: Parse error: parse error, expecting `','' or `';'' in form.php on line 60

What's wrong with the code?
User avatar
shewien
New php-forum User
New php-forum User
 
Posts: 13
Joined: Wed Sep 25, 2002 6:13 am


Postby Jay » Mon Sep 30, 2002 5:42 am

I think you've bitten off more than you can chew. I did suspect so, but didn't want to say. You need to learn how to access and manipulate a MySQL database with PHP, and also how to control variables and use them in presentation of data before you can think about inserting and retrieving form data!

Sorry, but we all have to start at the bottom!
Jay
 

OK

Postby shewien » Mon Sep 30, 2002 5:49 am

Of course you are right. I think I will study a bit more on the basics.
Thanks anyway so far.
User avatar
shewien
New php-forum User
New php-forum User
 
Posts: 13
Joined: Wed Sep 25, 2002 6:13 am


Return to PHP coding => General

Who is online

Users browsing this forum: Alexa [Bot], Bing [Bot] and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron