December 29, 200619 yr 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?
December 30, 200619 yr What is the SQL code you used to make the tables? There could be an error with that.
December 30, 200619 yr 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. :-$
December 30, 200619 yr Author 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.
December 30, 200619 yr Looks fine to me. mySQL has a habit of ordering data oddly; but it's nothing to be worried about.
December 30, 200619 yr 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)
December 30, 200619 yr Author 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
Create an account or sign in to comment