I wonder whether someone may be able to help me please.
I'm trying to use the script below to return data from a mySQL into a HTML form.
<?php
require("phpfile.php");
// Opens a connection to a MySQL server
$connection=mysql_connect ("host", $username, $password);
if (!$connection) { die('Not connected : ' . mysql_error());}
// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
$email = $_POST['email']
$sql = mysql_query("SELECT * FROM userdetails WHERE emailaddress like '%$email%'");
while($row = mysql_fetch_array($sql))
{
echo $row['forename'];
echo $row['surname'];
echo "<br />";
}
?>
The field which is used to match the input data to that held in my database is the email address. Basically if the keyed in email address matches a record in the database, it returns the first and surname.
However when I run it I receive the following error:
Parse error: syntax error, unexpected T_VARIABLE in /homepages/2/d333603417/htdocs/development/search.php on line 18
Where Line 18 is:
$sql = mysql_query("SELECT * FROM userdetails WHERE emailaddress like '%$email%'");
I've taken the source code from a tutorial I found on the Internet and I've been back to the source and rechecked my field names etc and I can't find out what the problem is.
Could som开发者_高级运维eone perhaps take a look at this and let me know where I'm going wrong please?
Many thanks
$email = $_POST['email']
$sql = mysql_query("SELECT * FROM userdetails WHERE emailaddress like '%$email%'");
change to:
$email = $_POST['email'];
$sql = mysql_query("SELECT * FROM userdetails WHERE emailaddress like '%$email%'");
you forgot the ; after declaring your $email variable.
Also, the clue here is unexpected T_VARIABLE.
Basically, unexpected means that the script was doing something and unexpectedly encountered something it shouldn't have during the process. In this case it unexpectedly encountered a variable ( T_VARIABLE ) when it was "expecting" a semi colon.
The line above line 18 lacks a semi-colon which is causing line 18 to be parsed incorrectly.
$email = $_POST['email']
The clue is "Parse error: syntax error", which oftentimes means you have a missing semi-colon, parentheses or curly brace in a previous statement.
精彩评论