FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


I'm doing something wrong,,,





golles
I'm doing something wrong when I check if a form is filled in.

this is the code that checkes the form:
Code:

if ($voornaam == "")
$msg1 = "Uw voornaam is niet ingevuld!<br>";
if ($achternaam == "")
$msg2 = "Uw achternaam is niet ingevuld!<br>";
if ($telefoonnummer == "")
$msg3 = "Uw telefoonnummer is niet ingevuld!<br>";
if ($emailadres == "")
$msg4 = "Uw e-mailadres is niet ingevuld!<br>";
if ($gebruikersnaam == "")
$msg5 = "Uw gebruikersnaam is niet ingevuld!<br>";
if ($wachtwoord == "")
$msg6 = "Uw wachtwoord is niet ingevuld!<br>";

else


afther the else comes a code that put the data in a mysql.

when I just hit the form button i get multiple errors:
Quote:


Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in C:\Documents and Settings\golles\Mijn documenten\Website\Project PHP en MySQL\registratie.php on line 36

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Documents and Settings\golles\Mijn documenten\Website\Project PHP en MySQL\registratie.php on line 38

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\Documents and Settings\golles\Mijn documenten\Website\Project PHP en MySQL\registratie.php on line 38

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Documents and Settings\golles\Mijn documenten\Website\Project PHP en MySQL\registratie.php on line 40

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\Documents and Settings\golles\Mijn documenten\Website\Project PHP en MySQL\registratie.php on line 40

Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in C:\Documents and Settings\golles\Mijn documenten\Website\Project PHP en MySQL\registratie.php on line 42

Warning: Cannot modify header information - headers already sent by (output started at C:\Documents and Settings\golles\Mijn documenten\Website\Project PHP en MySQL\registratie.php:36) in C:\Documents and Settings\golles\Mijn documenten\Website\Project PHP en MySQL\registratie.php on line 45


I think the if, if, if,,, else is wrong. the code should stop if one of these fields is empty.

hmm when I only fill in a wachtwoord (password) then it doesn't give any error and goes to the script completly Shocked

please hellup Embarassed
Stubru Freak
First, the code should be:

Code:
if ($voornaam == "")
$msg1 = "Uw voornaam is niet ingevuld!<br>";
elseif ($achternaam == "")
$msg2 = "Uw achternaam is niet ingevuld!<br>";
elseif ($telefoonnummer == "")
$msg3 = "Uw telefoonnummer is niet ingevuld!<br>";
elseif ($emailadres == "")
$msg4 = "Uw e-mailadres is niet ingevuld!<br>";
elseif ($gebruikersnaam == "")
$msg5 = "Uw gebruikersnaam is niet ingevuld!<br>";
elseif ($wachtwoord == "")
$msg6 = "Uw wachtwoord is niet ingevuld!<br>";

else


Otherwise the else only applies to the wachtwoord (password) if.
So if your telephone isn't filled in, it will tell you, but continue processing the else block.

The rest of your errors are after the else.
Please post the code there.
coreymanshack
there is something wrong with php/mysql interaction... i can think of some things that could be wrong..

1) Wrong DB Type
2) Wrong DB
3) DB doesn't exist
4) Wrong DB Password

It's something to do with connecting to the database... all of your other mysql queries are failing because of the db is failing to connect correctly...
golles
Stubru Freak wrote:
First, the code should be:

Code:
if ($voornaam == "")
$msg1 = "Uw voornaam is niet ingevuld!<br>";
elseif ($achternaam == "")
$msg2 = "Uw achternaam is niet ingevuld!<br>";
elseif ($telefoonnummer == "")
$msg3 = "Uw telefoonnummer is niet ingevuld!<br>";
elseif ($emailadres == "")
$msg4 = "Uw e-mailadres is niet ingevuld!<br>";
elseif ($gebruikersnaam == "")
$msg5 = "Uw gebruikersnaam is niet ingevuld!<br>";
elseif ($wachtwoord == "")
$msg6 = "Uw wachtwoord is niet ingevuld!<br>";

else


Otherwise the else only applies to the wachtwoord (password) if.
So if your telephone isn't filled in, it will tell you, but continue processing the else block.

The rest of your errors are after the else.
Please post the code there.


I knew about the elseif, but now I only get one foutbericht (error message) so I should make a new if, elseif, else for executing the other part of the code?

Code:

<?php
//conrtoleren of de post leeg is
if (empty($_POST)){}
else{
//alleen de code uitvoeren als de post niet leeg is

//post gegevens uitlezen
$voornaam = $_POST[voornaam];
$tussenvoegsel = $_POST[tussenvoegsel];
$achternaam = $_POST[achternaam];
$telefoonnummer = $_POST[telefoonnummer];
$emailadres = $_POST[emailadres];
$gebruikersnaam = $_POST[gebruikersnaam];
$wachtwoord = $_POST[wachtwoord];
$datum = $_POST[datum];

//fout berichten
if ($voornaam == "")
$msg1 = "Uw voornaam is niet ingevuld!<br>";
elseif ($achternaam == "")
$msg2 = "Uw achternaam is niet ingevuld!<br>";
elseif ($telefoonnummer == "")
$msg3 = "Uw telefoonnummer is niet ingevuld!<br>";
elseif ($emailadres == "")
$msg4 = "Uw e-mailadres is niet ingevuld!<br>";
elseif ($gebruikersnaam == "")
$msg5 = "Uw gebruikersnaam is niet ingevuld!<br>";
elseif ($wachtwoord == "")
$msg6 = "Uw wachtwoord is niet ingevuld!<br>";

else

//code dat word uitgevoerd als alle velden goed zijn ingevuld

//gegevens aan de database toevoegen
$con = mysql_connect("localhost","root");
mysql_select_db("hotel", $con);

mysql_query("INSERT INTO login (gebruikersnaam, wachtwoord, email) VALUES('$gebruikersnaam', '$wachtwoord', '$emailadres' ) "); 

mysql_query("INSERT INTO klanten (voornaam, tussenvoegsel, achternaam, telefoonnummer, datum) VALUES('$voornaam', '$tussenvoegsel', '$achternaam', '$telefoonnummer', '$datum' ) "); 

mysql_close($con);

//alles is goed, volgende pagina kan aangeroepen worden
header("Location: reservering.php")
?>

<?php } ?>

coreymanshack wrote:
there is something wrong with php/mysql interaction... i can think of some things that could be wrong..

1) Wrong DB Type
2) Wrong DB
3) DB doesn't exist
4) Wrong DB Password

It's something to do with connecting to the database... all of your other mysql queries are failing because of the db is failing to connect correctly...

I only get the error when some fields aren't filled in and press the button
Stubru Freak
golles wrote:
I knew about the elseif, but now I only get one foutbericht (error message) so I should make a new if, elseif, else for executing the other part of the code?


If you want multiple error messages you would need something like this:

Code:

$ok = true;

if ($voornaam == ""){
$msg1 = "Uw voornaam is niet ingevuld!<br>";
$ok = false;
}
if ($achternaam == ""){
$msg2 = "Uw achternaam is niet ingevuld!<br>";
$ok = false;
}
if ($telefoonnummer == ""){
$msg3 = "Uw telefoonnummer is niet ingevuld!<br>";
$ok = false;
}
if ($emailadres == ""){
$msg4 = "Uw e-mailadres is niet ingevuld!<br>";
$ok = false;
}
if ($gebruikersnaam == ""){
$msg5 = "Uw gebruikersnaam is niet ingevuld!<br>";
$ok = false;
}
if ($wachtwoord == ""){
$msg6 = "Uw wachtwoord is niet ingevuld!<br>";
$ok = false;
}

if($ok == true){
//What would normally be your else


And why are you saving the messages in variables? Shouldn't you just echo them?
d4rch
Hello !

I think your errors come from this line :
Code:

$con = mysql_connect("localhost","root");


Try to add the password like that :
Code:

$con = mysql_connect("localhost","root","");


I think that even if the password is empty you have to add "" otherwise the line is not unstertood...

Say me if it works
SlowWalkere
When you call mysql_connect, you don't need to supply a parameter for the password. According to php.net, password is an optional parameter with a default value of "".

As for recording error messages, there is good reason to save the messages to a variable first. This way you can do your script processing at the top of your html and keep it separate from the rest of the page. Then, in the presentation of the page all you have to do is check for any saved errors and output them.

As for the error you're getting, it's most definitely because of the structure of the if/else statements.

If any of the fields is not filled in, the if statements stop executing and they never get to the last else statement. That last else statement contains no brackets, so it only contains the one line: mysql_connect().

What is happening is that a field is empty, an error msg is plugged in, and that else statement is never executed. Therefore $con is never defined by mysql_connect, and $con is not a valid resource. But because there are no brackets around the code block, the next line tries to execute anyway (the mysql_select_db). At that point you pass a variable that is not a valid connection and get a whole string of errors.

Solution - Put brackets around that last else statement. First backet should go before "$con = ..." and the closing bracket I think should go after the header() call.

And, modify your if/else statements like Stubru posted if you want to get all of the applicable error msgs.

Good luck,
- Walkere
golles
thank you Stubru Freak, I was thinking of that a few days ago, but I f*cked up the code so I ctrl-z'ed till I was back to my old code again,,, Embarassed

@ SlowWalkere so an if else is only 1 line? if you want to use multiple lines you should use '{' and '}'?
thank you for your time!

last question:
why do I need to do this:
Code:

?>
<?php }} ?>


if I add the closing brackets into the first <?php ?> then it gives me errors and when I do it the way above the code is working good?????? Confused Confused Confused

Quote:
Parse error: parse error, unexpected '}' in C:\Documents and Settings\golles\Mijn documenten\Website\Project PHP en MySQL\registratie.php on line 60


complete code:
Code:
<?php
//conrtoleren of de post leeg is
if (empty($_POST)){}
else{
//alleen de code uitvoeren als de post niet leeg is

//post gegevens uitlezen
$voornaam = $_POST[voornaam];
$tussenvoegsel = $_POST[tussenvoegsel];
$achternaam = $_POST[achternaam];
$telefoonnummer = $_POST[telefoonnummer];
$emailadres = $_POST[emailadres];
$gebruikersnaam = $_POST[gebruikersnaam];
$wachtwoord = $_POST[wachtwoord];
$datum = $_POST[datum];

//fout berichten
$formcheck = true;

if ($voornaam == ""){
$msg1 = "Uw voornaam is niet ingevuld!<br>";
$formcheck = false;
}
if ($achternaam == ""){
$msg2 = "Uw achternaam is niet ingevuld!<br>";
$formcheck = false;
}
if ($telefoonnummer == ""){
$msg3 = "Uw telefoonnummer is niet ingevuld!<br>";
$formcheck = false;
}
if ($emailadres == ""){
$msg4 = "Uw e-mailadres is niet ingevuld!<br>";
$formcheck = false;
}
if ($gebruikersnaam == ""){
$msg5 = "Uw gebruikersnaam is niet ingevuld!<br>";
$formcheck = false;
}
if ($wachtwoord == ""){
$msg6 = "Uw wachtwoord is niet ingevuld!<br>";
$formcheck = false;
}

if($formcheck == true){
//code dat word uitgevoerd als alle velden goed zijn ingevuld

//gegevens aan de database toevoegen
$con = mysql_connect("localhost","root", "");
mysql_select_db("hotel", $con);

mysql_query("INSERT INTO login (gebruikersnaam, wachtwoord, email) VALUES('$gebruikersnaam', '$wachtwoord', '$emailadres' ) "); 

mysql_query("INSERT INTO klanten (voornaam, tussenvoegsel, achternaam, telefoonnummer, datum) VALUES('$voornaam', '$tussenvoegsel', '$achternaam', '$telefoonnummer', '$datum' ) "); 

mysql_close($con);

//alles is goed, volgende pagina kan aangeroepen worden
header("Location: reservering.php")
?>

<?php }} ?>
devroom
Code:

..............................
mysql_close($con);

//alles is goed, volgende pagina kan aangeroepen worden
header("Location: reservering.php")
}

 ?>


You just had one } too much.
golles
devroom wrote:
Code:

..............................
mysql_close($con);

//alles is goed, volgende pagina kan aangeroepen worden
header("Location: reservering.php")
}

 ?>


You just had one } too much.

I don't have

Code:
else{

Code:
if($formcheck == true){


why do I have to start a new <?php to close those^ 2 brackets? Confused < mathiaus: smilies removed >
golles
I allready saw my error I forgot a ; afther the header()Embarassed < mathiaus: smilies removed >
allways forget those stupid ;'s

guy's thanks for the wonderfull help!!
Related topics
Website Dont Work?
Can't access FTP
Can't get on to cpanel!!
FTP User Pass Invalid?
Just an article that got my attention...
Now how to make this work???
n0obie4life read
[RESOLVED] Need Help with pphlogger
JavaScript confirm() problem
need php help save command
PHP index page not displaying problem
problem with attached css style sheet
[RESOLVED] 'localhost' database connection error!
CGI-bin script help
I guess I'm doing something wrong...
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.