SitePoint Sponsor

User Tag List

Results 1 to 16 of 16

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Response Text Error!

    OK. My 'logincontainer is hard coded HTML in the index.html page and is shown when a 'placeorder' button is clicked. The client enters their e-mail address in the only input visible and javascript addevent onchange checks to see if it is a valid e-mail or not. Above the input id 'login' is a span tag id 'loginrequest' which serves as server responceText. When the 'login.value' is a valid email address the second input is made visible id 'pass'. The 'pass' input addevent onchange query's the database with 'SELECT id FROM members WHERE login= '".($login)."' AND pass='".($pass)."'". The problem is

    ResponceText span id 'loginrequest'
    Code:
    Parse error: syntax error, unexpected $end in D:\use_ide_1\UniServer\www\getmember.php on line 26
    MyDb Members Table Columns
    id|status|started|name|login

    Ajax call in index.js
    Code:
    var emailformat=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
    var lrq=document.getElementById('loginrequest');
    var login=document.getElementById('login');
    var passwordlist=document.getElementById('passwordlist');
    var temail=document.getElementById('temail');//html table cell written to
    
    function logincheck(){
    var p=login.value;
    if(p==' '){
    lrq.innerHTML='Please Enter Your E-mail Address to login and register.';
    return false;
    }
    if(emailformat.test(p)){
    lrq.innerHTML='Please enter Your password.';
    temail.innerHTML=p;
    passwordlist.className='show'; 
    return false; 
    }
    else{
    lrq.innerHTML='Please Enter a Valid E-mail address.';
    return true;//works
    }} 
    
    addEvent(login,'change',function(){logincheck();},false); 
    
    var pass=document.getElementById('pass');
    
    function getmember(p){
    if(p==' '){//if 'pass.value' is empty?
    lrq.innerHTML=' ';
    }
    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)
    {
    lrq.innerHTML=xmlhttp.responseText;
    }
    }
    xmlhttp.open('GET','members.php?q='+p,true);//+p being 'pass.value'? no +e login.value?
    xmlhttp.send();
    }
    
    addEvent(pass,'focus',function(){lrq.innerHTML='Minimum 8 characters, Maximum 12.';},false);
    
    addEvent(pass,'change',function(){
    var e=login.value;
    var p=pass.value;
    getmember(p);//Ajax call
    },false);
    getmember.php
    Code:
    1.	<?php
    
    2.	$q=$_GET["q"];//p or 'pass.value' variable? no 'e' or 'login.value'
    
    3.	$link=mysql_connect("localhost","root","root")or die(mysql_error( ));
    
    4.	mysql_select_db("bwi",$link) or die(mysql_error( )); 
    
    5.	$query=mysql_query("SELECT id FROM members WHERE login= '".($login)."' 
    6.	AND pass='".($pass)."'")or die(mysql_error());      
    7.	if($query_num_rows==0){       
    8.	echo 'You must register';//responceText gets the echo?    
    9.	}
    10.	else if($query_num_rows ==1){
    
    11.	while($row = mysql_fetch_array($query))
    
    12.	{
    
    13.	echo "Welcome back " . $row['name'] . ". You may change relevant items.";
    
    14.	}
    
    15.	mysql_close($link);
    16.	?> 
    //no line 26?
    I've got quite an elegant get php that returns beautiful html to a main display div from MyDb but post is probably smarter and the 'SELECT id FROM members' syntax is the issue. Please help me if you can. I can't get the gist of the other posts as they involve starting sessions etc.

  2. #2
    SitePoint Zealot Gman's Avatar
    Join Date
    Jan 2002
    Location
    Sarasota, FL
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In getmember. Remove your

    Else if and just use if on line 10

  3. #3
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Responce Text Error!

    Gman thanks for the responce, I will check it out now and get back.

  4. #4
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Responce Text Error!

    Gman Got the same responceText error. If I use ' php $e=post['login']; ' is that the input id 'login' that I'm posting or it's value? I've seen quite a few javascript like php 'if else' like statements but I'm not sure if the server excepts the value of the input as just the input id/name?
    Something like this.
    PHP Code:
    <?php

    $e
    =post["login"];//e or 'login.value' variable? 'login' is the input id

    $p=post["pass"];//p or 'pass.value' variable?  'pass' is the input id

    $link=mysql_connect("localhost","root","root")or die(mysql_error( ));

    mysql_select_db("mydb",$link) or die(mysql_error( )); 

    $query=mysql_query("SELECT id FROM members WHERE login= '".($e)."' 
    AND pass='"
    .($p)."'")or die(mysql_error()); 
    if(
    $query_num_rows ==0)
    {
     echo 
    "You must register, no such email address was found";   
    }    
    else if(
    $query_num_rows ==1)
    {
    while(
    $row mysql_fetch_array($query))
    echo 
    "Welcome back " $row['name'] . ". You may change relevant items.";
    }
    }
    mysql_close($link);
    ?>
    This returned
    PHP Code:
    Parse errorsyntax errorunexpected '[' in D:\use_ide_1\UniServer\www\mexicali.php on line 3 
    I'm guessing that post variables need to be initialized or something.

  5. #5
    SitePoint Zealot Gman's Avatar
    Join Date
    Jan 2002
    Location
    Sarasota, FL
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $login = $_POST["login"]; //We use the $_POST array
    
    
    $password = $_POST["pass"]; //
    
    
    $link = mysql_connect("localhost", "root", "root") or die(mysql_error());
    
    
    mysql_select_db("mydb", $link) or die(mysql_error());
    
    
    $query = mysql_query("SELECT id FROM members WHERE login = $login AND pass = $password") or die(mysql_error());
    
    // Get the row count
    $num_rows = mysql_num_rows($query);
    
    
    if ($num_rows == 0) {
        echo "You must register, no such email address was found";
    } else {
        while ($row = mysql_fetch_array($query)) {
            echo "Welcome back " . $row['name'] . ". You may change relevant items.";
        }
    }
    
    
    mysql_close($link);

  6. #6
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Responce Text Error!

    Gman doesn't that mean the ajax call has to be changed to post from get
    Code:
    function members(p){//take p out of members(p)?
    if(p==' '){
    lrq.innerHTML=' ';
    }
    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)
    {
    lrq.innerHTML=xmlhttp.responseText;
    }
    }
    xmlhttp.open('GET','mexicali.php?q='+p,true);//change 'GET' to 'POST'?
    xmlhttp.send();
    }

  7. #7
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does Heinz Stapff here = THEFOOL over at webdeveloper.com?

    If so, does the solution posted there for your request for help (which is a copy and paste of the op here) work?

    http://www.webdeveloper.com/forum/sh...11#post1178611

  8. #8
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Responce Text Error!

    webdev1958 one and the same, soon to be 'OMA'. I replied to that post just a minute ago. I've never seen that syntax before and it seems like an all rounder crossbrowser solution for 'GET' and 'POST' methods that doesn't help me with 'SELECT id FROM members WHERE login='".$login."' AND pass='".$pass"' syntax or posting variables in php like '$num=mysql_num_rows($query)' as it applies to the php if and else statements with comparison operator '==0' and '==1' so that the 'responceText' can return a statement in either case.

  9. #9
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Gman and webdev1958
    Just to let you know where I'm at. Thanks for your help. I will post back as soon as I got a solution.

    007Julien @webdeveloper.com thanks for that, I posted on DaniWeb my thoughts that passing two variables with 'get' method was not possible. You are saying that it is? I guess I'll do some research on Mr. Peter Paul Koch to see if I can get a better understanding of using 'get' with multiple variables which might have been a better title for this post. I used the same post title on Daniweb, and Sitepoint so I'm going to copy and paste this reply to them.

  10. #10
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Responce Text Error!

    Gmanat SitePoint.com and webdev1958
    at SitePoint.com As I posted at WebDeveloper.com, I'm really struggling here. Please help me if you can. I'm struggling to add multiple variables to a get Ajax call and adding a function that returns a different response if the database values don't match the input values.
    I'm going to copy and paste to DaniWeb.com where I have posted under the same title. Thanks for any consideration in advance.
    007Julienat WebDeveloper.com. well I'm realy strugling with this. I tried the article syntax to add multiple variables to the getmember.php but I get this error as responce text

    Error!

    Code:
    Notice: Undefined variable: _Get in D:\use_ide_1\UniServer\www\mexicali.php on line 3


    getmember.php

    Code:
    <?php
    $login=$_GET['login'];
    $pass=$_Get['pass'];//line 3 Error?
    $link=mysql_connect("localhost","root","root")or die(mysql_error( ));
    mysql_select_db("bwi",$link) or die(mysql_error( )); 
    $query=mysql_query("SELECT * FROM members WHERE login='".($login)."' AND pass='".($pass)."'")or die(mysql_error());
    while($row = mysql_fetch_array($query))
    {
    echo "Welcome back " . $row['name'] . ". You may change relevant items.";
    }
    mysql_close($link); 
    ?>


    Ajax call

    Code:
    function getmember(){
    var p=pass.value;
    if(p==' '){
    lrq.innerHTML=' ';
    }
    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)
    {
    lrq.innerHTML=xmlhttp.responseText;
    document.getElementById('pass2list').style.display='none';
    document.getElementById('emailpasslist').style.display='none';
    document.getElementById('loginrequest').style.display='block';
    document.getElementById('changepasslist').className='show';
    document.getElementById('continuelogin').style.visibility='visible';
    document.getElementById('logincontainer').style.paddingBottom='12%';
    //This works all the time even if the password and login don't match
    
    //do I need an if (xmlhttp.readyState==4 && xmlhttp.status==404)
    
    //i.e. when the values doen't match the database values?
    }
    }
    var loginvalue=encodeURIComponent(document.getElementById('login').value)
    var passvalue=encodeURIComponent(document.getElementById('pass').value)
    xmlhttp.open('GET','mexicali.php?login='+loginvalue+'&pass='+passvalue,true);
    xmlhttp.send(null);
    
    //added as the article indicated but throws undefined variable error on 
    
    // $pass=get['pass']; line 3?
    }


    I know I've simplified the variables and not stripped slashes or sanitized or MD5'd the password etc. but I'm just trying to understand what's going on. The dbase field 'login' is mysql phpadmin varchar(30) and the 'pass' field is varchar(12) but adding $login=(varchar)$_get['login']; like the article showed for (int)$_get['age']; produced an 'unexpected T error on line where I used (varchar)'? I still have to insert new members so I have to know what I'm doing before I proceed. For sure the insert members function will be a post onsubmit.

  11. #11
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The downside of posting for help on multiple websites is that if you get discovered, as in this case, you risk not getting as much help as you otherwise would because some people are put off spending time posting a suggested solution on one of your websites when you might have already received a solution on another website.

  12. #12
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Responce Text Error!

    webdev1958 You are right again but I don't have time to mess around and I have to get answers.

  13. #13
    SitePoint Zealot Gman's Avatar
    Join Date
    Jan 2002
    Location
    Sarasota, FL
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you have $_Get['pass']; should be: $_GET['pass'];

  14. #14
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs down Responce Text Error!

    Gman roger that, already fixed. Working on hideing and showing different fields by testing xhtml.responceText in readystatchange function of Ajax call. It's driving me nuts. Will post results manyana.

  15. #15
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Responce Text Error!

    OK. Thanks for the advice? 'Search: "Manipulating Form elements with xmlhttp.responseText" or "Handling xmlhttp.responseText" would have been good advice if the searches where not so convoluted with cryptic scenario solutions like this statement. At least it would have pointed me in the right direction! It makes me wonder whether the geniuses can actually speak English as their demonstration and communication skills appear to be left wanting'.
    To others that suggested that posting to multiple forums "won't earn you friends or answers!" I will say that I have one too many friends already but I lack the education needed to enhance future prospects and that is why I spend my 'extra' time in multiple forums searching, not just for answers and certainly not for 'friends' but for 'direction' and 'education'!
    Given that the current geniuses seem to lack the ability to grasp this simple concept, 'free education for all who are willing to put in the time to be educated', I've felt like it is some kind of secrete technology that others don't want to share and that I should throw in the towel.
    Then I realize that that is the true power of the web, 'You can't hide a lit candle in a hay stack'.

    THEFOOL a.k.a HEINZ PAUL STAPFF.
    Last edited by Heinz Stapff; Nov 7, 2011 at 10:30. Reason: To copy and paste to another forum, sorry!

  16. #16
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Response Text Error!

    One more try? I've been trying to manipulate the login form with the xmlhttp.responseText written to a p tag id="loginrequest". I know the three responses I expect, that do work. I even wrote them to an array and called the last member of the array added with .push using .split(-1) but checklogin()/response handler will alert the innerHTML of 'loginrequest' or the .split(-1) of the array and still ignores 'if(loginrequest.innerHTML==' Something'){//do something}if(loginrequest.innerHTML=='Something Else'){//do something else}. The separate ifs are supposed to reveal extra form fields but don't.
    1.)For a new member ie. not found on the db, 'loginrequest' reads, 'Not a member? Please register to submit your order.' A confirm password input should appear.
    2.)For correct login and wrong password, ie. members login found but password is wrong, 'loginrequest' reads, 'Your password is wrong, you have 3 more attempts to get it right.' No other form fields appear until the input is entered correctly. If the third attempt fails a link should appear with id='emailpass'.
    3.)For members found ie. when both login or password is found, 'loginrequest' reads, 'Welcome back " . $row[2] . ". You may change relevant items.' 3 links allowing them to change their password, billing and shipping info.

    This appears to be standard site login, so the question is, "Can I use the responseText, either stored in an array or directly from the p tag to alter the form by checking against the innerHTML of the p tag or the value.slice(-1) of the array written to using a php get or does it have to be a post?"

    I've tried three methods with getmember.php.
    a.)if(xmlhttp.responseText=='Welcome back...
    b.)if(loginrequest.innerHTML=='Welcome back...
    C.)if(arrayvalue.slice(-1)=='Welcome back...

    all three alert correctly but none affects the html output.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •