Help with a simple php/mysql website

Hi Guys,

This is my first post! I’m currently learning php/MySQL and I’m stuck on this php script that im writing that is based of the example from the O’reiley book on php, mysql, and javascript http://lpmj.net/10.php. I keep on getting this error “Parse error: syntax error, unexpected $end in C:\xampp\htdocs\pages\friends.php on line 78” (It’s pointing to the tag). Thx in advance! :smiley:

[php]<?php //friends.php
require_once ‘login.php’;

//connect to MySQL
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Unable to connect to MySQL: " .mysql_error());
echo "<p> connected </p>";

//connect to a database
mysql_select_db($db_database)
	or die("Unable to select database: " .mysql_error());
echo '<p> connected db</p> <br/>';

//Check
if (isset($_POST['delete']) && isset($_POST['name']))
{
	$name  = get_post('name');
	$query = "DELETE FROM main WHERE Name='$name'";
	if (!mysql_query($query, $db_server))  
		echo "DELETE failed: $query<br />" .
		mysql_error() . "<br /><br />";
}
if (isset($_POST['name']) && isset($_POST['age']) && isset($_POST['email']))
{
	$name = get_post('name');
	$age = get_post('age');
	$email = get_post('email');
	
	$query = "INSERT INTO main VALUES" .
	"('$name', '$age', '$email')";
		
	if (!mysql_quer($query, $db_server))
	{
		echo "INSERT failed: $query <br/>" . 
		mysql_error(). "<br><br/>";
	}
}
echo <<<_END
<form action ="friends.php" method="post"><pre>
	Name: <input type="text" name="name"/>
	Age:<input type="text" name="age"/>
	Email:<input type="text" name="email"/>
	<input type="submit" value="ADD RECORD"/>
	</pre></form>	
_END;
//select 
$query = "SELECT * FROM main";
$result = mysql_query($query);

if (!$result) die ("Database access failed: " . mysql_error());
$rows = mysql_num_rows($result);	

for ($k = 0; $k < $rows; ++$k)
{	
	$row = mysql_fetch_row($result);
	echo <<<_END
	<pre>
		Name $row[0]
		Age $row[1]
		Email $row[2]
	</pre>
	<form action="friends.php" method="post">
	<input type="hidden" name="delete" value="yes"/>
	<input type="hidden" name="name" value="$row[0]"/>
	<input type="submit" value="DELETE RECORD"/></form>
	_END;
}
mysql_close($db_server);
function get_post($var)
{
	return mysql_real_escape_string($_POST[$var]);
}
?>[/php]

If you’re going to use things like <<<END … END; You must make sure that the “END;” part isn’t indented at all.

Thanks! I took out the indents before the _END; and it works now :stuck_out_tongue:

Good to know! Glad to have helped.

Sponsor our Newsletter | Privacy Policy | Terms of Service