Solved PHP code error on line 28

Hewlett-packard / Cq61 notebook
April 30, 2013 at 05:22:16
Specs: Windows 7, AMD sempron 2 gb
Hi could someone please check this code and tell me why I get this error and tell me how to fix it?

Parse error: syntax error, unexpected end of file in C:\inetpub\wwwroot\input.php on line 28

This is the code:

<HTML>
<?php
if($submit)
{
$db = mysql_connect("localhost", "root","mypassword");
mysql_select_db("learndb",$db);
$sql = "INSERT INTO personnel (firstname, lastname, nick, email, salary)
VALUES ('$first','$last','$nickname','$email','$salary')";
$result = mysql_query($sql);
echo "Thank you! Information entered.\n";
}
else
{
?>
<form method="post" action="input.php">
First name:<input type="Text" name="first">

Last name:<input type="Text" name="last">

Nick Name:<input type="Text" name="nickname">

E-mail:<input type="Text" name="email">

Salary:<input type="Text" name="salary">

<input type="Submit" name="submit" value="Enter information"></form>
<?
}
?>
</HTML>
Also don't understand why it says error on line 28 when there are only 25 lines in the code.
Thank you


See More: PHP code error on line 28

Report •


✔ Best Answer
April 30, 2013 at 22:13:52
Razor's 3rd note and Fishmonger's first post are correct. You didn't properly open up the PHP tag on line 27.

<input type="Submit" name="submit" value="Enter information"></form>
<?php
}
?>
</HTML>

Apologies if I don't respond to your reply immediately. I don't check this site daily, but you're welcome to PM me as a reminder.



#1
April 30, 2013 at 05:43:56
Carlo2837: Also don't understand why it says error on line 28 when there are only 25 lines in the code.
Notepad tells me you pasted 30 lines.

Carlo2837: $sql = "INSERT INTO personnel (firstname, lastname, nick, email, salary)
VALUES ('$first','$last','$nickname','$email','$salary')";

Fun with SQL: Set the first name to:

Robbert'); DROP TABLE personnel;--
Make sure your database is backed up first.

Carlo2837: unexpected end of file in C:\inetpub\wwwroot\input.php on line 28
I don't actually do PHP, but think the second "<?" is missing "php".

How To Ask Questions The Smart Way


Report •

#2
April 30, 2013 at 06:22:09
Change line 27 from:
<?

to this:
<?php


Report •

#3
April 30, 2013 at 06:28:43
Or, use a heredoc.

<HTML>
<?php
if($submit)
{
    $db = mysql_connect("localhost", "root","mypassword");
    mysql_select_db("learndb",$db);
    $sql = "INSERT INTO personnel (firstname, lastname, nick, email, salary)
    VALUES ('$first','$last','$nickname','$email','$salary')";
    $result = mysql_query($sql);
    echo "Thank you! Information entered.\n";
}
else
{
echo <<<FORM
<form method="post" action="input.php">
First name:<input type="Text" name="first">

Last name:<input type="Text" name="last">

Nick Name:<input type="Text" name="nickname">

E-mail:<input type="Text" name="email">

Salary:<input type="Text" name="salary">

<input type="Submit" name="submit" value="Enter information"></form>

FORM;

}
?>
</HTML>


Report •

Related Solutions

#4
April 30, 2013 at 09:16:48
Hi I don't understand why I should drop the table personnel, all I need is the code that I copied from a tutorial checked and how to fix it. I think there is some problem with those tags.

Report •

#5
April 30, 2013 at 22:13:52
✔ Best Answer
Razor's 3rd note and Fishmonger's first post are correct. You didn't properly open up the PHP tag on line 27.

<input type="Submit" name="submit" value="Enter information"></form>
<?php
}
?>
</HTML>

Apologies if I don't respond to your reply immediately. I don't check this site daily, but you're welcome to PM me as a reminder.


Report •

#6
May 1, 2013 at 02:10:42


Hi XPs86, I corrected the code as you suggested..Now I get to see the form and also an error:
undefined variable submit in C:\inetpub\wwwroot\ input.php on line 4. My version of php is 5.4, here is the updated code:
<HTML>
<?php
if($submit)
{
$db = mysql_connect("localhost", "root","mypassword");
mysql_select_db("learndb",$db);
$sql = "INSERT INTO personnel (firstname, lastname, nick, email, salary)
VALUES ('$first','$last','$nickname','$email','$salary')";
$result = mysql_query($sql);
echo "Thank you! Information entered.\n";
}
else
{
?>
<form method="post" action="input.php">
First name:<input type="Text" name="first">

Last name:<input type="Text" name="last">

Nick Name:<input type="Text" name="nickname">

E-mail:<input type="Text" name="email">

Salary:<input type="Text" name="salary">

<input type="Submit" name="submit" value="Enter information"></form>
<?php
}
?>
</HTML>


Report •


Ask Question