<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=PHP-and-MySQL%2FC3%2FMySQL-Part-3%2FEnglish</id>
		<title>PHP-and-MySQL/C3/MySQL-Part-3/English - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=PHP-and-MySQL%2FC3%2FMySQL-Part-3%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C3/MySQL-Part-3/English&amp;action=history"/>
		<updated>2026-04-29T09:29:17Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C3/MySQL-Part-3/English&amp;diff=553&amp;oldid=prev</id>
		<title>Chandrika: Created page with '{| border=1 !Time !Narration |- |0:00 |Hi, welcome back. In this tutorial we will write some data into a database. |- |0:06 |To do this we will use our &quot;mysql query&quot; function. |-…'</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C3/MySQL-Part-3/English&amp;diff=553&amp;oldid=prev"/>
				<updated>2012-11-29T06:46:03Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;{| border=1 !Time !Narration |- |0:00 |Hi, welcome back. In this tutorial we will write some data into a database. |- |0:06 |To do this we will use our &amp;quot;mysql query&amp;quot; function. |-…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{| border=1&lt;br /&gt;
!Time&lt;br /&gt;
!Narration&lt;br /&gt;
|-&lt;br /&gt;
|0:00&lt;br /&gt;
|Hi, welcome back. In this tutorial we will write some data into a database.&lt;br /&gt;
|-&lt;br /&gt;
|0:06&lt;br /&gt;
|To do this we will use our &amp;quot;mysql query&amp;quot; function.&lt;br /&gt;
|-&lt;br /&gt;
|0:10&lt;br /&gt;
|Now you can see here that we have our... records.... &lt;br /&gt;
|-&lt;br /&gt;
|0:16&lt;br /&gt;
|I am redoing this tutorial because the first time I did it, it did not work. &lt;br /&gt;
|-&lt;br /&gt;
|0:21&lt;br /&gt;
|So first of all, I will just delete this data here.&lt;br /&gt;
|-&lt;br /&gt;
|0:29&lt;br /&gt;
|Well... ok... So we have a blank table, we have no data in our table whatsoever at the moment.&lt;br /&gt;
|-&lt;br /&gt;
|0:36&lt;br /&gt;
|we can see that there is nothing in here.&lt;br /&gt;
|-&lt;br /&gt;
|0:40&lt;br /&gt;
|These are just our field names here.&lt;br /&gt;
|-&lt;br /&gt;
|0:43&lt;br /&gt;
|To begin with, in here, lets just comment this.&lt;br /&gt;
|-&lt;br /&gt;
|0:47&lt;br /&gt;
|So &amp;quot;write some data&amp;quot;. Then we will set up a query that will write data.&lt;br /&gt;
|-&lt;br /&gt;
|0:52&lt;br /&gt;
|So... &amp;quot;write&amp;quot; and we will use &amp;quot;mysql query&amp;quot; function.&lt;br /&gt;
|-&lt;br /&gt;
|0:59&lt;br /&gt;
|And this takes exactly 1 parameter which is our sql query.&lt;br /&gt;
|-&lt;br /&gt;
|1:01&lt;br /&gt;
|To do this, we will type &amp;quot;INSERT&amp;quot; to insert data.&lt;br /&gt;
|-&lt;br /&gt;
|1:06&lt;br /&gt;
|We are going to say &amp;quot;INSERT INTO&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|1:09&lt;br /&gt;
|Now the reason I've typed this in capitals is because its sql code.&lt;br /&gt;
|-&lt;br /&gt;
|1:14&lt;br /&gt;
|If I type anything in uppercase it means it is sql code.&lt;br /&gt;
|-&lt;br /&gt;
|1:19&lt;br /&gt;
|If I type anything in lowercase it means its either a table name, database name or it is data that I'm writing to the database.&lt;br /&gt;
|- &lt;br /&gt;
|1:30&lt;br /&gt;
|So &amp;quot;INSERT INTO people&amp;quot; because that is our table name here.&lt;br /&gt;
|-&lt;br /&gt;
|1:34&lt;br /&gt;
| &amp;quot;INSERT INTO people&amp;quot; and then &amp;quot;VALUES&amp;quot; and then in brackets we will create a little area  for each value.&lt;br /&gt;
|-&lt;br /&gt;
|1:40&lt;br /&gt;
|So we got 1,2,3,4,5.&lt;br /&gt;
|-&lt;br /&gt;
|1:46&lt;br /&gt;
|There are 5 fields so we need exactly 5 pieces of database written here.&lt;br /&gt;
|-&lt;br /&gt;
|1:50&lt;br /&gt;
|We need the id, firstname, lastname, all the way down to gender.&lt;br /&gt;
|-&lt;br /&gt;
|1:55&lt;br /&gt;
|These are created in or created using single quotes each separated by comas.&lt;br /&gt;
|- &lt;br /&gt;
|2:03&lt;br /&gt;
|The reason we don't use double quotes is because we've got these at the end or rather start and end over here.&lt;br /&gt;
|-&lt;br /&gt;
|2:10&lt;br /&gt;
|We don't need to insert our id  here.&lt;br /&gt;
|-&lt;br /&gt;
|2:13&lt;br /&gt;
|Our next one is firstname - so I'll say &amp;quot;Alex&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|2:17&lt;br /&gt;
|My lastname I'll say is &amp;quot;Garrett&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|2:20&lt;br /&gt;
|For my date of birth I'll create a date function which equals to a variable &amp;quot;date&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
|2:26&lt;br /&gt;
|I'll put this in the particular structure.&lt;br /&gt;
|-&lt;br /&gt;
|2:28&lt;br /&gt;
|We can see from our database over here that when we go to insert a value, we can scroll down and see that our calender function has dates on it.&lt;br /&gt;
|-&lt;br /&gt;
|2:39&lt;br /&gt;
|So on clicking 23rd, we can see the structure this field takes.&lt;br /&gt;
|- &lt;br /&gt;
|2:45&lt;br /&gt;
|Its the year in long format.&lt;br /&gt;
|-&lt;br /&gt;
|2:47&lt;br /&gt;
|Next is the month and then the day.&lt;br /&gt;
|-&lt;br /&gt;
|2:48&lt;br /&gt;
|So 2009 02 23 which is 23rd of the 2nd, 2009.&lt;br /&gt;
|-&lt;br /&gt;
|2:54&lt;br /&gt;
|So what we can do here is we can structure our date function in capital Y  m and then d using hyphen in between to get the structure we need.&lt;br /&gt;
|-&lt;br /&gt;
|3:05&lt;br /&gt;
|So this will be structured like that.&lt;br /&gt;
|- &lt;br /&gt;
|3:09&lt;br /&gt;
|This will equal to this and that will be the current date.&lt;br /&gt;
|-&lt;br /&gt;
|3:13&lt;br /&gt;
|Using the date and presuming that is in the structure of our date, we can insert it into our table here.&lt;br /&gt;
|-&lt;br /&gt;
|3:24&lt;br /&gt;
|The last one is gender and since I'm a male, I'm putting in &amp;quot;M&amp;quot; for male.&lt;br /&gt;
|-&lt;br /&gt;
|3:28&lt;br /&gt;
|Presuming that will work, we can run this.&lt;br /&gt;
|-&lt;br /&gt;
|3:30&lt;br /&gt;
|But before that, we could say &amp;quot;or die&amp;quot; at the end followed by a mysql error.&lt;br /&gt;
|-&lt;br /&gt;
|3:38&lt;br /&gt;
|I will skip that for now but feel free to add them if you like.&lt;br /&gt;
|-&lt;br /&gt;
|3:44&lt;br /&gt;
|Ok so refreshing our page. &lt;br /&gt;
|-&lt;br /&gt;
|3:48&lt;br /&gt;
|What you see is from the last tutorial. &lt;br /&gt;
|- &lt;br /&gt;
|3:50&lt;br /&gt;
|ummmm..... Lets comment this out.&lt;br /&gt;
|-&lt;br /&gt;
|3:56&lt;br /&gt;
|Lets ignore this.&lt;br /&gt;
|-&lt;br /&gt;
|3:57&lt;br /&gt;
|This will completely ignore this part of tutorial.&lt;br /&gt;
|-&lt;br /&gt;
|4:02&lt;br /&gt;
|Ok - so back to the code that I am currently showing and lets refresh.&lt;br /&gt;
|-&lt;br /&gt;
|4:10&lt;br /&gt;
| I've refreshed it twice so accordingly 2 records have been put in.&lt;br /&gt;
|-&lt;br /&gt;
|4:14&lt;br /&gt;
|But by going back to browse and scrolling down we can see, lets delete 1 of these, we can see the data I just specified has been put into the database.&lt;br /&gt;
|-&lt;br /&gt;
|4:26&lt;br /&gt;
|In fact what I have done is I have put my date of birth as the current date which I didn't mean to do.&lt;br /&gt;
|-&lt;br /&gt;
|4:33&lt;br /&gt;
|I don't want my date of birth as the current date because I was not born today.&lt;br /&gt;
|-&lt;br /&gt;
|4:39&lt;br /&gt;
|My firstname is ok.  My lastname is ok.  My gender is fine.&lt;br /&gt;
|-&lt;br /&gt;
|4:43&lt;br /&gt;
|We can see that my id is 6 at the moment and the next time we insert a record this would go up to 7 and then again to 8.&lt;br /&gt;
|- &lt;br /&gt;
|4:53&lt;br /&gt;
|You should know that by now.&lt;br /&gt;
|-&lt;br /&gt;
|4:54&lt;br /&gt;
|Next what I'll show you is how to change my date of birth because I have made a mistake.&lt;br /&gt;
|-&lt;br /&gt;
|5:00&lt;br /&gt;
|So first I will comment these 2 lines so we don't have to rerun this.&lt;br /&gt;
|-&lt;br /&gt;
|5:04&lt;br /&gt;
|And I'll create a new variable.  We will just comment this as &amp;quot;update data&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|5:08&lt;br /&gt;
|Current variable called &amp;quot;update&amp;quot; and that's equal to &amp;quot;mysql query&amp;quot; function.&lt;br /&gt;
|-&lt;br /&gt;
|5:14&lt;br /&gt;
|And inside the parameter that we are calling is &amp;quot;mysql query&amp;quot; code itself.&lt;br /&gt;
|-&lt;br /&gt;
|5:20&lt;br /&gt;
|So here we will type &amp;quot;UPDATE&amp;quot; and we are going to say the table name which is &amp;quot;people&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|5:28&lt;br /&gt;
|Then we will say &amp;quot;SET&amp;quot; and we need to pick a particular field in which to set.&lt;br /&gt;
|-&lt;br /&gt;
|5:34&lt;br /&gt;
|This happens to be the &amp;quot;d o b&amp;quot; and that's equal to my actual date of birth which is 1989, the year I was born in and the month is November and the day I was born is 16th.&lt;br /&gt;
|-&lt;br /&gt;
|5:47&lt;br /&gt;
|By running this command what we are actually doing is we are updating everyone's date of birth in this table to this.&lt;br /&gt;
|- &lt;br /&gt;
|5:54&lt;br /&gt;
|That's because we've not specified where we want to update this.&lt;br /&gt;
|-&lt;br /&gt;
|5:57&lt;br /&gt;
|But we can do is after this we can say &amp;quot;WHERE id=6&amp;quot; because my unique id is 6.&lt;br /&gt;
|-&lt;br /&gt;
|6:08&lt;br /&gt;
|Lets have a look here.&lt;br /&gt;
|-&lt;br /&gt;
|6:10&lt;br /&gt;
|Otherwise it will update everyone else's.&lt;br /&gt;
|-&lt;br /&gt;
|6:12&lt;br /&gt;
|Remember I said the id is unique.  Its better to say update my id. &lt;br /&gt;
|-&lt;br /&gt;
|6:16&lt;br /&gt;
|What I could do instead, is say, &amp;quot;WHERE firstname equals Alex&amp;quot;.  However this will update every record that has firstname &amp;quot;Alex&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|6:24&lt;br /&gt;
|But we can also say &amp;quot;AND lastname equals Garrett&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
|6:26&lt;br /&gt;
|However if we still have two people in the database with the same firstname and lastname, we are still running the same risk as before.&lt;br /&gt;
|-&lt;br /&gt;
|6:43&lt;br /&gt;
|So its best to use our &amp;quot;unique&amp;quot; and thats the key word &amp;quot;unique id&amp;quot; which for me is 6.&lt;br /&gt;
|-&lt;br /&gt;
|6:48&lt;br /&gt;
|So at the moment, you can see that my date of birth is set to 2009 which is the current date.&lt;br /&gt;
|-&lt;br /&gt;
|6:53&lt;br /&gt;
|But by refreshing this page, nothing's happened because we are just running a command.&lt;br /&gt;
|-&lt;br /&gt;
|7:00&lt;br /&gt;
|Now if we click on browse to refresh and we scroll down, we can see that it has changed to what we specified and everything else has been left intact.&lt;br /&gt;
|-&lt;br /&gt;
|7:08&lt;br /&gt;
|So if you need to update data in your database or anything like that, you can specify what data you want to update.&lt;br /&gt;
|-&lt;br /&gt;
|7:15&lt;br /&gt;
|I used &amp;quot;dob&amp;quot; and that equals to the date of birth that was necessary.&lt;br /&gt;
|- &lt;br /&gt;
|7:18&lt;br /&gt;
|I could have updated my lastname.&lt;br /&gt;
|-&lt;br /&gt;
|7:20&lt;br /&gt;
|You also need to specify where you want this to be updated.&lt;br /&gt;
|-&lt;br /&gt;
|7:24&lt;br /&gt;
|So I said this record which is this long line here.&lt;br /&gt;
|-&lt;br /&gt;
|7:28&lt;br /&gt;
|These are called records and I specified &amp;quot;WHERE&amp;quot; the id was equal to 6 and that has updated my unique record.&lt;br /&gt;
|-&lt;br /&gt;
|7:35&lt;br /&gt;
|So that's what you have learnt - how to insert values and also how to update some values if you get it wrong like I did or if you just want to update some data which happens most of the time when your doing your databases.&lt;br /&gt;
|-&lt;br /&gt;
|7:54&lt;br /&gt;
|Ok - so join me in the next part to find out how to start reading from your database and display the data to the user.&lt;br /&gt;
|-&lt;br /&gt;
|8:04&lt;br /&gt;
|See you soon.  This is Juanita Jayakar dubbing for the Spoken Tutorial Project.&lt;/div&gt;</summary>
		<author><name>Chandrika</name></author>	</entry>

	</feed>