Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP -an error message I get 1

Status
Not open for further replies.

lupidol

Programmer
Apr 23, 2008
125
IL
Hi everyone,
This is my PHP script
Code:
<?php
$con=mysqli_connect("localhost","root","rootpass","dbname");
if (mysqli_connect_errno($con))
  {
    <p class="SQLconnect">
		echo "Failed to connect to MySQL: " . mysqli_connect_error();
    </p>
  }
else
	{
		echo "Success connecting to MySQL! " ;
	}
?>
When I run it I get the following error message:
Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\tiv oni\scripts\tivoni_connect.php on line 5]
Can anyone tell me please why am I getting hat error?
Thanks
 
You are including raw HTML in your php. You need to use echo or print to output HTML or close/open php tags

So put the <p....></p> tags inside the echo statement.
 
You can't place HTML directly within PHP. Its not valid. You'll need to use an echo, or print to output HTML.

Code:
 <?php
$con=mysqli_connect("localhost","root","rootpass","dbname");
if (mysqli_connect_errno($con))
  {
   [b] <p class="SQLconnect">[/b]
		echo "Failed to connect to MySQL: " . mysqli_connect_error();
    [b]</p>[/b]
  }
else
	{
		echo "Success connecting to MySQL! " ;
	}
?>

Something like:

Code:
 <?php
$con=mysqli_connect("localhost","root","rootpass","dbname");
if (mysqli_connect_errno($con))
  {
  [b] echo'<p class="SQLconnect"> Failed to connect to MySQL: ' . mysqli_connect_error() . '</p>';[/b]
  }
else
	{
		echo "Success connecting to MySQL! " ;
	}
?>

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top