Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,739 members, 7,824,114 topics. Date: Friday, 10 May 2024 at 11:24 PM

My First Real PHP Based Website - Programming (2) - Nairaland

Nairaland Forum / Science/Technology / Programming / My First Real PHP Based Website (8650 Views)

Closed - Out of date / Question And Answer Based Website (Program Routes) (2) (3) (4)

(1) (2) (Reply) (Go Down)

Re: My First Real PHP Based Website by Olaide1295: 11:48pm On Jun 04, 2016
hello bro, I also want to learn php, what softwares are u using to run it on your PC? I have xampp already,what do I need
Re: My First Real PHP Based Website by halmat(m): 12:05am On Jun 05, 2016
Olaide1295:
hello bro,
I also want to learn php, what softwares are u using to run it on your PC?
I have xampp already,what do I need

Nothing more than text editor and the offline version of php.net online documentation
Re: My First Real PHP Based Website by Nobody: 10:17am On Jun 10, 2016
Olaide1295:
hello bro,
I also want to learn php, what softwares are u using to run it on your PC?
I have xampp already,what do I need

Download a Text-Editor e.g; Sublime Text or Brackets (I use both).

To create a new Xampp Project, create a folder for the project at C:/xampp/htdocs/exampleproject . To view the project on the browser, go to localhost/exampleproject .
Hope you get it right, happy devving!

1 Like

Re: My First Real PHP Based Website by Realphilo(m): 5:39pm On Jun 11, 2016
Thirdwrist:


How do I rectify this?


public $sql;
public $row;
public $result;
public $something;
public function dbr(){

$this->sql="SELECT username, id FROM users";
foreach ($this->result->exec($sql) as $row) {
print $row['id'] . "\t";
print $row['username'] . "\n";

}



It reply's :

Fatal error: Call to a member function exec() on a non-object in E:\xampp\htdocs\Experiments\gstosa\index1.php on line 34

dhtml18
larisoft
nauman673
hcpaul
guru01
davidthegeek
sonoflucifer
hitz
Adesege
Check your index1.php file @ line 34
Re: My First Real PHP Based Website by wisemania(m): 10:55pm On Jun 12, 2016
@op, the truth is nobody cares about your codes unless it can create admirable web pages accessible by all.
Re: My First Real PHP Based Website by Thirdwrist(m): 11:22am On Jun 13, 2016
The login script is as follows


$email=mysql_real_escape_string($_POST['email']);
$pass=md5(mysql_real_escape_string($_POST['pass1']));
$sql="SELECT * FROM users WHERE Email='{$email}'";
require "db_connect.php";
$result=mysql_query($sql);
if (mysql_num_rows($result)){
$sql="SELECT * FROM users WHERE Email='{$email}' AND Pass='$pass'";
$result=mysql_query($sql);
if(mysql_num_rows($result)==true){
Echo "welcome man";
//require_once($_SERVER['DOCUMENT_ROOT']. "/Experiments/gstosa/index.html"wink;
die;
}

else{
$output="Incorrect password";
require "signin.php";

}

}

else{
$output="Incorrect email address";
//$output="Your email is not registered or wasn't entered correctly";
require "signin.php";
die;
}


Please help review if you see any inconsistency i will be more than happy to correct it.
And any security flow.
Re: My First Real PHP Based Website by Thirdwrist(m): 11:24am On Jun 13, 2016
The signup script is as follows
[codes]

#sighup script below
// Save form values in variables as well as clear it of any malicious characters
$fname=mysql_real_escape_string($_POST['fname']);
$lname=mysql_real_escape_string($_POST['lname']);
$email=mysql_real_escape_string($_POST['email']);
$gset=mysql_real_escape_string($_POST['gset']);
$department=mysql_real_escape_string($_POST['dpt']);
$pass1=mysql_real_escape_string($_POST['pass1']);
$pass2=mysql_real_escape_string($_POST['pass2']);
require "db_connect.php";

//checking lenght of string
if (strlen($lname) > 30 || strlen($lname)< 3 ){
$output="Invalid Last name";
require_once "signup.php";
die;
}
elseif (strlen($fname) > 30 || strlen($fname)< 3 ){
$output="Invalid First name";
require_once "signup.php";
die;

}
elseif (strlen($pass1) > 50 || strlen($pass1)< 7 ){
$output="Invalid password, Password must be minimum of 7 units";
require_once "signup.php";
die;
}

//if email is already reistered
$sql="SELECT Email FROM users WHERE email='{$email}'";
$result= mysql_query($sql);
//if the two passwords are the same
if($pass1!=$pass2){

$output= "Please make sure the two passwords are the same ";
require_once "signup.php";
die();
}

elseif(mysql_num_rows($result)==True){

$output= "This Email address has already been regisered here";
require_once "signup.php";
die();
}
else{
$pass1=md5(mysql_real_escape_string($pass1));
$sql="
INSERT INTO users SET
First_name ='{$fname}',
Last_name = '{$lname}',
Email= '{$email}',
Pass= '{$pass1}',
Graduation_set='{$gset}',
Department='{$department}'";
try{
$result=mysql_query($sql);
}
catch(MYSQLException $e){
$output="Failed to register, Please try again and if problem persist contact the admin". $e->getmessage();
}

}

echo "welcome bro";

[/codes]
Please help review if you see any inconsistency i will be more than happy to correct it.
And any security flaw
Re: My First Real PHP Based Website by Thirdwrist(m): 11:27am On Jun 13, 2016
Thank you Sir, I have fixed that. thank you...
Realphilo:

Check your index1.php file @ line 34

1 Like

Re: My First Real PHP Based Website by Thirdwrist(m): 11:32am On Jun 13, 2016
Thank you very much I have rectified the issue thanks to you Sir...
I would be grateful if you follow more of my recent posts on this tread and be as generous as you are now to administer solutions to my errors. Thank you again Sir.

sleepingdemon:
Op the content of the file you outline is it index1.php?
The class you provided, if ran, would return "you are an oop genius"
the error you are recieving is from the index1.php class, not the class.
besides, i guess you want the file to print out you are an oop genius and also usernames and id gotten from the user table.

if that is the case, ive corrected your class to be like this, and it should work.

But i repeat, the error of exec you are getting is from index1.php, not this file.


<?php
class user{
//inniating variables to be used in db_connect method.
// Database assess values.

public $db_host= "localhost";
public $username="";
public $password= "";
public $db_name="php_database";
public $dbc;
public $sql;
public $row;
public $result;
public $something;

function __construct(){

$this->connect();
}

// method to connect to database
function connect(){
try{

$this->dbc= new PDO("mysql:host=$this->db_host; dbname=$this->db_name;charset=utf8", $this->username, $this->password);
}
catch (PDOException $e){
echo "failed to connect to database pdo ";
echo $e->getmessage();
exit();
}
return $this->dbc;
}




public function dbr(){
$this->sql="SELECT username, id FROM users";

$stmt=$this->dbc->query($this->sql);
return $stmt;
return $stmt->fetchAll(PDO::FETCH_ASSOC);




}
}
$usermanagment= new user();



echo "you are an OOP genius";
echo "<br>";
try {
$answer=$usermanagment->dbr();

foreach ($answer as $row) {
print $row['id'] . "\t";
print $row['username'] . "\n";

}
} catch(PDOException $ex) {
echo $ex->getmessage();
//handle me.
}
echo "<br>";
echo $usermanagment->sql;


?>
Re: My First Real PHP Based Website by wisemania(m): 1:00am On Jun 14, 2016
I think it's still susceptible to sql injection...you could add a trim($pass) function together with strip_tags () aswell...theses would prevent simple attacks.to make it more secured you can hard code your validation to prevent any acceptance of sql syntaxes like : select, delete, insert, join, modify etc... But that doesnt mean it still isnt suceptible though, but it would require an expert to reck harvoc. My $0.2
Re: My First Real PHP Based Website by wisemania(m): 1:04am On Jun 14, 2016
Good
Re: My First Real PHP Based Website by D34lw4p(m): 3:26am On Jun 14, 2016
Booyakasha:


alright.. I'll mention you as soon as we launch.. thanks smiley
join www.nct.com.ng its the best programmers forum I can recommend to help you on your project, G33ks are there to help you!

(1) (2) (Reply)

Data Science Tutorial For Beginners With Python Programming Language / Any Female Programmers In The House? / What's Tools Do I Need To Start Building A Messaging App

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 29
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.