Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2011
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Inserting Javascript code into PHP

    I am trying to write an authentication code for my site.
    Cant figure out whats wrong.

    The line with *** is giving me this error :
    Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampp\htdocs\idpass.php on line 31


    Code:
    if($row['id']==$id&&$row['pass']==$pass)
    	{	
    	echo "You have logged in!";
    	echo '<script type="text/javascript">';
    ***	echo "function hide(){document.getElementById("form1").style.display = 'none';}";
    	echo '</script>';
    	}
    	else
    	{
    		echo "Invalid Username and/or Password!";
    	}
    Last edited by cyborg911; 04-12-2011 at 06:31 AM.

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    PHP Code:
    echo "function hide(){document.getElementById("form1").style.display = 'none';}"
    Whenever you want to include quotes within a string, the internal quotes must be escaped if you want then to be the same as the outer quotes or of the opposite type. Personally I prefer to use opposite type internal quotes.

    Try

    Code:
    echo "function hide(){document.getElementById('form1').style.display = 'none';}";


  •  

    Posting Permissions

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