insane Posted December 29, 2006 Share Posted December 29, 2006 I've just started to dabble in PHP/SQL, and I've run into a problem. I have a page set up so that you can enter your name and age, and it will enter these into an SQL database. The description of the table is as follows: Now, sometimes when I enter data, it inputs it into the table in a weird table: (note the 50,49,48 in the id field). My input script is as follows: <?php if (isset($_POST['name'])) { $name = $_POST['name']; $age = $_POST['age']; $booleanage = validAge($age); if (!$booleanage) { exit(' invalid age entered.'); } $sql = "INSERT INTO table_name (name, age) VALUES ('$name', $age)"; if (@mysql_query($sql)) { echo ' name entered into database';} else { echo ' error entering name & age into database: ' . mysql_error() . ''; } } ?> Any thoughts? Link to comment Share on other sites More sharing options...
Earpy Posted December 30, 2006 Share Posted December 30, 2006 What is the SQL code you used to make the tables? There could be an error with that. Link to comment Share on other sites More sharing options...
Cruiser Posted December 30, 2006 Share Posted December 30, 2006 I have little experience using mySQL, but have you been deleting other records as you add? The auto increment won't reuse IDs are far as I know. It never did when I was playing around with it anyway. :? Another side note, the mySQL query browser is so much nicer than the command line. :-$ Link to comment Share on other sites More sharing options...
insane Posted December 30, 2006 Author Share Posted December 30, 2006 What is the SQL code you used to make the tables? There could be an error with that. It's in the php script: $sql = "INSERT INTO table_name (name, age) VALUES ('$name', $age)"; but have you been deleting other records as you add? The auto increment won't reuse IDs are far as I know. Yes I have been deleting as I add but I don't see it as relevant. I added the record with id 48 first, then 49, then 50. But they are ordered 50, 49, and 48 in the table. Link to comment Share on other sites More sharing options...
____ Posted December 30, 2006 Share Posted December 30, 2006 Looks fine to me. mySQL has a habit of ordering data oddly; but it's nothing to be worried about. Link to comment Share on other sites More sharing options...
Olgath Posted December 30, 2006 Share Posted December 30, 2006 Data in an sql table is not necessarily put in the order you placed it in. That's why there is an ORDER BY statement. SELECT * FROM table ORDER BY columname theorderyouwant theorderyouwant = ASC(ascending) or DESC(descending) Link to comment Share on other sites More sharing options...
insane Posted December 30, 2006 Author Share Posted December 30, 2006 Data in an sql table is not necessarily put in the order you placed it in. That's why there is an ORDER BY statement. SELECT * FROM table ORDER BY columname theorderyouwant theorderyouwant = ASC(ascending) or DESC(descending) That's it. Thank you very much :D Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now