Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Pure VPN - Up to 27 Months
vgp
Updated:
Friday at 8:10 AM
එක පැකේජ් එකයි මාසෙටම Unlimited Internet. තාමත් DATA CARD දාන්න සල්ලි වියදම් කරනවද? අඩුම මිලට අපෙන්.
sayuru bandara
Updated:
Tuesday at 12:30 PM
Ad icon
ඉන්ටර්නෙට් එකෙන් හරියටම සල්ලි හොයන්න සහ Success වෙන්න කැමතිද? 🚀 (E-Money & Success Stories)
siri sumana
Updated:
May 30, 2026
Gemini AI PRO 18 months Offer
Hawaka
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
PHP PDO Help ekak
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="isurutmv" data-source="post: 22458627" data-attributes="member: 470006"><p><span style="font-size: 22px">Mcn kauru hari mata me code eka PDO walin karala dennako loku udawuwak mcn <img src="/styles/default/xenforo/smilies/default/happy.gif" class="smilie" loading="lazy" alt=":)" title="Happy :)" data-shortname=":)" /></span></p><p><span style="font-size: 22px"></span></p><p><span style="font-size: 22px">[PHP]</span></p><p><span style="font-size: 22px"><?php</span></p><p><span style="font-size: 22px"> //Start session</span></p><p><span style="font-size: 22px"> session_start();</span></p><p><span style="font-size: 22px"> </span></p><p><span style="font-size: 22px"> //Array to store validation errors</span></p><p><span style="font-size: 22px"> $errmsg_arr = array();</span></p><p><span style="font-size: 22px"> </span></p><p><span style="font-size: 22px"> //Validation error flag</span></p><p><span style="font-size: 22px"> $errflag = false;</span></p><p><span style="font-size: 22px"> </span></p><p><span style="font-size: 22px"> //Connect to mysql server</span></p><p><span style="font-size: 22px"> $link = mysql_connect('localhost','root',"");</span></p><p><span style="font-size: 22px"> if(!$link) {</span></p><p><span style="font-size: 22px"> die('Failed to connect to server: ' . mysql_error());</span></p><p><span style="font-size: 22px"> }</span></p><p><span style="font-size: 22px"> </span></p><p><span style="font-size: 22px"> //Select database</span></p><p><span style="font-size: 22px"> $db = mysql_select_db('sales', $link);</span></p><p><span style="font-size: 22px"> if(!$db) {</span></p><p><span style="font-size: 22px"> die("Unable to select database");</span></p><p><span style="font-size: 22px"> }</span></p><p><span style="font-size: 22px"> </span></p><p><span style="font-size: 22px"> //Function to sanitize values received from the form. Prevents SQL injection</span></p><p><span style="font-size: 22px"> function clean($str) {</span></p><p><span style="font-size: 22px"> $str = @trim($str);</span></p><p><span style="font-size: 22px"> if(get_magic_quotes_gpc()) {</span></p><p><span style="font-size: 22px"> $str = stripslashes($str);</span></p><p><span style="font-size: 22px"> }</span></p><p><span style="font-size: 22px"> return mysql_real_escape_string($str);</span></p><p><span style="font-size: 22px"> }</span></p><p><span style="font-size: 22px"> </span></p><p><span style="font-size: 22px"> //Sanitize the POST values</span></p><p><span style="font-size: 22px"> $login = clean($_POST['username']);</span></p><p><span style="font-size: 22px"> $password = clean($_POST['password']);</span></p><p><span style="font-size: 22px"> </span></p><p><span style="font-size: 22px"> //Input Validations</span></p><p><span style="font-size: 22px"> if($login == '') {</span></p><p><span style="font-size: 22px"> $errmsg_arr[] = 'Username missing';</span></p><p><span style="font-size: 22px"> $errflag = true;</span></p><p><span style="font-size: 22px"> }</span></p><p><span style="font-size: 22px"> if($password == '') {</span></p><p><span style="font-size: 22px"> $errmsg_arr[] = 'Password missing';</span></p><p><span style="font-size: 22px"> $errflag = true;</span></p><p><span style="font-size: 22px"> }</span></p><p><span style="font-size: 22px"> </span></p><p><span style="font-size: 22px"> //If there are input validations, redirect back to the login form</span></p><p><span style="font-size: 22px"> if($errflag) {</span></p><p><span style="font-size: 22px"> $_SESSION['ERRMSG_ARR'] = $errmsg_arr;</span></p><p><span style="font-size: 22px"> session_write_close();</span></p><p><span style="font-size: 22px"> header("location: index.php");</span></p><p><span style="font-size: 22px"> exit();</span></p><p><span style="font-size: 22px"> }</span></p><p><span style="font-size: 22px"> </span></p><p><span style="font-size: 22px"> //Create query</span></p><p><span style="font-size: 22px"> $qry="SELECT * FROM user WHERE username='$login' AND password='$password'";</span></p><p><span style="font-size: 22px"> $result=mysql_query($qry);</span></p><p><span style="font-size: 22px"> </span></p><p><span style="font-size: 22px"> //Check whether the query was successful or not</span></p><p><span style="font-size: 22px"> if($result) {</span></p><p><span style="font-size: 22px"> if(mysql_num_rows($result) > 0) {</span></p><p><span style="font-size: 22px"> //Login Successful</span></p><p><span style="font-size: 22px"> session_regenerate_id();</span></p><p><span style="font-size: 22px"> $member = mysql_fetch_assoc($result);</span></p><p><span style="font-size: 22px"> $_SESSION['SESS_MEMBER_ID'] = $member['id'];</span></p><p><span style="font-size: 22px"> $_SESSION['SESS_FIRST_NAME'] = $member['name'];</span></p><p><span style="font-size: 22px"> $_SESSION['SESS_LAST_NAME'] = $member['position'];</span></p><p><span style="font-size: 22px"> //$_SESSION['SESS_PRO_PIC'] = $member['profImage'];</span></p><p><span style="font-size: 22px"> session_write_close();</span></p><p><span style="font-size: 22px"> header("location: main/index.php");</span></p><p><span style="font-size: 22px"> exit();</span></p><p><span style="font-size: 22px"> }else {</span></p><p><span style="font-size: 22px"> //Login failed</span></p><p><span style="font-size: 22px"> header("location: index.php");</span></p><p><span style="font-size: 22px"> exit();</span></p><p><span style="font-size: 22px"> }</span></p><p><span style="font-size: 22px"> }else {</span></p><p><span style="font-size: 22px"> die("Query failed");</span></p><p><span style="font-size: 22px"> }</span></p><p><span style="font-size: 22px">?></span></p><p><span style="font-size: 22px">[/PHP]</span></p></blockquote><p></p>
[QUOTE="isurutmv, post: 22458627, member: 470006"] [SIZE=6]Mcn kauru hari mata me code eka PDO walin karala dennako loku udawuwak mcn :) [PHP] <?php //Start session session_start(); //Array to store validation errors $errmsg_arr = array(); //Validation error flag $errflag = false; //Connect to mysql server $link = mysql_connect('localhost','root',""); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db('sales', $link); if(!$db) { die("Unable to select database"); } //Function to sanitize values received from the form. Prevents SQL injection function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $login = clean($_POST['username']); $password = clean($_POST['password']); //Input Validations if($login == '') { $errmsg_arr[] = 'Username missing'; $errflag = true; } if($password == '') { $errmsg_arr[] = 'Password missing'; $errflag = true; } //If there are input validations, redirect back to the login form if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; session_write_close(); header("location: index.php"); exit(); } //Create query $qry="SELECT * FROM user WHERE username='$login' AND password='$password'"; $result=mysql_query($qry); //Check whether the query was successful or not if($result) { if(mysql_num_rows($result) > 0) { //Login Successful session_regenerate_id(); $member = mysql_fetch_assoc($result); $_SESSION['SESS_MEMBER_ID'] = $member['id']; $_SESSION['SESS_FIRST_NAME'] = $member['name']; $_SESSION['SESS_LAST_NAME'] = $member['position']; //$_SESSION['SESS_PRO_PIC'] = $member['profImage']; session_write_close(); header("location: main/index.php"); exit(); }else { //Login failed header("location: index.php"); exit(); } }else { die("Query failed"); } ?> [/PHP][/SIZE] [/QUOTE]
Insert quotes…
Verification
Dawasata paya keeyak thibeda?
Post reply
Top
Bottom