Skip to content
View in the app

A better way to browse. Learn more.

Tip.It Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PHP/SQL question

Featured Replies

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:

 

 

 

 

 

 

 

sqlen6.png

 

 

 

 

 

 

 

Now, sometimes when I enter data, it inputs it into the table in a weird table:

 

 

 

 

 

 

 

sql1fg1.png

 

 

 

(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?

summerpngwy6.jpg

What is the SQL code you used to make the tables? There could be an error with that.

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. :-$

  • 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.

summerpngwy6.jpg

Looks fine to me.

 

 

 

 

 

 

 

 

 

 

 

mySQL has a habit of ordering data oddly; but it's nothing to be worried about.

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)

  • 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

summerpngwy6.jpg

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.