poqoz-87 Posted May 10, 2007 Share Posted May 10, 2007 i can insert the fields into the ms sql database. what i am now trying to do is to validate the fields in the document. i have tried validating the fields, but then later, i cannot insert the data into the database. can someone show me an example of how to validate fields in a document? Link to comment https://forums.phpfreaks.com/topic/50789-how-to-validate-fields-in-a-doc-help-please/ Share on other sites More sharing options...
trq Posted May 10, 2007 Share Posted May 10, 2007 What document? Your post makes little sense. Link to comment https://forums.phpfreaks.com/topic/50789-how-to-validate-fields-in-a-doc-help-please/#findComment-249763 Share on other sites More sharing options...
poqoz-87 Posted May 11, 2007 Author Share Posted May 11, 2007 oopss. sorry. i m using php document and the database that i am using is ms sql database. i can connect the php document to the ms sql database. the codes that i am using to connect the php doc to the database is this: <?php if (!empty($_POST["submit"])) { $conn = mssql_connect("<my ip address>", "<my user name>", "<my pwd>"); mssql_select_db("lalalalalala", $conn); $sql = "INSERT INTO Hello (fname,lname)VALUES ("; $sql .= "'" . $_POST["fname"] . "', "; $sql .= "'" . $_POST["lname"] . "')"; mssql_query($sql, $conn); mssql_close($conn); echo("<p>Entry added to database!</p>"); } ?> what i am now trying to do is to validate both of these two fields(fname & lname), when the user clicks onto the submit button. can someone give me an example of code on how to validate both of these two fields? Link to comment https://forums.phpfreaks.com/topic/50789-how-to-validate-fields-in-a-doc-help-please/#findComment-250260 Share on other sites More sharing options...
StormTheGates Posted May 11, 2007 Share Posted May 11, 2007 You mean like make sure they have data in them? if(!$_POST['name']){ echo "You need to submit a name!"; } elseif(!$_POST['pass']){ echo "You need to submit a password!"; } else { // Do db stuff } Link to comment https://forums.phpfreaks.com/topic/50789-how-to-validate-fields-in-a-doc-help-please/#findComment-250277 Share on other sites More sharing options...
poqoz-87 Posted May 11, 2007 Author Share Posted May 11, 2007 but..ermm..where shall i put the code? Link to comment https://forums.phpfreaks.com/topic/50789-how-to-validate-fields-in-a-doc-help-please/#findComment-250309 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.