<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mdpai.com - Blogging + Tutorial PHP, MySQL, Ajax, Photoshop, Javascript &#187; Tutorial PHP</title>
	<atom:link href="http://www.mdpai.com/category/tutorial-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mdpai.com</link>
	<description>tutorial php bahasa melayu, mysql, ajax, photoshop, javascript, html, css - mdpai.com</description>
	<lastBuildDate>Mon, 25 Jan 2010 22:23:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Lindungi code anda dari SQL Injection</title>
		<link>http://www.mdpai.com/tutorial-php/lindungi-code-anda-dari-sql-injection/</link>
		<comments>http://www.mdpai.com/tutorial-php/lindungi-code-anda-dari-sql-injection/#comments</comments>
		<pubDate>Fri, 21 Mar 2008 22:23:34 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[PHP Snippet]]></category>
		<category><![CDATA[Tutorial PHP]]></category>
		<category><![CDATA[]]></category>
		<category><![CDATA[addslashes]]></category>
		<category><![CDATA[basic php tutorial]]></category>
		<category><![CDATA[sql injection]]></category>

		<guid isPermaLink="false">http://www.mdpai.com/tutorial-php/lindungi-code-anda-dari-sql-injection/</guid>
		<description><![CDATA[Anda tentu pernah dengar tentang SQL injection bukan, ia adalah salah satu cara hacker/cracker untuk memecah/mengodam/menukar data anda yang disimpan di dalan database SQL.
Mereka yang ingin melakukan SQL injection ini akan mencari entry point / attack surface / backdoor yang membolehkan mereka memecah masuk ke dalam database kita. Jadi untuk mengelakkan perkara ini berlaku, sebagai [...]]]></description>
			<content:encoded><![CDATA[<p>Anda tentu pernah dengar tentang SQL injection bukan, ia adalah salah satu cara hacker/cracker untuk memecah/mengodam/menukar data anda yang disimpan di dalan database SQL.</p>
<p>Mereka yang ingin melakukan SQL injection ini akan mencari entry point / attack surface / backdoor yang membolehkan mereka memecah masuk ke dalam database kita. Jadi untuk mengelakkan perkara ini berlaku, sebagai programmer kita perlu memastikan semua input yang dimasukkan oleh user valid dan tiada unsur hacking. Dalam istilah english, ia dipanggil sanitization of user inputs to decrease the attack surface. (mana tau kot2 anda nak googling lepas baca tutorial ni kan?).</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p224code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2242"><td class="code" id="p224code2"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> sql_quote<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$value</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">get_magic_quotes_gpc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$value</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//check if this function exists</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;mysql_real_escape_string&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$value</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//for PHP version &amp;lt; 4.3.0 use addslashes</span>
&nbsp;
<span style="color: #b1b100;">else</span>
&nbsp;
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #990000;">addslashes</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$value</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Contoh penggunaan, saya ambil contoh mudah;<br />
Katakan anda mempunyai variable $_POST['username] . Jadi apa yang perlu anda lakukan sebelum melakukan apa2 SQL query adalah $username = sql_quote($_POST['username']);</p>
<p>sng bukan? tiada lagi ancaman sql injection.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mdpai.com/tutorial-php/lindungi-code-anda-dari-sql-injection/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Generate PDF menggunakan PHP (Class FPDF)</title>
		<link>http://www.mdpai.com/tutorial-php/generate-pdf-menggunakan-php-class-fpdf/</link>
		<comments>http://www.mdpai.com/tutorial-php/generate-pdf-menggunakan-php-class-fpdf/#comments</comments>
		<pubDate>Wed, 31 Oct 2007 18:05:42 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[Tutorial PHP]]></category>

		<guid isPermaLink="false">http://www.mdpai.com/tutorial-php/generate-pdf-menggunakan-php-class-fpdf/</guid>
		<description><![CDATA[Salam kepada semua pengunjung mdpai.com,
Buat masa sekarang saya amat sibuk dengan projek2 yang datelinenya semakin hampir, so kalau YM anda tak terbalas tu, faham2 la ye. jangan merajuk pulak dah tak tegur saya dah. =) So hari ni saya akan menulis tentang bagaimana membina file pdf menggunakan php, atau lebih tepat lagi dengan menggunakan class [...]]]></description>
			<content:encoded><![CDATA[<p>Salam kepada semua pengunjung mdpai.com,</p>
<p>Buat masa sekarang saya amat sibuk dengan projek2 yang datelinenya semakin hampir, so kalau YM anda tak terbalas tu, faham2 la ye. jangan merajuk pulak dah tak tegur saya dah. =) So hari ni saya akan menulis tentang bagaimana membina file pdf menggunakan php, atau lebih tepat lagi dengan menggunakan class FPDF (free PDF)  dari  Olivier Plathey (client terbaru sy meminta supaya data2 dari database di print dengan lawa dan tersusun. So saya ambil keputusan untuk menggunakan class fpdf ni. Alang2, ada bahan untuk dimuatkan kat mdpai.com). File untuk class ini boleh didapati di <a href="http://www.phpclasses.org/browse/package/421.html" target="_blank">sini.</a></p>
<p>Di antara features FPDF adalah;</p>
<p>- Choice of measure unit, page format and margins<br />
- Page header and footer management<br />
- Automatic page break<br />
- Automatic line break and text justification<br />
- Image support (JPEG and PNG)<br />
- Colors<br />
- Links<br />
- TrueType and encoding support (Central European, Cyrillic and Greek)<br />
- Page compression</p>
<p>*dipetik dari phpclasses.org</p>
<p><span id="more-208"></span></p>
<p><strike>Contoh penggunaan akan saya post kemudian setelah saya membaca kesemua documentation yang ada. Tapi jika anda tak sabar, boleh terus baca di website fpdf.</strike></p>
<p>Ok, saya akan terangkan secara asas bagaimana menggunakan class ini untuk kegunaan anda.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mdpai.com/tutorial-php/generate-pdf-menggunakan-php-class-fpdf/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL Function dalam PHP : 1</title>
		<link>http://www.mdpai.com/tutorial-php/mysql-function-dalam-php-1/</link>
		<comments>http://www.mdpai.com/tutorial-php/mysql-function-dalam-php-1/#comments</comments>
		<pubDate>Mon, 10 Sep 2007 19:10:36 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[Tutorial PHP]]></category>

		<guid isPermaLink="false">http://www.mdpai.com/tutorial-php/mysql-function-dalam-php-1/</guid>
		<description><![CDATA[Dalam post saya yang lepas, saya menerangkan tentang command SQL yang boleh kita pakai jika kita menggunakan PHP dengan database. Post kali ini pula, saya akan menerangkan tentang function2 MySQL yang boleh kita guna pakai dalam PHP termasuk dengan parameter function2 tersebut. Dalam bahagian 1 ini, saya hanya akan terangkan beberapa fungsi yang asas (yang [...]]]></description>
			<content:encoded><![CDATA[<p>Dalam <a href="http://www.mdpai.com/tutorial-php/sql-short-list/">post</a> saya yang lepas, saya menerangkan tentang command SQL yang boleh kita pakai jika kita menggunakan PHP dengan database. Post kali ini pula, saya akan menerangkan tentang function2 MySQL yang boleh kita guna pakai dalam PHP termasuk dengan parameter function2 tersebut. Dalam bahagian 1 ini, saya hanya akan terangkan beberapa fungsi yang asas (yang selalu digunapakai jika kita bekerja dengan database).<br />
<strong>mysql_connect();</strong></p>
<p>Function ini digunakan untuk membuka sambungan dengan server mysql. Juga terdapat <strong>mysql_pconnect()</strong> yang fungsinya tidak jauh berbeza dengan <strong>mysql_connect()</strong><br />
Parameter :  [string $server [, string $username [, string $password [, bool $new_link [, int $client_flags]]]]]</p>
<p>Contoh penggunaan biasa:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p106code9'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p1069"><td class="code" id="p106code9"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mysql_user'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mysql_password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Could not connect: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Connected successfully'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>mysql_close();</strong></p>
<p>Function ini digunakan untuk menutup sambungan dengan server mysql.</p>
<p>Parameter :  [resource $link_identifier]</p>
<p>Contoh penggunaan biasa:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p106code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10610"><td class="code" id="p106code10"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mysql_user'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mysql_password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Could not connect: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Connected successfully'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>mysql_error();</strong></p>
<p>Function ini digunakan untuk menyimpan mesej error dari operasi sql yang terakhir.</p>
<p>Contoh penggunaan biasa:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p106code11'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10611"><td class="code" id="p106code11"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;mysql_user&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;mysql_password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;nonexistentdb&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">mysql_errno</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;kossu&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM nonexistenttable&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">mysql_errno</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><span id="more-106"></span></p>
<p><strong>mysql_select_db();</strong></p>
<p>Function ini digunakan untuk mengaktifkan database pilihan kita.</p>
<p>Parameter : string $database_name [, resource $link_identifier]</p>
<p>Contoh penggunaan biasa :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p106code12'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10612"><td class="code" id="p106code12"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mysql_user'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mysql_password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Not connected : '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// make foo the current db</span>
<span style="color: #000088;">$db_selected</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'foo'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$link</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$db_selected</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">die</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Can'</span>t use foo <span style="color: #339933;">:</span> <span style="color: #0000ff;">' . mysql_error());
}</span></pre></td></tr></table></div>

<p><strong>mysql_query();</strong></p>
<p>Function ini digunakan untuk menghantar request unik kepada server SQL (kepada database yang aktif)</p>
<p>Parameter : string $query [, resource $link_identifier]</p>
<p>Return Value : Jika anda menggunakan penyataan SELECT, SHOW, DESCRIBE, EXPLAIN, Server SQL akan return nilai yang dicari, tetapi jika anda menggunakan penyataan UPDATE, DELETE, DROP, <em>true</em> untuk query yang berjaya dan <em>false</em> jika terdapat error.</p>
<p>Contoh penggunaan biasa :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p106code13'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10613"><td class="code" id="p106code13"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SELECT * WHERE id=1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Invalid query: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>mysql_fetch_assoc();</strong></p>
<p>Fungsi :  Sepertimana nama function ni, ia akan fetch data yang kita query (sebagai associative array). Terdapat juga fungsi <strong>mysql_fetch_row()</strong> dan <strong>mysql_fetch_array()</strong> yang fungsinya sedikit berbeza dengan <strong>mysql_fetch_assoc()</strong> ini.<br />
Parameter : resource $result .Parameter untuk mysql_fetch_array() adalah result kepada mysql_query().</p>
<p>Return Value  :  <em>Associative array</em> yang merujuk kepada hasil query yang dihantar kepada server sql.</p>
<p>Contoh penggunaan biasa :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p106code14'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10614"><td class="code" id="p106code14"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$conn</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;mysql_user&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;mysql_password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$conn</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Unable to connect to DB: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mydbname&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Unable to select mydbname: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT id as userid, fullname, userstatus
FROM   sometable
WHERE  userstatus = 1&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Could not successfully run query (<span style="color: #006699; font-weight: bold;">$sql</span>) from DB: &quot;</span> <span style="color: #339933;">.</span>
<span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> 0<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;No rows found, nothing to print so am exiting&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;userid&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;fullname&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;userstatus&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Dengan beberapa fungsi asas MySQL dalam PHP di atas, anda sudah boleh mula mempraktikkan penggunaan database dalam pengaturcaraan PHP anda.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mdpai.com/tutorial-php/mysql-function-dalam-php-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SQL Short List</title>
		<link>http://www.mdpai.com/tutorial-php/sql-short-list/</link>
		<comments>http://www.mdpai.com/tutorial-php/sql-short-list/#comments</comments>
		<pubDate>Sun, 09 Sep 2007 11:29:06 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[Tutorial PHP]]></category>

		<guid isPermaLink="false">http://www.mdpai.com/tutorial-php/sql-short-list/</guid>
		<description><![CDATA[Dibawah merupakan listing syntax atau command untuk MySQL (pemprosesan database). Saya ni jenis yang tak suka hafal, jadi selalunya saya akan buka beberapa tab dalam browser, khas untuk reference PHP, MySQL, dan Javascript (bukan perangai coder yang baik, jadi jgn contohi).
Dalam 2-3 post akan datang, saya akan tekankan tentang database (saya gunakan MySQL).


General Commands


USE database_name


&#160;
Change [...]]]></description>
			<content:encoded><![CDATA[<p>Dibawah merupakan listing syntax atau command untuk MySQL (pemprosesan database). Saya ni jenis yang tak suka hafal, jadi selalunya saya akan buka beberapa tab dalam browser, khas untuk reference PHP, MySQL, dan Javascript (bukan perangai coder yang baik, jadi jgn contohi).<br />
Dalam 2-3 post akan datang, saya akan tekankan tentang database (saya gunakan MySQL).<span id="more-104"></span></p>
<table>
<tr>
<th align="center" colspan="2"><font size="+2">General Commands</font></th>
</tr>
<tr>
<td colspan="2"><strong>USE database_name</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Change to this database.  You need to change to some database when you first connect to MySQL.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>SHOW DATABASES</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Lists all MySQL databases on the system.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>SHOW TABLES [FROM database_name]</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Lists all tables from the current database or from the database given in the command.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>DESCRIBE table_name</strong></td>
</tr>
<tr>
<td colspan="2"><strong>SHOW FIELDS FROM table_name</strong></td>
</tr>
<tr>
<td colspan="2"><strong>SHOW COLUMNS FROM table_name</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>These commands all give a list of all columns (fields) from the given table, along with column type and other info.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>SHOW INDEX FROM table_name</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Lists all indexes from this tables.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>SET PASSWORD=PASSWORD(&#8216;new_password&#8217;)</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Allows the user to set his/her own password.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<th align="center" colspan="2"><font size="+2">Table Commands</font></th>
</tr>
<tr>
<td colspan="2"><strong>CREATE TABLE table_name (create_clause1, create_clause2, &#8230;)</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Creates a table with columns as indicated in the create clauses.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><strong>create_clause</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>column name followed by column type, followed optionally by modifiers. For example, &#8220;gene_id INT AUTO_INCREMENT PRIMARY KEY&#8221; (without the quotes) creates a column of type integer with the modifiers described below.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><strong>create_clause modifiers</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<ul>
<li>AUTO_INCREMENT : each data record is assigned the next sequential number when it is given a NULL value.</li>
<li>PRIMARY KEY : Items in this column have unique names, and the table is indexed automatically based on this column. One column must be the PRIMARY KEY, and only one column may be the PRIMARY KEY. This column should also be NOT NULL.</li>
<li>NOT NULL : No NULL values are allowed in this column: a NULL generates an error message as the data is inserted into the table.</li>
<li>DEFAULT value : If a NULL value is used in the data for this column, the default value is entered instead.</li>
</ul>
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>DROP TABLE table_name</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Removes the table from the database. Permanently! So be careful with this command!</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>ALTER TABLE table_name ADD (create_clause1, create_clause2, &#8230;)</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Adds the listed columns to the table.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>ALTER TABLE table_name DROP column_name</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Drops the listed columns from the table.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>ALTER TABLE table_name MODIFY create_clause</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Changes the type or modifiers to a column. Using MODIFY means that the column keeps the same name even though its type is altered. MySQL attempts to convert the data to match the new type: this can cause problems.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>ALTER TABLE table_name CHANGE column_name create_clause</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Changes the name and type or modifiers of a column. Using CHANGE (instead of MODIFY) implies that the column is getting a new name.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>ALTER TABLE table_name ADD INDEX [index_name] (column_name1, column_name2, &#8230;)</strong></td>
</tr>
<tr>
<td colspan="2"><strong>CREATE INDEX index_name ON table_name (column_name1, column_name2, &#8230;)</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Adds an index to this table, based on the listed columns. Note that the order of the columns is important, because additional indexes are created from all subsets of the listed columns reading from left to write. The index name is optional if you use ALTER TABLE, but it is necesary if you use CREATE INDEX. Rarely is the name of an index useful (in my experience).</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<th align="center" colspan="2"><font size="+2">Data Commands</font></th>
</tr>
<tr>
<td colspan="2"><strong>INSERT [INTO] table_name VALUES (value1, value2, &#8230;)</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Insert a complete row of data, giving a value (or NULL) for every column in the proper order.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>INSERT [INTO] table_name (column_name1, column_name2, &#8230;) VALUES (value1, value2, &#8230;)</strong></td>
</tr>
<tr>
<td colspan="2"><strong>INSERT [INTO] table_name SET column_name1=value1, column_name2=value2, &#8230;</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Insert data into the listed columns only. Alternate forms, with the SET form showing column assignments more explicitly.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>INSERT [INTO] table_name (column_name1, column_name2, &#8230;) SELECT list_of_fields_from_another_table FROM other_table_name WHERE where_clause</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Inserts the data resulting from a SELECT statement into the listed columns. Be sure the number of items taken from the old table match the number of columns they are put into!</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>DELETE FROM table_name WHERE where_clause</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Delete rows that meet the conditions of the where_clause. If the WHERE statement is omitted, the table is emptied, although its structure remains intact.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>UPDATE table_name SET column_name1=value1, column_name2=value2, &#8230; [WHERE where_clause]</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Alters the data within a column based on the conditions in the where_clause.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>LOAD DATA LOCAL INFILE &#8216;path to external file&#8217; INTO TABLE table_name</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Loads data from the listed file into the table. The default assumption is that fields in the file are separated by tabs, and each data record is separated from the others by a newline. It also assumes that nothing is quoted: quote marks are considered to be part of the data. Also, it assumes that the number of data fields matches the number of table columns. Columns that are AUTO_INCREMENT should have NULL as their value in the file.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>LOAD DATA LOCAL INFILE &#8216;path to external file&#8217; [FIELDS TERMINATED BY 'termination_character'] [FIELDS ENCLOSED BY 'quoting character'] [LINES TERMINATED BY 'line termination character'] FROM table_name </strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Loads data from the listed file into the table, using the field termination character listed (default is tab \t), and/or the listed quoting character (default is nothing), and/or the listed line termination chacracter (default is a newline \n).</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>SELECT column_name1, column_name2, &#8230; INTO OUTFILE &#8216;path to external file&#8217; [FIELDS TERMINATED BY 'termination_character'] [FIELDS ENCLOSED BY 'quoting character'] [LINES TERMINATED BY 'line termination character'] FROM table_name [WHERE where_clause]</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Allows you to move data from a table into an external file. The field and line termination clauses are the same as for LOAD above. Several tricky features:</p>
<ol>
<li>Note the positions of the table_name and where_clause, after the external file is given.</li>
<li>You must use a complete path, not just a file name. Otherwise MySQL attempts to write to the directory where the database is stored, where you don&#8217;t have permission to write.</li>
<li>The user who is writing the file is &#8216;mysql&#8217;, not you! This means that user &#8216;mysql&#8217; needs permission to write to the directory you specify. The best way to do that is to creat a new directory under your home directory, then change the directory&#8217;s permission to 777, then write to it. For example: <strong>mkdir mysql_output</strong>, <strong>chmod 777 mysql_output</strong>.</li>
</ol>
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2">
<hr /></td>
</tr>
<tr>
<th align="center" colspan="2"><font size="+2">Privilege Commands</font></th>
</tr>
<tr>
<td align="center" colspan="2">Most of the commands below require MySQL root access</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>GRANT USAGE ON *.* TO user_name@localhost [IDENTIFIED BY 'password'] </strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Creates a new user on MySQL, with no rights to do anything. The IDENTIFED BY clause creates or changes the MySQL password, which is not necessarily the same as the user&#8217;s system password. The @localhost after the user name allows usage on the local system, which is usually what we do; leaving this off allows the user to access the database from another system. User name NOT in quotes.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>GRANT SELECT ON *.* TO user_name@localhost</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>In general, unless data is supposed to be kept private, all users should be able to view it. A debatable point, and most databases will only grant SELECT privileges on particular databases. There is no way to grant privileges on all databses EXCEPT specifically enumerated ones.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>GRANT ALL ON database_name.* TO user_name@localhost </strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Grants permissions on all tables for a specific database (database_name.*) to a user. Permissions are for: ALTER, CREATE, DELETE, DROP, INDEX, INSERT, SELECT, UPDATE.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>FLUSH PRIVILEGES </strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Needed to get updated privileges to work immediately.  You need RELOAD privileges to get this to work.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>SET PASSWORD=PASSWORD(&#8216;new_password&#8217;)</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Allows the user to set his/her own password.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>REVOKE ALL ON [database_name.]* FROM user_name@localhost</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Revokes all permissions for the user, but leaves the user in the MySQL database. This can be done for all databases using &#8220;ON *&#8221;, or for all tables within a specific databse, using &#8220;ON database_name.*&#8221;.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>DELETE FROM mysql.user WHERE user=&#8217;user_name@localhost&#8217;</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Removes the user from the database, which revokes all privileges.  Note that the user name is in quotes here.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>UPDATE mysql.user SET password=PASSWORD(&#8216;my_password&#8217;) WHERE user=&#8217;user_name&#8217;</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>Sets  the user&#8217;s password. The PASSWORD function encrypts it; otherwise it will be in plain text.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>SELECT user, host, password, select_priv, insert_priv, shutdown_priv, grant_priv FROM mysql.user</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>A good view of all users and their approximate privileges. If there is a password, it will by an encrytped string; if not, this field is blank. Select is a very general privlege; insert allows table manipulation within a database; shutdown allows major system changes, and should only be usable by root; the ability to grant permissions is separate from the others.</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><strong>SELECT user, host, db, select_priv, insert_priv, grant_priv FROM mysql.db</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>View permissions for individual databases.</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://www.mdpai.com/tutorial-php/sql-short-list/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Study Case : Search Function</title>
		<link>http://www.mdpai.com/tutorial-php/study-case-search-function/</link>
		<comments>http://www.mdpai.com/tutorial-php/study-case-search-function/#comments</comments>
		<pubDate>Tue, 05 Jun 2007 19:51:46 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[Tutorial PHP]]></category>

		<guid isPermaLink="false">http://www.mdpai.com/tutorial-php/study-case-search-function/</guid>
		<description><![CDATA[Study case adalah ruangan baru yang saya buat khas untuk membincangkan tentang masalah2 yang mungkin anda hadapi ketika membina satu2 aplikasi menggunakan PHP. Jika anda ada apa2 masalah yang mahu dikongsi bersama, sila email ke coozthaseq@yahoo.com dengan menggunakan &#8220;study case mdpai.com&#8221; sebagai subject email anda.
Study case kali ini adalah masalah yang saya ambil dari forum [...]]]></description>
			<content:encoded><![CDATA[<p>Study case adalah ruangan baru yang saya buat khas untuk membincangkan tentang masalah2 yang mungkin anda hadapi ketika membina satu2 aplikasi menggunakan PHP. Jika anda ada apa2 masalah yang mahu dikongsi bersama, sila email ke coozthaseq@yahoo.com dengan menggunakan &#8220;study case mdpai.com&#8221; sebagai subject email anda.</p>
<p>Study case kali ini adalah masalah yang saya ambil dari forum php.net.my. Masalah ini dikemukakan oleh sdr bushak;</p>
<blockquote><p>&#8220;..<span class="smalltxt"><br />
Katakan aku nak buat seacrh function.. User ada pilihan 2 input utk search:<br />
1. nama<br />
2. asal (negeri)</span></p>
<p>User boleh buat searching samada kedua² pilihan tersebut atau salah satu jer.. ..&#8221;</p></blockquote>
<p>Jika field anda ada 2/3 saja, takde masalah, anda boleh test jika field itu di isi atau tidak dengan menggunakan function if else biasa. Tapi cuba bayangkan jika terdapat 10 field dan user boleh pilih nak isi yang mana dia mahu (maksudnya field2 tersebut tidak wajib diisi, field2 terbabit hanya akan diproses jika ianya tidak NULL).</p>
<p>Ini cadangan saya terhadap permasalahan ini;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p101code16'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10116"><td class="code" id="p101code16"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$myArray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">Array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;nama&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$option1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;asal&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$option2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;umur&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$option3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$where</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM user WHERE &quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$myArray</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$key</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; RLIKE &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$temp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; AND &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$myArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$where</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$temp</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.mdpai.com/tutorial-php/study-case-search-function/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Form Validation &#8211; Javascript</title>
		<link>http://www.mdpai.com/tutorial-php/form-validation-javascript/</link>
		<comments>http://www.mdpai.com/tutorial-php/form-validation-javascript/#comments</comments>
		<pubDate>Tue, 29 May 2007 19:12:24 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[PHP Snippet]]></category>
		<category><![CDATA[Tutorial PHP]]></category>

		<guid isPermaLink="false">http://www.mdpai.com/tutorial-php/form-validation-javascript/</guid>
		<description><![CDATA[Setiap form yang diisi oleh pengguna mestilah di&#8217;valid&#8217;kan / diperiksa terlebih dahulu. Saya masih ingat lagi satu ayat dari sebuah buku PHP yang saya baca, &#8220;..Jangan percaya satu pun yang user anda masukkan! Check all of them!..&#8221;. Form Validation adalah antara benda yang mudah tapi leceh untuk dilaksanakan dengan menggunakan PHP. Tengok contoh di bawah:

?View [...]]]></description>
			<content:encoded><![CDATA[<p>Setiap form yang diisi oleh pengguna mestilah di&#8217;valid&#8217;kan / diperiksa terlebih dahulu. Saya masih ingat lagi satu ayat dari sebuah buku PHP yang saya baca, &#8220;..Jangan percaya satu pun yang user anda masukkan! Check all of them!..&#8221;. Form Validation adalah antara benda yang mudah tapi leceh untuk dilaksanakan dengan menggunakan PHP. Tengok contoh di bawah:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p100code23'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10023"><td class="code" id="p100code23"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
Name field missing<span style="color: #339933;">!</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$age</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
Age field missing<span style="color: #339933;">!</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><span id="more-100"></span></p>
<p>Itu baru dua variable yang kita &#8216;valid&#8217;kan, cuba bayang kita ada 10 variable? sakit jugak nak buat tu. =) memang saya tak nafikan, bukannya tak boleh, tapi membazir masa. Untuk mengelakkan masalah ni, kita boleh menggunakan javascript. Lihat contoh di bawah;</p>
<p>Katakan kita ada satu form HTML seperti berikut;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p100code24'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10024"><td class="code" id="p100code24"><pre class="html" style="font-family:monospace;">&lt;form action=&quot;xxxx.php&quot; method=&quot;post&quot; name=&quot;UD&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;Name :&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Age :&lt;/td&gt;
&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;age&quot; /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;input type=&quot;button&quot; value=&quot;Submit&quot; name=&quot;Submit&quot; onclick=&quot;return validateForm()&quot; /&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;</pre></td></tr></table></div>

<p>*Pastikan form anda ada tag nama, sebagai contoh name=&#8221;UD&#8221;.<br />
**Pastikan anda menambah attribute onclick=&#8221;return validateForm()&#8221; pada button submit anda.</p>
<p>Setelah selesai dengan form di atas, tambah kod javascript berikut di dalam file anda (anda boleh letak kod jscript tersebut sejurus selepas tag penutup head;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p100code25'); return false;">View Code</a> JS</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10025"><td class="code" id="p100code25"><pre class="js" style="font-family:monospace;">&lt;script xsrc=&quot;JavaScript.js&quot;&gt;&lt;/script&gt;
&lt;SCRIPT LANGUAGE=&quot;JavaScript&quot;&gt;
&lt;!--
function validateForm()
{
var count=0;
var msg=&quot;&quot;;
for(i=0;i&lt;=2;i++)
{
if(document.UD.elements[i].value==&quot;&quot;)
{
count=1;
msg=msg+&quot;\n&quot;+document.UD.elements[i].name;
}
else if((i&gt;1) &amp;&amp; (count==0))
{
return(true);
}
}
for(i=0;i&lt;=2;i++)
{
if(document.UD.elements[i].value==&quot;&quot;)
{
alert(&quot;Ruangan di bawah wajib di isi\n &quot;+msg);
document.UD.elements[i].focus();
return(false);
}
}
}
//--&gt;
&lt;/SCRIPT&gt;</pre></td></tr></table></div>

<p>Jangan risau, saya akan terangkan bagaimana anda boleh menggunakan script ini untuk semua form anda nnt, hanya sekadar menukar sedikit nombor2 yang terdapat di dalam script itu, dan siap!</p>
<p>Jika anda perasan, dalam form saya HTML sebelum ini, saya meminta user masukkan nama dan juga umur mereka. Ini bermaksud dua input yang akan mereka masukkan. Perhatikan kod jscript dan cari line ini</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p100code26'); return false;">View Code</a> JS</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10026"><td class="code" id="p100code26"><pre class="js" style="font-family:monospace;">for(i=0;i&lt;=2;i++)</pre></td></tr></table></div>

<p>dan</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p100code27'); return false;">View Code</a> JS</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10027"><td class="code" id="p100code27"><pre class="js" style="font-family:monospace;">for(i=0;i&lt;=2;i++)</pre></td></tr></table></div>

<p>Tukar 2 mengikut jumlah input yang terdapat dalam form anda.</p>
<p>Kemudian cari line ini;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p100code28'); return false;">View Code</a> JS</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10028"><td class="code" id="p100code28"><pre class="js" style="font-family:monospace;">else if((i&gt;1) &amp;&amp; (count==0))</pre></td></tr></table></div>

<p>Tukar 1 mengikut jumlah input anda tolak 1 (jangan lupa, tolak satu!).</p>
<p>Siap! tanya di ruangan komen jika anda mengalami masalah tentang script ini. Selamat mencuba. Download contoh script <a href="http://www.mdpai.com/tutorial-php/script4/">di sini</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mdpai.com/tutorial-php/form-validation-javascript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Kelas 13 &#8211; Elak email masuk SPAM box?</title>
		<link>http://www.mdpai.com/tutorial-php/kelas-13-elak-email-masuk-spam-box/</link>
		<comments>http://www.mdpai.com/tutorial-php/kelas-13-elak-email-masuk-spam-box/#comments</comments>
		<pubDate>Mon, 28 May 2007 20:38:52 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[Tutorial PHP]]></category>

		<guid isPermaLink="false">http://www.mdpai.com/tutorial-php/kelas-12-elak-email-masuk-spam-box/</guid>
		<description><![CDATA[Kelas kali ini adalah rentetan dari Kelas 6 &#8211; Contact Us/Feedback Form. Kebanyakan dari pengunjung mdpai.com yang menghubungi saya mengatakan bahawa email yang mereka hantar dengan menggunakan script di dalam kelas 6 tidak sampai ke inbox pengguna tetapi masuk ke dalam spam box.
Perkara ini bukanlah baru, dan memang biasa berlaku. Ia disebabkan oleh server yang [...]]]></description>
			<content:encoded><![CDATA[<p>Kelas kali ini adalah rentetan dari <a href="http://www.mdpai.com/pembangunan-laman-web/kelas-6-contact-us-feedback-form/">Kelas 6 &#8211; Contact Us/Feedback Form</a>. Kebanyakan dari pengunjung mdpai.com yang menghubungi saya mengatakan bahawa email yang mereka hantar dengan menggunakan script di dalam kelas 6 tidak sampai ke inbox pengguna tetapi masuk ke dalam spam box.</p>
<p><span id="more-99"></span>Perkara ini bukanlah baru, dan memang biasa berlaku. Ia disebabkan oleh server yang diblacklist kerana penghantaran email secara spam (secara nyatanya, ia bukan salah kita!) Dalam kelas 6, kita menggunakan function mail() yang disediakan oleh PHP untuk menghantar email kita. Untuk mengelakkan masalah ini, saya mencadangkan satu penyelesaian baru, iaitu dengan menggunakan class PHPMailer (<a href="http://phpmailer.sourceforge.net/">download di sini</a>) . Class ini membolehkan kita menghantar email dengan menggunakan kaedah mail() biasa dan juga satu cara baru iaitu, dengan menggunakan SMTP mail. Dengan SMTP, email yang kita hantar mempunyai peratus yang amat tinggi untuk masuk ke inbox, tidak seperti kaedah yang lama.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p99code30'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p9930"><td class="code" id="p99code30"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;class.phpmailer.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$mail</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PHPMailer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//kita create satu object baru dari class PHPMailer</span>
&nbsp;
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">IsSMTP</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">//kita memberitahu yang kita akan hantar melalui SMTP</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Host</span>     <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;mail.mdpai.com;smtp.mdpai.com&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//set SMTP server, dapatkan nama SMTP server anda sendiri (boleh tanya admin server anda)</span>
&nbsp;
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">From</span>     <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;info@mdpai.com&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//email pengirim</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FromName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;mdpai&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//nama pengirim</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">AddAddress</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;johan@mdpai.com&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;Johan Adam&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//email dan nama penerima</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">AddAddress</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ellen@site.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>               <span style="color: #666666; font-style: italic;">//email tambahan</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">AddReplyTo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;info@site.com&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;Information&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">WordWrap</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">;</span>                              <span style="color: #666666; font-style: italic;">// set word wrap</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">IsHTML</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                               <span style="color: #666666; font-style: italic;">// send as HTML</span>
&nbsp;
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Subject</span>  <span style="color: #339933;">=</span>  <span style="color: #0000ff;">&quot;Here is the subject&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Body</span>     <span style="color: #339933;">=</span>  <span style="color: #0000ff;">&quot;This is the &lt;strong&gt;HTML body&lt;/strong&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">AltBody</span>  <span style="color: #339933;">=</span>  <span style="color: #0000ff;">&quot;This is the text-only body&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Message was not sent&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Mailer Error: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ErrorInfo</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Message has been sent&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Download contoh code <a href="http://www.mdpai.com/tutorial-php/kelas12/">di sini</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mdpai.com/tutorial-php/kelas-13-elak-email-masuk-spam-box/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Convention ketika coding PHP</title>
		<link>http://www.mdpai.com/tutorial-php/convention-ketika-coding-php/</link>
		<comments>http://www.mdpai.com/tutorial-php/convention-ketika-coding-php/#comments</comments>
		<pubDate>Wed, 14 Mar 2007 06:47:24 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[Tutorial PHP]]></category>

		<guid isPermaLink="false">http://www.mdpai.com/tutorial-php/convention-ketika-coding-php/</guid>
		<description><![CDATA[Seringkali, kita sering membaca semula code PHP yang kita tulis setengah tahun yang lepas. Tapi, mesti kita terfikir, &#8220;..ni code ke apa ni? aku coding macam ni ke, tak faham langsung!..&#8221;. Ha tulah jadinya jika kita coding sesuka hati tanpa berfikir dahulu, salah satu ciri code PHP yang baik adalah walaupun 6 bulan selepas itu, [...]]]></description>
			<content:encoded><![CDATA[<p>Seringkali, kita sering membaca semula code PHP yang kita tulis setengah tahun yang lepas. Tapi, mesti kita terfikir, &#8220;..ni code ke apa ni? aku coding macam ni ke, tak faham langsung!..&#8221;. Ha tulah jadinya jika kita coding sesuka hati tanpa berfikir dahulu, salah satu ciri code PHP yang baik adalah walaupun 6 bulan selepas itu, kita masih lagi faham apa yang kita telah tulis. Kebaikan untuk ini adalah, kita boleh menggunakan semula code2 lama kita tanpa perlu menulisnya kembali, sng cerita jimat MASA.<br />
Bagi saya, 2 benda yang paling penting untuk tujuan ini ialah nested block dan juga commented block.</p>
<p>Contoh:</p>
<p><font color="#cc0000"></p>
<pre><code>if($user == "admin") { //if user == admin
</code> <code>     //code utk admin di sini
</code> <code>     if($varA == $varB) { //if varA == varB
</code> <code>          //code di sini
</code> <code>          //code lagi di sini
</code> <code>     } //end if varA == varB
</code> <code>} //end if user == admin
</code></pre>
<p></font></p>
<p>Dalam code di atas, ada 2 blok IF, tengok yang saya telah komen setiap pembuka blok dan juga penutup blok. Ini penting jika code anda itu panjang dan terdapat banyak blok. Jika kita membaca code ini setahun akan datang pun, kita akan tahu, penutup blok ini untuk blok yang mana, penutup yang ini pula untuk blok yang mana. Jadi kita boleh jimat MASA untuk proses coding di kemudian hari.</p>
<p>Satu perkara lagi yang sering dilupakan ialah nested block. Lihat yang saya telah tabkan blok2 code saya. Nampak lebih teratur dan kemas bukan? Satu kelebihan utama berbuat begini ialah code kita senang dibaca oleh orang lain dan juga oleh diri kita sendiri.</p>
<p>Kesimpulan, saya tahu yang walaupun kita tak buat 2 convention di atas, memang takde masalah, code kita still betul. Tapi cuba bayangkan, 2-3 bulan selepas itu, kita nak tambah atau edit code kita yang sedia ada. Ha time tu baru tau kepentingan convention ni. =)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mdpai.com/tutorial-php/convention-ketika-coding-php/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Tukar link affiliate anda versi 2</title>
		<link>http://www.mdpai.com/tutorial-php/php-snippet/tukar-link-affiliate-anda-versi-2/</link>
		<comments>http://www.mdpai.com/tutorial-php/php-snippet/tukar-link-affiliate-anda-versi-2/#comments</comments>
		<pubDate>Sun, 11 Feb 2007 22:05:43 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[PHP Snippet]]></category>

		<guid isPermaLink="false">http://www.mdpai.com/tutorial-php/php-snippet/tukar-link-affiliate-anda-versi-2/</guid>
		<description><![CDATA[Saya telah pun menyiapkan hampir 90% sistem penyelarasan affiliate yang sy ada janjikan pada post2 sebelum ini.. Sebenarnya sistem ni sy dah test kat localserver (pc saya), dan ianya dah berjaya..Namun setelah sy cuba upload, terdapat error file creation..insyaAllah saya akan memperbaiki error ini secepat mungkin&#8230;Nantikan sistem ini daripada saya.
UPDATE TERKINI:
Saya sedang menambah beberapa fungsi [...]]]></description>
			<content:encoded><![CDATA[<p>Saya telah pun menyiapkan hampir 90% sistem penyelarasan affiliate yang sy ada janjikan pada post2 sebelum ini.. Sebenarnya sistem ni sy dah test kat localserver (pc saya), dan ianya dah berjaya..Namun setelah sy cuba upload, terdapat error file creation..insyaAllah saya akan memperbaiki error ini secepat mungkin&#8230;Nantikan sistem ini daripada saya.</p>
<p>UPDATE TERKINI:</p>
<p>Saya sedang menambah beberapa fungsi kepada sistem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mdpai.com/tutorial-php/php-snippet/tukar-link-affiliate-anda-versi-2/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Tukar link affiliate anda</title>
		<link>http://www.mdpai.com/tutorial-php/php-snippet/tukar-link-affiliate-anda/</link>
		<comments>http://www.mdpai.com/tutorial-php/php-snippet/tukar-link-affiliate-anda/#comments</comments>
		<pubDate>Thu, 25 Jan 2007 21:47:53 +0000</pubDate>
		<dc:creator>mdpai</dc:creator>
				<category><![CDATA[PHP Snippet]]></category>

		<guid isPermaLink="false">http://www.mdpai.com/tutorial-php/php-snippet/tukar-link-affiliate-anda/</guid>
		<description><![CDATA[Mungkin anda pernah terfikir, &#8220;hmm..pjg sgt la link affiliate aku ni..mane ade org teringin nak masuk?..&#8221; atau &#8220;tak menarik btul link affiliate aku ni, byk nombor la..&#8221;
Dengan PHP, ada satu cara mudah yang boleh mengatasi masalah ini. Contoh anda memiliki satu web www.affiliate-saya.com, yang khas untuk menjual produk-produk affiliate yang anda sertai. Memang bagus, tapi [...]]]></description>
			<content:encoded><![CDATA[<p>Mungkin anda pernah terfikir, &#8220;hmm..pjg sgt la link affiliate aku ni..mane ade org teringin nak masuk?..&#8221; atau &#8220;tak menarik btul link affiliate aku ni, byk nombor la..&#8221;</p>
<p>Dengan PHP, ada satu cara mudah yang boleh mengatasi masalah ini. Contoh anda memiliki satu web www.affiliate-saya.com, yang khas untuk menjual produk-produk affiliate yang anda sertai. Memang bagus, tapi anda baru perasan bahawa web anda penuh dengan link affiliate!</p>
<p>Caranya mudah sahaja, create satu folder baru di dalam root anda (selalunya folder www atau public_html)..Cth anda mahu menjual produk komputer, create folder bernama komputer. Kemudian di dalam folder ini, create satu file index.php.</p>
<p>Dalam file index.php ini, letakkan code di bawah:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p84code32'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p8432"><td class="code" id="p84code32"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Location: http://www.kedai.com/?aff=mdpai&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>** tukar link affiliate mengikut link affiliate anda.</p>
<p>Save file tersebut. Siap! tak sampai seminit dah siap..sekarang anda tidak perlu lagi promosi link affiliate yang pjg, tetapi link yang menggunakan nama domain anda sendiri. ( dalam kes ini, anda hanya perlu mempromosikan www.affiliate-saya.com/komputer)..</p>
<p>Download contoh code <a href="http://www.mdpai.com/tutorial-php/script3/">di sini</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mdpai.com/tutorial-php/php-snippet/tukar-link-affiliate-anda/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>
