Jump to content

nouaman

Members
  • Posts

    12
  • Joined

  • Last visited

Posts posted by nouaman

  1. Hi ,

     

    please be noted that i need help with php fetshing logged user s data and displaying all the data regarding the logged user below is explanation of what happens and the code im using

     

    -so i was able to write a code that authenticare registered users , for example when i log with let say a username "steve" i direct user to profile page wich says welcome steve and in the same page i put for test a link that says "see my profile"

     

    when i click on that link "see my profile" it shows me "Welcome SELECT * FROM users WHERE username =steve. Click here to"

     

    im pretty sur that this has to do with this line of code:

     

    Welcome <?php echo "SELECT * FROM users WHERE username =".$_SESSION["username"] ; ?>

     

    please refer to code below to locate the line that is giving me the wrong output

     

     

    Note : i ve been digging on that in google and im sur that line should give the info of the logged user please help me with this matter and of you need more info let me know

     

    thanks in advace

     

     

     

    ----------------------------------------------------- code-----------------------

     

     

    <?php
    session_start();
    ?>
    <html>
    <head>
    <title>User Login</title>
    <link rel="stylesheet" type="text/css" href="styles.css" />
    </head>
    <body>
    <table border="0" cellpadding="10" cellspacing="1" width="500" align="center">
    <tr class="tableheader">
    <td align="center">User Dashboard</td>
    </tr>
    <tr class="tablerow">
    <td>
    <?php
    if($_SESSION["username"]) {
    ?>
    Welcome <?php echo "SELECT * FROM users WHERE username =".$_SESSION["username"] ; ?>.
    Click here to <a href="logout.php" tite="Logout">Logout.<br /> <a href="profile.php" tite="profile"> see my profile
    <?php
    }
    ?>
    </td>
    </tr>
    </body></html>
  2. hi there

     

    thanks for your reply first , actually as i mentioned in my first post i m using this code snipet so i copied/pasted the code to see if it s working and then try to customized for my need so i got stack with these errors.so. i guess that the code snipet should not use it as you mentioned

     

    in this case could you please suggest me what to use instead or point me to what can be done and i will dig on it on my own that will be very appreciated

     

    thanks again for taking time to read my posts

     

    Note : im beginer in PHP so when im stack on something i use google to find out solution or this site w3schools or hints from this forum :)

  3. Hi there

     

    thank you for your reply it was helpful fixing that problem but now i got another error related to this line :

     

    $this->connection = mysql_connect('localhost','root','') or die(mysql_error());

     

    and the error was :Fatal error: Using $this when not in object context in C:wampwwwphploginsnipetlogin_check.php on line 10

     

    any suggestion would be appreciated

     

    thanks in advance

  4. please im seeking help through your helpful webite

     

    im using a code snipet from a website regarding user logon session so i got the error :

     

    Parse error: syntax error, unexpected '"', expecting ')' in your code on line 28

     

    i check on php code checker and got the same error

     

    below is the code in question please point me to the error to be fixed as im unable to locate it even if im considering the error line and had a look at my code but eas unable to resolve this issue

     

    also i found in google somethingn related to php version but im not sur so FYI im using version 5.4,16 ofo PHP

     

    thank you in advance

     

    code :

     

    ------------------------------------------

     

    /* Snippet #1 */

    <?php
    // login_check.php
    define("server", "localhost");
    define("user", "root");
    define("password", "");
    define("name", "test");
    $connection;
    $this->connection = mysql_connect(localhost,root,'') or die(mysql_error());
    mysql_select_db(name, $this->connection) or die(mysql_error());
    function is_logged_in () {
    if (!($_SESSION["id"]) || ($_SESSION["id"] == "") || ($_SESSION["id"] == 0)) {
    Header("Location: ./login.php");
    exit();
    }
    }
    function clean_input($input) {
    $clean = array("",'<','>','`',':',';','/','(',')','{','}','[',']');
    //$with = array();
    return str_ireplace($clean,'', $input);
    }
    function login_check ($forms) {
    $error = "";
    $username = clean_input($forms["username"]);
    $password = clean_input($forms["password"]);
    if (trim($username) == "") $error .= "<li>Your username is empty.</li>";
    if (trim($password) == "") $error .= "<li>Your password is empty.</li>";
    /* from here, do your sql query to query the database to search for existing record with correct username and password */
    $query = "SELECT password, username FROM users WHERE username = '".mysql_real_escape_string($username)."' AND password = '".mysql_real_escape_string($password)."'";
    $result = mysql_query($query, $this->connection);
    if(!$result || (mysql_numrows($result) < 1)) {
    $error = "Invalid username or password";
    }else
    {
    $error = "";
    }
    if (trim($error)!="") return $error;
    }
    function login ($forms) {
    $username = clean_input($forms["username"]);
    $password = clean_input($forms["password"]);
    /* do your sql query again, but now returning the id of member */
    $query = "SELECT member_id FROM users WHERE username = '".mysql_real_escape_string($username)."' AND password = '".mysql_real_escape_string($password)."'";
    $result = mysql_query($query, $this->connection);
    $result = mysql_query($query, $this->connection);
    if(!$result || (mysql_numrows($result) < 1)) {
    $id = 0;
    }else
    {
    $id = $result;
    }
    return $id;
    }
    ?>

     

     

  5. hi

     

    actually i tried this http://localhost/ajaxdataphp/ajaxtest.html

     

    its working partially but when i choose the first opttion or name it shows me the second one ,

     

    same for second shows me the 3rd

     

    and third shows me the 4th so it skeeps the 1st row

     

    i think there something to go with Id if im not mistaken

     

    i tried to change in the option values in html but same result any suggestions would be appreciated

     

     

    thanks in advance

  6. hi there

     

    im not sure what u r refering to here

     

    i use local host so when i run the html file i get the problem reported in my first post so when say type the URL what do u mean please check below :

     

    when i click on run the html file this is the adress i get on my browser : http://127.0.0.1:8020/ajaxdataphp/ajaxtest.html (problem when i choose a value like reported in first post)

     

    so what do you mean by typinh the url here

     

    thank u in advance

  7. Hi there

     

    thanks for ur reply first,

     

    i have tried as u suggested this code :

     

    <?phpecho 'Hello, World!';exit;?>

     

    and it returned hello world which is fine

     

    so i have tried to replace the (q) in my code with a value which 2 and executed the php file and it returned the right row corresponding to number 2 please check image below to see what im talking about

     

     

    ( ! ) Notice: Undefined index: q in C:wampwwwajaxdataphpgetuser.php on line 23 Call Stack # Time Memory Function Location 1 0.0020 143968 {main}( ) ..getuser.php:0 Firstname Lastname Age Hometown Job Joseph Swanson 39 Quahog Police Officer

     

    thanks in advance

  8. hi thereplease be noted that i need help with the code found on w3schools regarding fetching data from mysql dbase using php and ajax and im using 2 files one is html and second one is phpi used the 2 codes below but when i select a user all i get is this please see below :Firstname Lastname Age Hometown Job "; while($row = mysql_fetch_array($result)) { echo ""; echo "" . $row['FirstName'] . ""; echo "" . $row['LastName'] . ""; echo "" . $row['Age'] . ""; echo "" . $row['Hometown'] . ""; echo "" . $row['Job'] . ""; echo ""; } echo ""; mysql_close($con); ?>Note : that i have created the same database suggested i just wanted to try that and see if it works and then proceed with my own database and tablesNote : my database is :testmy table is :userHTML CODE :---------<html><head> <script>function showUser(str) { if (str == "") { document.getElementById("txtHint").innerHTML = ""; return; } else { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById("txtHint").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET","getuser.php?q="+str,true); xmlhttp.send(); }}</script></head><body><form><select name="users" onchange="showUser(this.value)"> <option value="">Select a person:</option> <option value="1">Peter Griffin</option> <option value="2">Lois Griffin</option> <option value="3">Joseph Swanson</option> <option value="4">Glenn Quagmire</option> </select></form><br><div id="txtHint"><b>Person info will be listed here.</b></div></body></html>---------------------PHP CODE :=========<?php$q = intval($_GET['q']);$con = mysql_connect('localhost','root','','test');if (!$con) { die('Could not connect: ' . mysql_error($con));}mysql_select_db("test",$con);$sql="SELECT * FROM user WHERE Id = '".$q."'";$result = mysql_query($con,$q);echo "<table border='1'><tr><th>Firstname</th><th>Lastname</th><th>Age</th><th>Hometown</th><th>Job</th></tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "<td>" . $row['Age'] . "</td>"; echo "<td>" . $row['Hometown'] . "</td>"; echo "<td>" . $row['Job'] . "</td>"; echo "</tr>";}echo "</table>";mysql_close($con);?>

×
×
  • Create New...