Re: im so stupid

From: Date: Mon, 11 Feb 2002 17:54:54 +0000
Subject: Re: im so stupid
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-11981@lists.php.net to get a copy of this message
MessageOk, but did you see I changed form tag to action=$PATH_INFO and because that I used if-else statement. As I said, I tried to keep all code into one file. And once you submitted the form tag you "go back" to use the same file (not register.php) but this time just part that inserting info into database. Afan ----- Original Message ----- From: Todd Williamsen To: 'Afan Pasalic' Sent: Monday, February 11, 2002 12:37 PM Subject: RE: [PHP-WIN] im so stupid i was being sarcastic... You added unnecessary code, so whats the point of using that code if it doesn't do anything? The way you wrote the IF statement, if the submit button is pressed execute this code. Doesn't make sense. how else would the code be executed? So the form tage with the action="register.php" tells the form button what to do, so you added redundant code. See what I mean? You can added the register.php page at the top if you don't want to type html code over again like this <? include "register.php"; ?> Get it? -----Original Message----- From: Afan Pasalic [mailto:afan@sprout.net] Sent: Monday, February 11, 2002 11:41 AM To: Todd Williamsen Subject: Re: [PHP-WIN] im so stupid Hi Todd, Your last email looks like "I'm not thankful". If you didn't catch: Chris posted that question this morning and I tried to help him, just like you. Afan ----- Original Message ----- From: Todd Williamsen To: 'Afan Pasalic' ; php-windows@lists.php.net Sent: Monday, February 11, 2002 12:21 PM Subject: RE: [PHP-WIN] im so stupid I gave you a simple solution, and you don't like it? There is no need for an IF-ELSE statement, its unecessary especially since you are just trying to get it to work. You can use the IF statements if you want to vaildate the form fields. Anyways... this is all you need for it to work. <?php $db = MSSQL_CONNECT($hostname,$username,$password); mssql_select_db($dbname); $sql = "insert into studenter(fornavn, etternavn) values ('$fornavn','$etternavn')"; $result = mssql_query($sql, $db); echo"<h2>You have successfully entered the following information $fornavn<br> $etternavn</h2>"; ?> <form method="post" action="register.php"> Fornavn: <input type="text" name="fornavn"><br> Etternavn: <input type="text" name="etternavn"><br> <input type="Submit" name="submit" value="Registrer"><br> </form> <?php } ?> <------NOT NECESSARY!! </body> </html> -----Original Message----- From: Afan Pasalic [mailto:afan@sprout.net] Sent: Monday, February 11, 2002 11:24 AM To: Todd Williamsen; php-windows@lists.php.net Subject: Re: [PHP-WIN] im so stupid No, I just thought with IF - ELSE statement to keep a whole code in one file. You think it's bad? I'm new in PHP and I thought it's correct way? Afan ----- Original Message ----- From: Todd Williamsen To: php-windows@lists.php.net Sent: Monday, February 11, 2002 12:09 PM Subject: Re: [PHP-WIN] im so stupid There is no need for the If and Else statement. Are you doing validation checking? "Afan Pasalic" <afan@sprout.net> wrote in message news:009d01c1b31f$be771d80$311f49d1@VAIO... Yes Todd, you're right. It looks now much better, but I just pointed to Chris what could solve the problem... Actually, I would rather do that everything in one file: <html> <head></head> <body> <?php if($submit) { $db = MSSQL_CONNECT($hostname,$username,$password); mssql_select_db($dbname); $sql = "insert into studenter(fornavn, etternavn) values ('$fornavn','$etternavn')"; $result = mssql_query($sql, $db); echo"<h2>You have successfully entered the following information $fornavn<br> $etternavn</h2>"; } else { ?> <form method="post" action="<?php echo $PATH_INFO ?>"> Fornavn: <input type="text" name="fornavn"><br> Etternavn: <input type="text" name="etternavn"><br> <input type="Submit" name="submit" value="Registrer"><br> </form> <?php } ?> </body> </html> Right? Afan ----- Original Message ----- From: Todd Williamsen To: php-windows@lists.php.net Sent: Monday, February 11, 2002 11:51 AM Subject: Re: [PHP-WIN] im so stupid Afan... First off, to make things easier and since you are calling register.php in your form... Just make a plain HTML page like this and name it whatever the hell you want <html> <head></head> <body><form method="post" action="registrer.php"> Fornavn: <input type="text" name="fornavn"><br> Etternavn: <input type="text" name="etternavn"><br> <input type="Submit" name="submit" value="Registrer"><br> </form> </body> </html> Then make your registrer.php page: $db = MSSQL_CONNECT($hostname,$username,$password); mssql_select_db($dbname); $sql = "insert into studenter(fornavn, etternavn) values ('$fornavn','$etternavn')"; $result = mssql_query($sql, $db); <html> <head> <title>Success!</title> <body> <h2>You have successfully entered the following information <? echo "$fornavn<br> $etternavn"; ?></h2> </body> </html> "Afan Pasalic" <afan@sprout.net> wrote in message news:005601c1b310$fa19ad80$311f49d1@VAIO... Try this: $db = MSSQL_CONNECT($hostname,$username,$password); mssql_select_db($dbname); $sql = "insert into studenter(fornavn, etternavn) values ('$fornavn','$etternavn')"; $result = mssql_query($sql, $db); Afan ----- Original Message ----- From: chris To: php-windows@lists.php.net Sent: Monday, February 11, 2002 6:10 AM Subject: [PHP-WIN] im so stupid I have made a script and for some reason i dont understand it doesnt do what its supposed to. maybe you can tell me whats wrong. its a form where im supposed to insert a new record in a mssql table. but when i hit submit it just refreshes blank. <html> <head></head> <body><form method="post" action="registrer.php"> Fornavn: <input type="text" name="fornavn"><br> Etternavn: <input type="text" name="etternavn"><br> <input type="Submit" name="submit" value="Registrer"><br> </form> <? IF (isset($submit)) { $hostname = "dbname"; $username = "chris"; $password = "*****"; $dbname = "chris"; MSSQL_CONNECT($hostname,$username,$password); mssql_select_db($dbname); $sql = "insert into studenter(fornavn, etternavn) values ('$fornavn','$etternavn')"; $result = mssql_query($sql); $studentnummer = mssql_insert_id(); Print("Studenten er lagt inn!"); } ?> </body> </html> -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.windows (#11981) next »