FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Hey, a little help plz





Poetsunited
I'm trying to make a script that randomly selects a word from my db, and asks for the translation... that word is then send to another file to compare etc...


I have that part working but now i have two problems :

1: the words are French, so when i type ' it automaticly says its wrong, because it adds \ in front of it

2: some answers exists of more then one word ( for example un homme ) and then it only shows up the un...


anyone know how to solve this?

thanks for reading

- kevin -
Diablosblizz
For the first question, it can be easily fixed by:

Code:
$variable = stripslashes($whatever);


Replace $whatever with the part that gets the translation from the form. I am a bit confused on the second question, could you please explain more?
Peterssidan
Are you sure that the words in the database are correct? Does they look alright in phpmyadmin?
Poetsunited
Diablosblizz wrote:
For the first question, it can be easily fixed by:

Code:
$variable = stripslashes($whatever);


Replace $whatever with the part that gets the translation from the form. I am a bit confused on the second question, could you please explain more?


Thanks, that fixed my first problem, the second problem is like this...

for example, the answer is : la lune de miel, then somehow it only posts the first word, and it says it wasn't correct

http://unitedpoets.frihost.net/voc2000/index.php

thats my site, above the form you'll see 2 words, for example...

Vertaal volgend woordje :
de echtgenote l'épouse

vertaal volgend woordje : translate this word
copy the second part into the form section to see how it works... so in this case it would be l'épouse

the words in my db look ok...


- thanks for the help Smile -
Peterssidan
I don't know exactly how it works but the hidden field with the answer only contains the last word.
Code:
<input type=hidden name=ans value=l'épouse>

It must be something wrong with your php script.
Poetsunited
this is the coding... I've been going trough it a few times finding no error :< so yeah idk

Code:
<?php
include 'connect.php';
echo "Vertaal volgend woordje : <br>";
 $x = mysql_fetch_array(mysql_query("select * from woorden where `unite`='1' ORDER BY RAND() limit 1 "));

echo $x["nederlands"];
$n = $x["nederlands"];
$f = $x["frans"] ;
echo ' ';
echo $x["frans"];

echo '<form action=http://unitedpoets.frihost.net/voc2000/index2.php target="iframe" method=POST>';
echo 'Frans: <input type=text name=frans />';
echo '<input type=hidden name=ans value=' . $f . '>';
echo '<input type=submit value=submit>';
echo '</form>';


echo '<iframe name="iframe" width="300" height="100" src="http://unitedpoets.frihost.net/voc2000/index2.php"></iframe>'
?>



Code:
<?php
include 'connect.php';
$variable2 = stripslashes($_POST["frans"]);
$variable = stripslashes($_POST["ans"]);


if($variable2 !="")
{
   
   if ($variable2==$variable)
      echo "Correct!";
   else
      echo 'Fout :( het juist antwoord was ' . $variable ;
}
else
{
}
?>
Peterssidan
$x["nederlands"] is "de echtgenote" and $x["frans"] is "l'épouse".

the problem is (if I have understand it correctly) that you only want both words to be the answer, "de echtgenote l'épouse". the problem is that you only add $x["frans"] to the hidden field. You have to add both of them I guess.
Poetsunited
no I only need the french part, because it just compares the answer ( which is the french word the user has to type ) and the db french word

the problem is that my hidden value only copies up to the first space... so if the answer is more then two words ( which is the case always ) it only shows the first one and drops the rest for some unknown reason :<
Peterssidan
ah, so you you mean when the French word is more than one word it gets wrong. You have to surround the word in quotes to send more than one word.
change
Code:
echo '<input type=hidden name=ans value=' . $f . '>';
to
Code:
echo '<input type=hidden name=ans value="' . $f . '">';
Poetsunited
Lol it works now I sorta feel stupid now lol

thanks for the help Smile

one more thing i'd like to ask ( sorry for all the questions lol :p ) is there a way to refresh the page when I submit form? because now if i submit, it stays on the same word so i'd have to manually refresh the page to make it show a new one
* or make the db generate a new one, on submit or something?

- kev -
Peterssidan
In that case I think you should not use the iframe. Instead have all code in index.php and send the form data to the page itself.

I hope you realize that it's very easy to cheat in this game because the answer is clearly visible in the source code.
Poetsunited
Lol i know... but its for people in my class, to study french... so its stupid if they 'cheat' since its in their interest to be honest


and good point :p i'll try it without the iframe

thanks again :p
Poetsunited
It worked, thanks a lot man Smile


- kev -
Related topics
Dreamweaver Help!
The noob needs help/Plz
Hey hello ALL!
Can't start building my web even that I posted 5 posts..HELP
Battlefield 2
A problem with my computer.....need help...plz
Help, I need LWP::Simple perl module!!
help plz
A little help would be nice...
need urgent help plz !
need help on PHP or HTML...
Hey Guys, A Little Help?
help plz
Need a little help with my JS
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.