Hola tengo un error de sintaxis en un codigo fuente que me sirve para realizar una pagina donde realizar consultas en una base de datos, el caso es que no consigo arreglar el error, aqui os dejo el codigo a ver si me podeis exar una mano
El error es ste
Parse error: syntax error, unexpected '<' in C:\Apache\Apache2\htdocs\mysql_send.php on line 78
Y este el codigo de la pagina a realizar
<!-- Program: mysql_send.php
Desc: PHP program that sends an SQL query to the
MySQL server and displays the results.
-->
<html>
<head>
<title>SQL Query Sender</title>
</head>
<body>
<?php
$host="localhost";
$user="";
$password="";
/* Section that executes query */
if(@$_GET['form']=="yes")
{
mysql_connect($host,$user,$password);
mysql_select_db($_POST['database']);
$query = stripSlashes($_POST['query']);
$result = mysql_query($query);
echo "Database Selected: <b>{$_POST['database']}</b><br>
Query: <b>$query</b><h3>Results</h3><hr>";
if($result == 0)
echo "<b>Error ".mysql_errno().": ".mysql_error().
"</b>";
elseif (@mysql_num_rows($result) == 0)
echo("<b>Query completed. No results returned.</b><br>");
else
{
echo "<table border='1'><thead><tr>";
for($i = 0;$i < mysql_num_fields($result);$i++)
{
echo "<th>".mysql_field_name($result.$i).
"</th>";
}
echo " </tr> </thead> <tbody";
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
echo "<tr>";
$row = mysql_fetch_row($result);
for($j = 0; $j < mysql_num_fields($result);$j++)
{
echo("<td>" . $row[$j] . "</td>");
}
echo "</tr>";
}
echo "</tbody>
</table>";
} //end else
echo "
<hr><br>
<form action=\"{$_SERVER['PHP_SELF']}\" method=\"POST">
<input type='hidden' name='query' value='$query'>
<input type='hidden' name='database' value={$POST['database']}>
<input type='submit' name=\"queryButton\" value=\"New Query\">
<input type='submit' name=\"queryButton\" value=\"Edit Query\">
</form>";
unset($form);
exit();
} // endif form=yes
/* Section that request user input of query */
@$query=stripSlashes($_POST['query']);
if (@$_POST['queryButton'] != "Edit Query")
{
$query = " ";
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>?form=yes" method="POST">
<table>
<tr>
<td align=right><b>Type in database name</b></td>
<td><input type="text" name="database" value=<?php echo @$_POST['database'] ?> ></td>
</tr>
<tr>
<td align="right" valign="top"><b>Type in SQL query</b></td>
<td><textarea name="query" cols="60" rows="10"><?php echo $query ?></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit Query"></td>
</tr>
</table>
</form>
</body>
</html>
Hola, aca no se cierra la etiqueta <tbody>:
echo " </tr> </thead> <tbody";
No creo que sea ese el error (aunque nunca se sabe)... pruebe y nos avisa ;D
línea 77
<form action=\"{$_SERVER['PHP_SELF']}\" method=\"POST">
por:
<form action=\"{$_SERVER['PHP_SELF']}\" method=\"POST\">
porque no usas comillas simples mejor?
echo '
<hr><br />
<form action="'$_SERVER['SCRIPT_URI'].'" method="post">
<input type="hidden" name="query" value="'.htmlspecialchars($query, ENT_QUOTES).'">
<input type="hidden" name="database" value="'.htmlspecialchars($_POST['database'], ENT_QUOTES).'">
<input type="submit" name="queryButton" value="New Query">
<input type="submit" name="queryButton" value="Edit Query">
</form>
';
Se ve que mezclas las comillas simples con las dobles, de seguro copiaste el codigo por ahi y lo comenzaste a editar.
Fijate en los valores de los inputs, los pasé por htmlspecialchars para evitar un xss o para que pueda procesar todo tipo de carácteres incluyendo los especiales, ahora solo cuidate de la inyección sql.
Fijate que también reemplazé php_self por script_uri para evitar el xss debido al index.php/xss aca/x.php
También reemplazé las comillas simples por dobles porque en el caso de que utilizes htmlentities no te va a escapar las comillas simples y te puede causar un xss igual.
Y ojo que en $POST['database'] si pretendias poner el post de la supervariable post no te va a funcionar porque post lleva un guion bajo $_POST tal como lo puse en el código.
También en ves de poner tantas arrobas puedes declarar un error_reporting(0); en la cabezera del script.
Saludos.