/    Sign up×
Community /Pin to ProfileBookmark

Responce 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
[B][U]ResponceText span id ‘loginrequest’[/U][/B]

[code]
Parse error: syntax error, unexpected $end in D:use_ide_1UniServerwwwgetmember.php on [B][COLOR=red]line 26[/COLOR][/B][/code]

[B][U]MyDb Members Table Columns[/U][/B]
id|status|started|name|login
[B][U]Ajax call in index.js[/U][/B]

[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);
[/code]

[B][U]getmember.php[/U][/B]

[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?
[/code]

I’ve got quite an elegant [B]get[/B] 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.?

to post a comment
PHP

16 Comments(s)

Copy linkTweet thisAlerts:
@007JulienNov 03.2011 — The least if($query_num_rows ==1){in [I]getmember.php[/I] seems not to be closed ...
Copy linkTweet thisAlerts:
@THEFOOLauthorNov 03.2011 — Today 04:41 PM007Julien

[LEFT][B][COLOR=blue]Today 04:41 PM[/COLOR][/B][B][COLOR=blue]007Julien[/COLOR][/B]

[COLOR=blue][B]007Julien [/B][/COLOR][COLOR=black]it is closed but it still produces an error of 'undefined variable:query_num_rows'. I've decided I have to chage the ajax call to post and write the variables in the getmember.php and am strugling with the $number=mysql_num_rows(query) variable and changing the ajax call to post[/COLOR]

[B][U]Ajax call[/U][/B]
[CODE]
function getmember(p){//exclude p from ()?
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);//change 'GET' to 'POST' ?xmlhttp.send();
}
[/CODE]

[B][U]getmember.php[/U][/B]
[CODE]
<?php
$login=post["login"];//that is the login input id/name?
$pass=post["pass"];//that is the password input id/name?
$q=$_GET["q"];//p or 'pass.value' variable? no 'e' or 'login.value'
$link=mysql_connect("localhost","root","root")or die(mysql_error( ));
mysql_select_db("bwi",$link) or die(mysql_error( ));
$query=mysql_query("SELECT id FROM members WHERE login= '".($login)."' AND pass='".($pass)."'")or die(mysql_error());

$num=mysql_num_rows($query);

if($num==0)
{

echo 'You must register';//responceText gets the echo?

}
else if($num ==1)
{
while($row = mysql_fetch_array($query))
{
echo "Welcome back " . $row['name'] . ". You may change relevant items.";
}
15. mysql_close($link);
16. ?>
[/CODE]
[/LEFT]
Copy linkTweet thisAlerts:
@007JulienNov 04.2011 — I use this old function (from Peter Paul Koch) for Ajax calls
[CODE]var xmlObj=false;
var xmlFct=[function(){return new XMLHttpRequest()}
// the two first functions are only for old IE versions
,function(){return new ActiveXObject("Msxml2.XMLHTTP")}
,function(){return new ActiveXObject("Msxml3.XMLHTTP")}
,function(){return new ActiveXObject("Microsoft.XMLHTTP")}];
for (var i=0;i<xmlFct.length;i++) {try{xmlObj = xmlFct[i]();}catch(e){continue;}break;}
function sndRqu(url,cllbck,pstDta){
var req=xmlObj;
if (!req) return;
var mth=(pstDta)? "POST":"GET";
req.open(mth,url,true);
req.setRequestHeader('User-Agent','XMLHTTP/1.0');
if (pstDta) req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
req.onreadystatechange=function(){
if (req.readyState!=4) return;
if (req.status!=200 && req.status!=304) {// 200 Ok, 304 Redirection Not modified
// alert('HTTP error ' + req.status);
return;}
cllbck(req);}
if (req.readyState==4) return;
req.send(pstDta);
};[/CODE]


For POST request, you have in particular to add a [B]xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');[/B]
Copy linkTweet thisAlerts:
@THEFOOLauthorNov 04.2011 — [COLOR=#0000ff][B]007Julien[/B][/COLOR][COLOR=black], wierd, I've never seen syntax like the one in your last post but I guess it's a crossbrowser all rounder solution that deals with 'get' and 'post' situations. The funny thing is, my get function applies the id of the element clicked to the get['q'] select from mysql query in getproduct.php and simplifies all the get ajax nicely. I'm not sure I could understand right now how to combine the two and make it work but thanks for the intro.[/COLOR]
Copy linkTweet thisAlerts:
@007JulienNov 04.2011 — With this function, you have only to write
[code=html]
<script type="text/javascript">
// For a GET request with your p, q (and an other couple u,v)
sndRqu('members.php?q='+encodeURIComponent(p)+'&v='+encodeURIComponent(u),function(r){var s=r.responseText;alert(s);});
// For a POST request the third argument is used (*)
sndRqu('members.php',function(r){var s=r.responseText;alert(s);},'q='+p+'&v='+u);
</script>
[/code]

Then to complete the callback function (replace the alert) to work with the answer...

(*) You have to serialize the data for a bigger form (See quirksmode.js).
Copy linkTweet thisAlerts:
@THEFOOLauthorNov 04.2011 — [COLOR=blue][B]007Julien[/B][/COLOR][COLOR=black] 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. [COLOR=#660000]Peter Paul Koch[/COLOR] 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.[/COLOR]
Copy linkTweet thisAlerts:
@007JulienNov 04.2011 — It obviously possible : see this pages...
Copy linkTweet thisAlerts:
@THEFOOLauthorNov 04.2011 — Roger that [COLOR=#0000ff][B]007Julien[/B][/COLOR][COLOR=black] the function is in the ajax call itself. I'll have to post back my result after I test it?[/COLOR]
Copy linkTweet thisAlerts:
@THEFOOLauthorNov 05.2011 — [COLOR=#0000ff][B]007Julien [/B][/COLOR][COLOR=black]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?[/COLOR]

[B][U]Error![/U][/B]
[CODE]
[B]Notice[/B]: Undefined variable: _Get in [B]D:use_ide_1UniServerwwwmexicali.php[/B] on line [B]3[/B]
[/CODE]


[B][U]getmember.php[/U][/B]
[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);
?>
[/CODE]


[B][U]Ajax call[/U][/B]
[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?
}
[/CODE]


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.?
Copy linkTweet thisAlerts:
@007JulienNov 05.2011 — At first $_Get is not $_GET ! (see Google with PHP case sensivity and for example this page).

Then it's better to write :
[code=php]xmlhttp.open('GET','mexicali.php?login='+encodeURIComponent(loginvalue)+'&pass='+encodeURIComponent(passvalue),true);[/code]
This avoid errors with blank or other specials characters in login or password.

In PHP, you have not to used the function url_decode (See the warning at the middle of this page )
Copy linkTweet thisAlerts:
@THEFOOLauthorNov 05.2011 — [COLOR=blue][B]007Julien [/B][/COLOR][COLOR=black]Thanks, I'm onit. Have to try your Ajax Call and alter the getmember.php. WPB:eek:[/COLOR]
Copy linkTweet thisAlerts:
@THEFOOLauthorNov 05.2011 — [COLOR=#0000ff][B]007Julien [/B][/COLOR][COLOR=black]Ok. I got it working but when the wrong password is entered the responceText or lrq.innerHTML doesn't show up but the other inputs do. Is there an 'if (responceText=='Not found')' or something else I can use. I've tried an elseif($row==0) in the getmember.php but have no luck. I guess I have to know the php and the ajax methodes of doing so if there is any?:eek: I'm overwhelmed that I can't find any simple examples of this on the web. Most people are echoing the whole form while mine is html?[/COLOR]
Copy linkTweet thisAlerts:
@007JulienNov 05.2011 — With your function and a callback function, you have no more to change this function.

If the user give a bad login or password... there is many methods to give an alert. For example you can echoing a error text like a rspTxt="rrr|message" and test if this rrr| exist (if rspTxt.substr(0,4)==''rrr|") to display the message with an alert(rspTxt.substr(4)); or an myResponseParagraph.innerHTML=rspTxt.substr(4);
Copy linkTweet thisAlerts:
@THEFOOLauthorNov 05.2011 — [COLOR=#0000ff][B]007Julien[/B][/COLOR][COLOR=black] that is what I'm looking for. I've searched for if else in php while $row but keep getting errors when trying to apply it. I know that checking xhtml.responceText is probably the way to go even though I would like to back it up on the server i.e. in the getmember.php. I need to see an example of both before I can go any further. Any direction is more than appreciated. Someting like 'if(($login!match login(in db)){echo "something"}' or 'if(xhtml.responceText==' ') { do something }' but I don't know where to put the statements or their syntax in the situation mentioned in this post?[/COLOR]
Copy linkTweet thisAlerts:
@THEFOOLauthorNov 07.2011 — 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.:eek:
Copy linkTweet thisAlerts:
@THEFOOLauthorNov 09.2011 — [B]One more try?[/B] 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, '[B]loginrequest' reads, 'Not a member? Please register to submit your order.[/B]' A confirm password input should appear.

2.)For correct login and wrong password, ie. members login found but password is wrong, 'loginrequest' reads, '[B]Your password is wrong, you have 3 more attempts to get it right.[/B]' 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, '[B]Welcome back " . $row[2] . ". You may change relevant items.[/B]' 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 [B]php get[/B] or does it have to be a post?"

[B][U]I've tried three methods with getmember.php[/U][/B].

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.?:eek:
×

Success!

Help @THEFOOL spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...