5 Replies - 813 Views - Last Post: 05 July 2012 - 02:56 AM Rate Topic: -----

#1 saravana pandian  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-July 12

how to solve the error?

Posted 04 July 2012 - 05:20 AM

<!-- PLEASE TELL HOW TO SOLVE THE ERROR FOR THE FOLLOWING CODE.
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in F:\xampp\htdocs\BASIC\form1.php
-->
<html>
<?php
  $connect=mysql_connect("localhost","root","");
  mysql_select_db("regis",$connect);

   if(isset($_REQUEST['submit']))
     {
      $result1=mysql_query("SELECT email,password FROM regist WHERE email='$_POST['mailid']' and password='$_POST['pwd']' ");<br>
      //$result2=mysql_query("SELECT  FROM regist WHERE ");
	  if($result1)
	     {
		    echo "YOU HAVE SUCCESSFULY LOG IN!";
		 }
	   else
	     {
		   echo "YOU ENTERED WRONG EMAIL/PASSWORD!, PLEASE TRY AGIAN!";
		  }
	  } 


?>
<body bgcolor="#33CCCC">
<br> <h1 align="center"><b>SIGNIN</b></h1>
<form action="www.google.com" method="post"><br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th scope="row">EMAIL&nbsp;</th>
    <td>:&nbsp;</td>
    <td><input name="mailid" type="text" />&nbsp;</td>
  </tr>
  <tr>
    <th scope="row">PASSWORD&nbsp;</th>
    <td>:&nbsp;</td>
    <td><input name="pwd" type="text" />&nbsp;</td>
  </tr>
  <tr>
    <th scope="row">&nbsp;</th>
    <td>&nbsp;</td>
    <td><input name="submit" type="submit"/>&nbsp;</td>
  </tr>
</table>
</form>
<?php
  echo " ";
  ?>
  </body>
  </html>


THIS IS THE ERROR MESSAGE..,
==========================
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in F:\xampp\htdocs\BASIC\form1.php on line 8


*** EDIT ***
Please use code tags when posting code
Posted Image

Attached File(s)

  • Attached File  form1.php (1.14K)
    Number of downloads: 17

This post has been edited by GunnerInc: 04 July 2012 - 07:47 AM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: how to solve the error?

#2 anonymouscodder  Icon User is offline

  • member icon

Reputation: 126
  • View blog
  • Posts: 710
  • Joined: 01-January 10

Re: how to solve the error?

Posted 04 July 2012 - 07:27 AM

This section is for Introductions! ('introduce yourself')

:code:

and be more polite instead of 'PLEASE TELL HOW TO SOLVE THE ERROR FOR THE FOLLOWING CODE'

;)
Was This Post Helpful? 1
  • +
  • -

#3 GunnerInc  Icon User is online

  • "Hurry up and wait"
  • member icon




Reputation: 876
  • View blog
  • Posts: 2,312
  • Joined: 28-March 11

Re: how to solve the error?

Posted 04 July 2012 - 07:46 AM

Moving...
Was This Post Helpful? 0
  • +
  • -

#4 mavidchar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-November 11

Re: how to solve the error?

Posted 05 July 2012 - 01:21 AM

I made a few changes to your code and I think now it is ok!

First of all, I introduced a new variable called $sql just to make the code more readable.
I changed the syntax a bit to overcome the error. See line 8.

Moreover, I used the function mysql_num_rows($result1) to check if something was returned from the database.

I would strongly recommend to check any data coming from the user before querying the database using them.

<?php
$message = "";
   if(isset($_REQUEST['submit']))
     {
       $connect=mysql_connect("localhost","root","");
       mysql_select_db("regis",$connect);
       
      $sql = "SELECT email FROM regist WHERE email='" . $_POST['mailid'] . "' AND password='" . $_POST['pwd'] . "'";
      $result1 = mysql_query($sql);
      //$result1=mysql_query("SELECT email,password FROM regist WHERE email='$_POST['mailid']' and password='$_POST['pwd']' ");//<br>
      //$result2=mysql_query("SELECT  FROM regist WHERE ");
      if(mysql_num_rows($result1) == 1))
         {
            $message =  "YOU HAVE SUCCESSFULY LOG IN!";
         }
       else
         {
           $message =  "YOU ENTERED WRONG EMAIL/PASSWORD!, PLEASE TRY AGIAN!";
          }
      }
?>
<html>
<body bgcolor="#33CCCC">
<br> <h1 align="center"><b>SIGNIN</b></h1>
<form action="www.google.com" method="post"><br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th scope="row">EMAIL&nbsp;</th>
    <td>:&nbsp;</td>
    <td><input name="mailid" type="text" />&nbsp;</td>
  </tr>
  <tr>
    <th scope="row">PASSWORD&nbsp;</th>
    <td>:&nbsp;</td>
    <td><input name="pwd" type="text" />&nbsp;</td>
  </tr>
  <tr>
    <th scope="row">&nbsp;</th>
    <td>&nbsp;</td>
    <td><input name="submit" type="submit"/>&nbsp;</td>
  </tr>
</table>
</form>
<?php
  echo $message;
  ?>
  </body>
  </html>


Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6110
  • View blog
  • Posts: 23,670
  • Joined: 23-August 08

Re: how to solve the error?

Posted 05 July 2012 - 02:36 AM

Thanks for trying, but you really failed to improve anything.

Look up SQL Injection, for starters, then go read the documentation and notice that the mysql_* functions should no longer be used, instead using PDO or the mysqli (MySQL Improved) extension.
Was This Post Helpful? 0
  • +
  • -

#6 mavidchar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 25-November 11

Re: how to solve the error?

Posted 05 July 2012 - 02:56 AM

Well, I know all these things but here the problem wasn't that and I didn't have the time to fully rewrite the code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1