jagguy Posted November 2, 2006 Share Posted November 2, 2006 Hi,When using php with mysql do you check for data problems with php and not mysql. The reason is that if you add a duplicate record for a primary key field mysql gives an error (not user friendly). So if you use pphp to check the to see if the data already exists then the mysql error won't be needed (you will search a table first manually with php before adding).This is a php issue and not a mysql issue , to help the user with data problems. Quote Link to comment Share on other sites More sharing options...
fenway Posted November 2, 2006 Share Posted November 2, 2006 You can capture the mysql error and handle it yourself, instead of just die()-ing. Quote Link to comment Share on other sites More sharing options...
gluck Posted November 2, 2006 Share Posted November 2, 2006 You need to check for an element before adding it else mysql will complain Quote Link to comment Share on other sites More sharing options...
fenway Posted November 2, 2006 Share Posted November 2, 2006 I don't know what you mean by "element"... but even if MySQL complains, this still never has to make it out to the user directly. Quote Link to comment Share on other sites More sharing options...
jagguy Posted November 3, 2006 Author Share Posted November 3, 2006 how do you test for an error with php? Quote Link to comment Share on other sites More sharing options...
fenway Posted November 3, 2006 Share Posted November 3, 2006 Well, I assume that the mysql_query() call with return something that evaluates to false... Quote Link to comment Share on other sites More sharing options...
jagguy Posted November 4, 2006 Author Share Posted November 4, 2006 q)Say I get an error with mysql and I want to redo my form entry screen.How can i get the html to select a php server program based on output, eg if true run this php file else run this file?q) Also how can i get a preview screen to happen with php,html as i want the user to see the form data and decide whether this is what they want to submit? Quote Link to comment Share on other sites More sharing options...
fenway Posted November 4, 2006 Share Posted November 4, 2006 1) I assume you mean using an include...2) I don't know what you mean. Quote Link to comment Share on other sites More sharing options...
.josh Posted November 4, 2006 Share Posted November 4, 2006 you would use mysql_error() to display the current error. for example:mysql_query('select blah from table') or die(mysql_error());as far as the "preview my form before I submit" thing - one way to do it is to have your form, user inputs their info, they submit the form. on the target script, you would display their info based on the posted variables in this "previewed" format that which you speak of. You would also want to start a session and make some session variables (or an array would be easier) to hold this information. then have your little button or whatever for the user to send it off for really real or go back and make changes. Whichever button the user decides to click, you would auto-insert the form with the session vars or else process their info using the session vars. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.