Rene, -{ Rene Brehmer }- said: > I'm not sure how to explain this, I'm totally new to MySQL and SQL as a > whole, this is my first ever code using SQL at all...so plz bare with me > here... > > I'm working with PHP 4.2.3 and MySQL 4.something (not certain what version > the end-server runs). > > For a game clan I'm in (MPE 1A in Earth: 2025 - 1a), I'm working on a DB > to > store some rather game-specific info. It's only a single table in the DB, > but the table is indexed by the field 'id'. > Is that your Primary Key? Does this ID have a meaning to you, or is it random? > Whenever someone wants to add data to the table, they fill out a form, hit > submit and either get an error about wrong or missing data, or if ok get a > preview before being able to finally add it to the table. As the script is > now, it will attempt to add the data to the table, but if already there, > nothing happens, and there's no response to the user about it. > Do you mean if the ID is already there? > I want it to give a feedback message that the data is already in the > table, > and bump ppl back to the edit form with that message. For the other things > the script checks, all it does is load the variable $error with the > error-message and set a phase-flag to the right value, and then the page > generation part knows that there's been an error, and regenerates the > entry > form with the submitted data. So what I want, is to have the add data part > to just change the two variables needed for the error system to see > there's > something wrong, but I've got no idea what I need to change in the code to > do that. I've searched google and the archives, but come up with > nothing... > > Here's the add-data part of the code...the variables in the comment is > just > so that I know what kind of data are in each variable, rather than what > they're actually set to in the DB: > > elseif ($phase == 3) { > /* > num / id = int > country = string > nw = int > gov = string > strat = string > ally = string > spies = int > totdef = int > totoff = int > owner = string > */ > mysql_connect($host,$username,$password); > @mysql_select_db($database) or die('Unable to select database'); > $query = "INSERT INTO ally2ally VALUES > ('".$_POST['num']."','".$_POST['country']."','".$_POST['nw']."','".$_POST['gov']."','".$_POST['strat']."','".$_POST['spies']."','".$_POST['totdef']."','".$_POST['totoff']."','".$_POST['ally']."','".$_POST['owner']."')"; > > mysql_query($query); > > mysql_close(); > } > > the error message part is simply this: > > <?php > // if there is an error in the submitted data, display the error > message > if (isset($error)) { > ?> > <table> > <tr> > <td><?php echo($error); ?></td> > </tr> > </table><br> > <br> > <?php > } > ?> > > The rest of the code is not essential in this aspect. I just need some > help > to figure out how to make the script tell the user that it can't add the > data because the ID is already in the database...(that's the first field > btw). I'm still not sure what exactly you want to do. But usually you make your ID an AUTO_INCREMENT. That way you don't have to worry about giving the same ID twice. Regards, Sebastian > > TIA > > Rene > -- > Rene Brehmer > aka Metalbunny > > http://metalbunny.net/ > References, tools, and other useful stuff... > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Once a problem is defined - it is half way solved. (Henry Ford) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php