Hello There, Guest! Login Register


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Hey! I need help.
#1
Hey! I need help because i want to know how to print the columns data to echo. I don't know whihc query i should use. See this .

PHP Code:
$res=mysql_query("SELECT * FROM login WHERE username=".$_SESSION['usern']);

$sql mysql_query("SELECT * FROM login"); 

What should i do next ? I want to print username's text in the echo .
Welcome to Hostingee.

Get your own Free SA:MP server on Hostingee.com by post2host method! Just go, register, earn points by posting and then get your own server!

Website :- http://hostingee.com
Reply
#2
use mysql_fetch_row or mysql_fetch_assoc or $d = $res->fetch(). Then echo $d['username'];
Reply
#3
(06-22-2016, 06:19 AM)Fahad Wrote: use mysql_fetch_row or mysql_fetch_assoc or $d = $res->fetch(). Then echo $d['username'];

Can you specify that decently ? i mean in the full line so i can add your line in my script. Btw, Its of home page so that if user login then he can see his stat provided by administrators to their accounts in their columns. So please please please help to out of this problem. I cannot find help on Internet . I tried help from StackExchange and other scripting help forum but i failed to find it. It shows different methods which i don't under stand . I tried you tube also but i failed in it.
Welcome to Hostingee.

Get your own Free SA:MP server on Hostingee.com by post2host method! Just go, register, earn points by posting and then get your own server!

Website :- http://hostingee.com
Reply
#4
take a look at this

PHP Code:
function getuser(){
 
 global $conn;
 $sql "SELECT * FROM login WHERE username=".$_SESSION['usern']";
 
$result = $conn->query($sql);
 if (
$result->num_rows > 0) {
   // output data of each row
   
$arr=[];
   while(
$row = $result->fetch_assoc()) {
     
$arr[] = $row;
   }
   return 
$arr;
 } else {
   return 0;
 }




maybe:

PHP Code:
$sql mysql_query("SELECT * FROM login");
$sql->fetch_assoc();
echo 
$sql["username"
__                    
|_  _ |_  o  _ |      
|  (_||_) | (_)|__|_|><


If you enjoyed, please give me your like (:
Reply
#5
(06-27-2016, 10:27 AM)FabioLux Wrote: take a look at this

PHP Code:
function getuser(){
 
 global $conn;
 $sql "SELECT * FROM login WHERE username=".$_SESSION['usern']";
 
$result = $conn->query($sql);
 if (
$result->num_rows > 0) {
   // output data of each row
   
$arr=[];
   while(
$row = $result->fetch_assoc()) {
     
$arr[] = $row;
   }
   return 
$arr;
 } else {
   return 0;
 }




maybe:

PHP Code:
$sql mysql_query("SELECT * FROM login");
$sql->fetch_assoc();
echo 
$sql["username"

When i try to echo the username it goes working but some other columns then failed Sad . What should i do brother ?
Welcome to Hostingee.

Get your own Free SA:MP server on Hostingee.com by post2host method! Just go, register, earn points by posting and then get your own server!

Website :- http://hostingee.com
Reply
#6
i put all of the code section(connect database, execute query and print also some error handlers)
i hope this would help.i tried to explain each line fo code,feel free to ask whatever you want to know.


PHP Code:
//create a connection obect which will be used for query
$connection = new mysqli $servername$username$password$dbname );
//if there is a error than print and exit
if ($connection->connect_error) {
die ( 
"Connection error: " $connection->connect_error );
}
//which query you want(like update, alter, drop and such)
$query "SELECT * FROM login";
//executes query and gets the result
$result $connection->query($query);
//if there is a error with query then $result will be false, then print error
if(!$result){//lets throw an exception
//in truth there is no difference between die();
//die() prints the error and kills page. but throw() gives some other information like stack trace, throw() useful for functions
throw new Exception("Database Error [{connection->errno}] {connection->error}");
}
//then we will process result row by row
//this might be confusing, main idea is that check $row if it is false then there is no more row, otherwise process the row
//fetch_assoc() func tries to get next row from the result and returns, if there is no more row returns false
while ($row $result->fetch_assoc()){
$username $row["username"];//get any column you want
echo $username;//then print 
}
//as always close the your connection while leaving
$connection->close (); 

by the way you can check online php manual for more information about functions.
Reply
#7
PHP Code:
<?php session_start();
include_once(
'connect.php');
if(isset(
$_REQUEST["btnlogin"]))
{
 $username $_REQUEST["txtusername"];
 $pass $_REQUEST["txtpass"];
 $qry "SELECT * FROM user WHERE username='$username' AND pass='".md5($pass)."'";
 $result=mysql_query($qry,$con);
 $row=mysql_fetch_array($result);
 if(mysql_affected_rows()>0)
 {
          $_SESSION["username"]= $username;
          $_SESSION["userid"]= $row["uid"];
          header("Location:new_top.php");//Everything ok,send user to other page
          
 
}
 else 
 
{
    echo "Please check your username or password"   
 
}
}
?>

-> This will do the job, a part from my project.
-> session_start(); so you can flow the data in other files if you want to..(For that you need session_start(); in other files, and to destroy,session_destroy()Wink
-> if(isset($_REQUEST["btnlogin"])) (isset,value is set or the button you made for form submission is clicked,$_REQUEST is an environment variable)
-> $username and $pass will hold the values requested through $_REQUEST,from the form
-> Now,to login,you will select the data of that user,so you need to use SELECT query with username and pass(as in columns of your mysql software)
-> Save the SELECT query in a variable and fetch in a variable.
-> If query is okay,then only those rows which have the exact data as given by user will get effected and you will proceed forward
-> connect.php has connections to the server.
-> md5 is one way password hashing system..If you want to know more then reply.
Thanks for the instant vps Freedomain.club.. Loved this great service. Smile
Reply
#8
(06-20-2016, 12:53 PM)Manal Wrote: Hey! I need help because i want to know how to print the columns data to echo. I don't know whihc query i should use. See this .

PHP Code:
$res=mysql_query("SELECT * FROM login WHERE username=".$_SESSION['usern']);

$sql mysql_query("SELECT * FROM login"); 

What should i do next ? I want to print username's text in the echo .

If just want print username just show the session with this code

Code:
<?php
session_start();
echo $_SESSION['usern'];
?>
Reply


Forum Jump:


Users browsing this thread:
1 Guest(s)