473,418 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ


PHP and Writing to MySQL Databases Explained

By Blair Ireland
Senior Editor, TheScripts.com

Code Instructions

Now I better explain everything....

$host is the name of the host that the MySQL server is running off of, pretty self explanatory. $user and $pass are your username and password that you use to connect to your MySQL server account. $DBName is the name of your database, and $table is the specific table you have created to insert all this wonderful information.

All of those variables did not have to be made, they could have just been inserted into the actual function. I find it makes everything easier to read if you do it like this though.

$sqlquery is what we want to send to MySQL as, well, our query. This utilizes the MySQL syntax, giving you another reason to want to learn it. The function using this $sqlquery variables is mysql_query. This function just passes the information you specified to MySQL, and allows it to perform what you asked.

For $sqlquery though, notice the order I sent everything into MySQL, everything is in the order that I originally made the table with. You must put everything in the order you made the table in, or else you are putting stuff in the wrong place.

Lets look back at the form though, at the line <input type="hidden" name="id" value="NULL">. The reason I made this value "NULL" is because, when we made the table, we specified id INT NOT NULL AUTO_INCREMENT. This means that the id value cannot be NULL, and it automatically increments up 1 from the last value. This way, we get a unique id number for each record.

Give it a try.... if you check your database afterwards, you will see your entry in the db....

« First Things First  

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.