Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8045591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:35:47+00:00 2026-06-05T05:35:47+00:00

I’m trying to learn some javascript and i’m having trouble figuring out why my

  • 0

I’m trying to learn some javascript and i’m having trouble figuring out why my code is incorrect (i’m sure i’m doing something wrong lol), but anyways I am trying to create a login page so that when the form is submitted javascript will call a function that checks if the login is in a mysql database and then checks the validity of the password for the user if they exist. however I am getting an error (Illegally Formed XML Syntax) i cannot resolve. I’m really confused, mostly because netbeans is saying it is a xml syntax error and i’m not using xml. here is the code in question:

function validateLogin(login){

  login.addEventListener("input", function() {
    $value = login.value;
    if (<?php
    //connect to mysql
    mysql_connect(host, user, pass) or die(mysql_error());
    echo("<script type='text/javascript'>");
    echo("alert('MYSQL Connected.');");
    echo("</script>");
    //select db
    mysql_select_db() or die(mysql_error());
    echo("<script type='text/javascript'>");
    echo("alert('MYSQL Database Selected.');");
    echo("</script>");
    //query
    $result = mysql_query("SELECT * FROM logins") or die(mysql_error()); 
    //check results against given login
    while($row = mysql_fetch_array($result)){
      if($row[login] == $value){
        echo("true");
        exit(0);
      }
    }
    echo("false");
    exit(0);
      ?>) {
      login.setCustomValidity("Invalid Login. Please Click 'Register' Below.")
    } else {
      login.setCustomValidity("")
    }

  });
}

the code is in an external js file and the error throws on the last line. Also from reading i understand best practices is to not mix js and php so how would i got about separating them but maintaining the functionality i need?
thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:35:48+00:00Added an answer on June 5, 2026 at 5:35 am

    You can’t mix PHP and JavaScript in this way as all of your PHP has already executed on the server before any of your JavaScript executes on the client.

    The error is because the client is receiving and failing to execute this as JavaScript:

    function validateLogin(login){
    
      login.addEventListener("input", function() {
        $value = login.value;
        if (<script type='text/javascript'>alert('MYSQL Connected.');</script>...
    // etc.
    

    To interact with PHP from the client, you’ll have to make another HTTP request — either by <a> click, <form> submit, or Ajax request (using jQuery.post for brevity; see Using XMLHttpRequest for further details):

    function validateLogin(login){
      login.addEventListener("input", function() {
        $.post('/validateLogin.php', { login: login }, function (result) {
          if (result === "true") {
            login.setCustomValidity("Invalid Login. Please Click 'Register' Below.")
          } else {
            login.setCustomValidity("")
          }
        });
      });
    }
    

    Adjust the URL, /validateLogin.php, as needed; but create a PHP file for this URL similar to:

    <?php
    $value = $_POST['login'];
    
    mysql_connect(host, user, pass) or die(mysql_error());
    mysql_select_db() or die(mysql_error());
    
    $result = mysql_query("SELECT * FROM logins") or die(mysql_error());
    while($row = mysql_fetch_array($result)){
      if($row[login] == $value){
        echo("true");
        exit(0);
      }
    }
    echo("false");
    exit(0);
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.