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

2 possible replies to a form, how to code?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

2 possible replies to a form, how to code?

Postby shewien » Wed Sep 25, 2002 6:21 am

My visitors have to submit a form. Every 50th submitter will receive a present. The 50th will get the message:"Congratulations! You are user number 50." All other users get:"Unfortunately, you are number ..."
I coded it like below, but it doesn't work.

Can anyone see where my mistake is?

<?php

if ($submit == "VERSTUUR"){

$connection=mysql_connect ("localhost","indianpearls","");
if ($connection==false){
echo mysql_errno().": ".mysql_error()."<br>";
exit;
}

$query="insert into deelnemer (nr, fname, lname, geslacht, adres, postcode, plaats, email, item, datum) values ('$nr','$fname','$lname','$geslacht','$adres','$postcode','$plaats','$email','$item',NOW())";
$result=mysql_db_query ("indianpearls_nl_db",$query);

$dothis = "select count(*) from deelnemer";
$result = mysql_db_query("indianpearls_nl_db",$dothis);
$number = mysql_num_rows($result);


if (!$number%50){

echo "Congratulations! You are user number $number[0].<br>";
echo "You will receive your present within the next 8 days.<br>";

}

else{

echo "Unfortunately, you are user number $number[0].<br>";
echo "Please try again soon.<br>";

}
else{

echo mysql_errno().": ".mysql_error()."<br>";
}
mysql_close();
}

else{

echo '
<body bgcolor="#FF9966">

<form method="post" action="testform.php">

<table border="0" width="100%">
<tr>
<td width="19%">Voornaam:</td>
<td width="81%"><input type="text" name="fname" size="25"></input></td>
</tr>
<tr>
<td width="19%">Achternaam:</td>
<td width="81%"><input type="text" name="lname" size="25"></input></td>
</tr>
<tr>
<td width="19%">Geslacht:</td>
<td width="81%"><input type="radio" name="geslacht" value="man">man <input type="radio" name="geslacht" value="vrouw">vrouw</input></td>
</tr>
<tr>
<td width="19%">Adres:</td>
<td width="81%"><input type="text" name="adres" size="25"></input></td>
</tr>
<tr>
<td width="19%">Postcode:</td>
<td width="81%"><input type="text" name="postcode" size="25"></input></td>
</tr>
<tr>
<td width="19%">Woonplaats:</td>
<td width="81%"><input type="text" name="plaats" size="25"></input></td>
</tr>
<tr>
<td width="19%">E-mail:</td>
<td width="81%"><input type="text" name="email" size="25"></input></td>
</tr>
<tr>
<td width="19%">DVD titel:</td>
<td width="81%"><input type="text" name="item" size="25"></input></td>
</tr>
</table>
<p>

<input type="submit" name="submit" value="VERSTUUR"></input>
</p></form>

</body>
';
}

?>
User avatar
shewien
New php-forum User
New php-forum User
 
Posts: 13
Joined: Wed Sep 25, 2002 6:13 am

Postby DoppyNL » Wed Sep 25, 2002 6:43 am

What error do you get?? what goes wrong??

or does the page always return as if the user was not no. 50 ??
in the that situation you will have to look at you're condition:
Code: Select all
if (!$number%50)

personally, I have never seen this construction, so I don't know if it is correct or not.

Greetz Daan
DoppyNL
 

this goes wrong.

Postby shewien » Wed Sep 25, 2002 6:49 am

I have never seen - if (!$number%50) - either, but someone suggested this on another php-forum. Can you suggest another code to get the same desired result?
When running this script, the error message is: "Parse error: parse error in testform.php on line 33"
User avatar
shewien
New php-forum User
New php-forum User
 
Posts: 13
Joined: Wed Sep 25, 2002 6:13 am

Postby DoppyNL » Wed Sep 25, 2002 6:56 am

on line 33 is an else-statement located wich php can't link to an if-statement.
You might have closed a block of code (behind an if-statement) to early or maybe you've misplaced the else-part.

Greetz Daan
DoppyNL
 

can't figure it out

Postby shewien » Wed Sep 25, 2002 7:10 am

I am very new at this php thing, and I really cannot see where the if-else mistake is in my code. Can anyone please look at my code suggest something?
User avatar
shewien
New php-forum User
New php-forum User
 
Posts: 13
Joined: Wed Sep 25, 2002 6:13 am

Postby DoppyNL » Wed Sep 25, 2002 7:21 am

This piece of code doesn't make sence on the location it's currently located (line 33 and following)
Code: Select all
else{

echo mysql_errno().": ".mysql_error()."<br>";
}




This isn't neccesary, php automaticly closes any connections at the end of the script. Note, there is nothing wrong with it!
Code: Select all
mysql_close();



You got a MASSIVE echo-statement, wich echo's loads of text
Code: Select all
echo ' Text to echo '

This looks nicer (if there is loads of text in between) and is probably more readable (and it works ofcourse ;))
Code: Select all
?> Text to echo <?php

You may conclude that you can switch between php-mode and html-mode any time in you're script!
This also "works", it output's "There's a difference!!"
Code: Select all
if ("little sheep" == "big cows")
{
    ?>
        blablabla
     <?php
}
else
{
   ?>
       There's a difference!!
   <?php
}


Greetz Daan
DoppyNL
 

thanks!

Postby shewien » Fri Sep 27, 2002 3:45 am

Thanks Doppy. You helped me out. I also wasn't aware of the switch possibility between php and html. My page now looks a lot better!

Thanks again!
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: Google Feedfetcher and 3 guests

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