varun_146100 Posted November 14, 2008 Share Posted November 14, 2008 Hi, I have a form from which the user inputs some data. Now i need to check from the database whether these are valid values or not since the values inputted can clash with the existing values. Here is the query: $sql="if exists(select * from EnvironmentBookingtest where EnvironmentId=$_POST[EnvName] and ((convert(varchar(10),convert( datetime,'$_POST[Date1]',103), 110 ) between StartDate and EndDate) OR (convert(varchar(10),convert( datetime,'$_POST[Date2]',103), 110 ) between StartDate and EndDate))) begin print 'wrong data' end else begin INSERT INTO EnvironmentBooking VALUES ($_POST[EnvName],'".$_POST[bookFor]."',convert(varchar(10),convert( datetime,'$_POST[Date1]',103), 110 ),convert(varchar(10),convert( datetime,'$_POST[Date2]',103), 110 ),'".$_POST[Purpose]."',getdate()) end"; sybase_query($sql) or die ('Error updating database'); Now what i want is that this message 'wrong data' should be printed on the form when the user inputs the data and hits the submit button. Or is there a way where i can add it as a validation using javascript such that it can be sent as an alert ?? Please help.Its urgently required. Link to comment https://forums.phpfreaks.com/topic/132680-validation-while-inserting-into-database/ Share on other sites More sharing options...
DarkerAngel Posted November 14, 2008 Share Posted November 14, 2008 First of all that SQL statement is just wow I don't know if I would even want to touch it, I don't know if it would work, but it's one of those thing that you see and think if I touch this thing I'm going to break it. Secondly I think JavaScript or better yet AJAX would be the way to go. AJAX can run the code in the background (the check), and once validated submit it. Link to comment https://forums.phpfreaks.com/topic/132680-validation-while-inserting-into-database/#findComment-690045 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.