Foros del Web » Programando para Internet » PHP »

Parse error en PHP

Estas en el tema de Parse error en PHP en el foro de PHP en Foros del Web. Hola, soy nuevo me llamo Marcos Lobato. Yo no tengo casi idea de programación pero estoy haciendo un script de chat de PHP con un ...
  #1 (permalink)  
Antiguo 08/08/2008, 11:41
 
Fecha de Ingreso: agosto-2008
Mensajes: 4
Antigüedad: 15 años, 8 meses
Puntos: 0
Parse error en PHP

Hola, soy nuevo me llamo Marcos Lobato.
Yo no tengo casi idea de programación pero estoy haciendo un script de chat de PHP con un tutorial. El caso es un parse error que me sale y que no entiendo...

Os paso el error:
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/www/chatrs.awardspace.com/chat.php on line 75

Y la línea 75 del script es:
document.chatform.chat.value '<font color"'+document.chatform.col[document.chatform.col.selectedIndex].text+'">'+document.chatform.chat.value+'</font>';

Sin necesitais el script entero avisad y lo escribo.
Pregunté en yahoo respuestas y me dijeron que quitando las comillas y no se que no se cuanto y no me fue. Os daré más detalles cuando los pidais.

Gracias.
  #2 (permalink)  
Antiguo 08/08/2008, 12:47
Avatar de DooBie  
Fecha de Ingreso: septiembre-2004
Mensajes: 1.101
Antigüedad: 19 años, 7 meses
Puntos: 71
Respuesta: Parse error en PHP

esa linea es de javascript, no de php, si la tienes tal cual, es normal que te falle. pon mas trozo de codigo, para hecharle un vistacillo
  #3 (permalink)  
Antiguo 08/08/2008, 12:57
 
Fecha de Ingreso: junio-2008
Ubicación: Mexico, DF.
Mensajes: 51
Antigüedad: 15 años, 10 meses
Puntos: 2
Respuesta: Parse error en PHP

si, pon todo tu script que asi no hay mucho que ver..
aunque ese error siempre sale cuando te falta cerrar una llave o te falta un parentesis o algo asi...
  #4 (permalink)  
Antiguo 08/08/2008, 12:58
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: Parse error en PHP

Normalmente si te salen ese tipo de codigos, es que se te olvido cerrar una llave como dice lugaluf unas lineas mas arriba.
  #5 (permalink)  
Antiguo 08/08/2008, 13:29
 
Fecha de Ingreso: agosto-2008
Mensajes: 4
Antigüedad: 15 años, 8 meses
Puntos: 0
Respuesta: Parse error en PHP

OK. Os pongo el script entero:
function ShowLoginForm() {

?>

<b>Escribe tu Nick</b>

<form name="chat" method="post" action="chat.php" target="_top">

<input type="text" name="nick" size="20">

<input type="hidden" name="action" value="enter">

<input type="hidden" name="chat" value="<font color=FF0000><b>entró al chat</b></font>">

<input type="submit" name="Submit" value="Submit">

</form>

<?php



function Login() {

global $chat;

global $nick;



session_start();

session_register("nick", $nick);

?>

<frameset rows="563,62" cols="*">

<frame name="posts" src="chat.php?action=posts&nick=<?php echo $nick; ?>&chat=<?php echo $chat; ?>">

<frame name="form" src="chat.php?action=form&nick=<?php echo $nick; ?>">

</frameset>

<noframes>

<body>

<p>Este chat utiliza frames, pero tu navegador no los soporta.</p>

</body>

</noframes>

</frameset>

<?php

}

function doSubmit()

{

if(document.chatform.chat.value == '') {

alert ('Escribe algún texto, ¿no?');

document.chatform.chat.focus();

return false;

}

document.chatform.chat.value '<font color"'+document.chatform.col[document.chatform.col.selectedIndex].text+'">'+document.chatform.chat.value+'</font>';

document.chatform.submit();

document.chatform.chat.value = '';

document.chatform.chat.focus();

return true;

}

function GetInput() {

global $HTTP_SESSION_VARS;

global $chat;

global $nick;

?>



<form onSubmit="return doSubmit" name="chatform" method="post" action="chat.php" target="posts">

<input type="text" name="chat">

<input type="hidden" name="nick" value="<?php echo $nick; ?>">

<input type="button" onClick="doSubmit()" name="Submit" value="Say">

<select name="col">

<option>Negro</option>

<option>Rojo</option>

<option>Verde</option>

<option>Azul</option>

<option>Naranja</option>

</select>



<input type="button" name="DoFace1" value=" :) " onClick="sendFace(1)">

<input type="button" name="DoFace2" value=" :( " onClick="sendFace(2)">

<input type="button" name="DoFace3" value=" :D " onClick="sendFace(3)">

<input type="hidden" name="action" value="posts">

</form>

<script language="JavaScript">

function sendFace(faceNum)

{

switch(faceNum)

{

case 1:

document.chatform.chat.value = ':)';

break;

case 2:

document.chatform.chat.value = ':(';

break;

case 3:

document.chatform.chat.value = ':D';

break;

}



document.chatform.submit();

document.chatform.chat.value = '';

}

function doSubmit()

{

if(document.chatform.chat.value == '') {

alert('Escribe algún texto, ¿no?');

document.chatform.chat.focus();

return false;

}

document.chatform.chat.value = '<font color="'+document.chatform.col[document.chatform.col.selectedIndex].text+'">'+document.chatform.chat.value+'</font>';

document.chatform.submit();

document.chatform.chat.value = '';

document.chatform.chat.focus();

return true;

}

</script>

<?php

}

global $HTTP_SESSION_VARS;

global $chat;

global $nick;
print '<meta http-equiv="refresh" content="10;URL=chat.php?action=posts&nick=<?php echo $nick; ?>">';
$svrConn = mysql_connect("servidorbddementira.mentira.com", "usr", "pwd") or die("<b>Error:</b> No se puedo conectar a la base de datos.");

$dbConn = mysql_select_db("chatrs_chat", $svrConn) or die ("<b>Error:</b> No se puedo conectar a la base de datos.");

if(!empty($chat)) {

$strQuery = "insert into chatScript values(0, '$chat', '$nick')";

mysql_query($strQuery);

}
$strQuery = "select theText, theNick from chatScript order by pk_Id desc limit 20";

$chats = mysql_query($strQuery);
while($chatline = mysql_fetch_array($chats)) {

print "<b>" . $chatline["theNick"] . ":</b> " . swapFaces($chatline["theText"]) . "<br>";

}
$chatLine = str_replace(":)", "<img src='smile.gif'>", $chatLine);

$chatLine = str_replace(":(", "<img src='frown.gif'>", $chatLine);

$chatLine = str_replace(":D", "<img src='bigsmile.gif'>", $chatLine);

return $chatLine;

}

if (empty($action))

ShowLoginForm();

elseif ($action == "posts")

ShowAddPosts();

elseif ($action == "form")

GetInput();

elseif ($action == "enter")

Login();


Os cambio el usuario y la contraseña de mi base de datos y el host. jaja.
  #6 (permalink)  
Antiguo 08/08/2008, 14:20
Avatar de DooBie  
Fecha de Ingreso: septiembre-2004
Mensajes: 1.101
Antigüedad: 19 años, 7 meses
Puntos: 71
Respuesta: Parse error en PHP

Tienes EXCESIVOS errores, si has seguido algun tutorial, repasalo, yo he intentado arreglar el codigo, pero... lo ideal seria que revises el manual que has seguido, leete los comentarios.


Código PHP:
<?php
function ShowLoginForm() {
  
?>
  <b>Escribe tu Nick</b>
  <form name="chat" method="post" action="chat.php" target="_top">
  <input type="text" name="nick" size="20">
  <input type="hidden" name="action" value="enter">
  <input type="hidden" name="chat" value="<font color=FF0000><b>entró al chat</b></font>">
  <input type="submit" name="Submit" value="Submit">
  </form>
  <?php
// Falta (fin funcion ShowLoginForm())

function Login() {
  global 
$chat;
  global 
$nick;
  
session_start();
  
session_register("nick"$nick);
  
?>
  <frameset rows="563,62" cols="*">
  <frame name="posts" src="chat.php?action=posts&nick=<?php echo $nick?>&chat=<?php echo $chat?>">
  <frame name="form" src="chat.php?action=form&nick=<?php echo $nick?>">
  </frameset>
  <noframes>
  <body>
  <p>Este chat utiliza frames, pero tu navegador no los soporta.</p>
  </body>
  </noframes>
  </frameset>
  <?php
}

/* Esta funcion la pongo en un comentario, por que parece ser una funcion javascript, nose. De hecho, esta definida mas abajo como funcion para javascript...
function doSubmit(){
  if(document.chatform.chat.value == '') {
    alert ('Escribe algún texto, ¿no?');
    document.chatform.chat.focus();
    return false;
  }
  document.chatform.chat.value '<font color"'+document.chatform.col[document.chatform.col.selectedIndex].text+'">'+document.chatform.chat.value+'</font>';
  document.chatform.submit();
  document.chatform.chat.value = '';
  document.chatform.chat.focus();
  return true;
}
*/

function GetInput() {
  global 
$HTTP_SESSION_VARS;
  global 
$chat;
  global 
$nick;
?>
  <form onSubmit="return doSubmit" name="chatform" method="post" action="chat.php" target="posts">
  <input type="text" name="chat">
  <input type="hidden" name="nick" value="<?php echo $nick?>">
  <input type="button" onClick="doSubmit()" name="Submit" value="Say">
  <select name="col">
  <option>Negro</option>
  <option>Rojo</option>
  <option>Verde</option>
  <option>Azul</option>
  <option>Naranja</option>
  </select>
  <input type="button" name="DoFace1" value=" :) " onClick="sendFace(1)">
  <input type="button" name="DoFace2" value=" :( " onClick="sendFace(2)">
  <input type="button" name="DoFace3" value=" :D " onClick="sendFace(3)">
  <input type="hidden" name="action" value="posts">
  </form>
  <script language="JavaScript">
  function sendFace(faceNum)
  {
    switch(faceNum)
    {
      case 1:
        document.chatform.chat.value = ':)';
        break;
      case 2:
        document.chatform.chat.value = ':(';
        break;
      case 3:
        document.chatform.chat.value = ':D';
        break;
    }
    document.chatform.submit();
    document.chatform.chat.value = '';
  }
  function doSubmit()
    {
      if(document.chatform.chat.value == '') {
        alert('Escribe algún texto, ¿no?');
        document.chatform.chat.focus();
        return false;
      }
    document.chatform.chat.value = '<font color="'+document.chatform.col[document.chatform.col.selectedIndex].text+'">'+document.chatform.chat.value+'</font>';
    document.chatform.submit();
    document.chatform.chat.value = '';
    document.chatform.chat.focus();
    return true;
  }
  </script>
<?php
//} // Yo creo que esta llave, sobra, y cierra la funcion GetInput abajo, pero no estoy seguro

    
global $HTTP_SESSION_VARS;
    global 
$chat;
    global 
$nick;
    print 
'<meta http-equiv="refresh" content="10;URL=chat.php?action=posts&nick=<?php echo $nick; ?>">';
    
$svrConn mysql_connect("servidorbddementira.mentira.com""usr""pwd") or die("<b>Error:</b> No se puedo conectar a la base de datos.");
    
$dbConn mysql_select_db("chatrs_chat"$svrConn) or die ("<b>Error:</b> No se puedo conectar a la base de datos.");
    if(!empty(
$chat)) {
      
$strQuery "insert into chatScript values(0, '$chat', '$nick')";
      
mysql_query($strQuery);
    }
    
$strQuery "select theText, theNick from chatScript order by pk_Id desc limit 20";
    
$chats mysql_query($strQuery);
    while(
$chatline mysql_fetch_array($chats)) {
      print 
"<b>" $chatline["theNick"] . ":</b> " swapFaces($chatline["theText"]) . "<br>";
    }
    
$chatLine str_replace(":)""<img src='smile.gif'>"$chatLine);
    
$chatLine str_replace(":(""<img src='frown.gif'>"$chatLine);
    
$chatLine str_replace(":D""<img src='bigsmile.gif'>"$chatLine);
    return 
$chatLine;
  } 
// Cierra GetInput

  
if (empty($action)) ShowLoginForm();
  elseif (
$action == "posts"ShowAddPosts();
  elseif (
$action == "form"GetInput();
  elseif (
$action == "enter"Login();
?>
  #7 (permalink)  
Antiguo 08/08/2008, 15:34
 
Fecha de Ingreso: agosto-2008
Mensajes: 4
Antigüedad: 15 años, 8 meses
Puntos: 0
Respuesta: Parse error en PHP

Cita:
Iniciado por DooBie Ver Mensaje
Tienes EXCESIVOS errores, si has seguido algun tutorial, repasalo, yo he intentado arreglar el codigo, pero... lo ideal seria que revises el manual que has seguido, leete los comentarios.


Código PHP:
<?php
function ShowLoginForm() {
  
?>
  <b>Escribe tu Nick</b>
  <form name="chat" method="post" action="chat.php" target="_top">
  <input type="text" name="nick" size="20">
  <input type="hidden" name="action" value="enter">
  <input type="hidden" name="chat" value="<font color=FF0000><b>entró al chat</b></font>">
  <input type="submit" name="Submit" value="Submit">
  </form>
  <?php
// Falta (fin funcion ShowLoginForm())

function Login() {
  global 
$chat;
  global 
$nick;
  
session_start();
  
session_register("nick"$nick);
  
?>
  <frameset rows="563,62" cols="*">
  <frame name="posts" src="chat.php?action=posts&nick=<?php echo $nick?>&chat=<?php echo $chat?>">
  <frame name="form" src="chat.php?action=form&nick=<?php echo $nick?>">
  </frameset>
  <noframes>
  <body>
  <p>Este chat utiliza frames, pero tu navegador no los soporta.</p>
  </body>
  </noframes>
  </frameset>
  <?php
}

/* Esta funcion la pongo en un comentario, por que parece ser una funcion javascript, nose. De hecho, esta definida mas abajo como funcion para javascript...
function doSubmit(){
  if(document.chatform.chat.value == '') {
    alert ('Escribe algún texto, ¿no?');
    document.chatform.chat.focus();
    return false;
  }
  document.chatform.chat.value '<font color"'+document.chatform.col[document.chatform.col.selectedIndex].text+'">'+document.chatform.chat.value+'</font>';
  document.chatform.submit();
  document.chatform.chat.value = '';
  document.chatform.chat.focus();
  return true;
}
*/

function GetInput() {
  global 
$HTTP_SESSION_VARS;
  global 
$chat;
  global 
$nick;
?>
  <form onSubmit="return doSubmit" name="chatform" method="post" action="chat.php" target="posts">
  <input type="text" name="chat">
  <input type="hidden" name="nick" value="<?php echo $nick?>">
  <input type="button" onClick="doSubmit()" name="Submit" value="Say">
  <select name="col">
  <option>Negro</option>
  <option>Rojo</option>
  <option>Verde</option>
  <option>Azul</option>
  <option>Naranja</option>
  </select>
  <input type="button" name="DoFace1" value=" :) " onClick="sendFace(1)">
  <input type="button" name="DoFace2" value=" :( " onClick="sendFace(2)">
  <input type="button" name="DoFace3" value=" :D " onClick="sendFace(3)">
  <input type="hidden" name="action" value="posts">
  </form>
  <script language="JavaScript">
  function sendFace(faceNum)
  {
    switch(faceNum)
    {
      case 1:
        document.chatform.chat.value = ':)';
        break;
      case 2:
        document.chatform.chat.value = ':(';
        break;
      case 3:
        document.chatform.chat.value = ':D';
        break;
    }
    document.chatform.submit();
    document.chatform.chat.value = '';
  }
  function doSubmit()
    {
      if(document.chatform.chat.value == '') {
        alert('Escribe algún texto, ¿no?');
        document.chatform.chat.focus();
        return false;
      }
    document.chatform.chat.value = '<font color="'+document.chatform.col[document.chatform.col.selectedIndex].text+'">'+document.chatform.chat.value+'</font>';
    document.chatform.submit();
    document.chatform.chat.value = '';
    document.chatform.chat.focus();
    return true;
  }
  </script>
<?php
//} // Yo creo que esta llave, sobra, y cierra la funcion GetInput abajo, pero no estoy seguro

    
global $HTTP_SESSION_VARS;
    global 
$chat;
    global 
$nick;
    print 
'<meta http-equiv="refresh" content="10;URL=chat.php?action=posts&nick=<?php echo $nick; ?>">';
    
$svrConn mysql_connect("servidorbddementira.mentira.com""usr""pwd") or die("<b>Error:</b> No se puedo conectar a la base de datos.");
    
$dbConn mysql_select_db("chatrs_chat"$svrConn) or die ("<b>Error:</b> No se puedo conectar a la base de datos.");
    if(!empty(
$chat)) {
      
$strQuery "insert into chatScript values(0, '$chat', '$nick')";
      
mysql_query($strQuery);
    }
    
$strQuery "select theText, theNick from chatScript order by pk_Id desc limit 20";
    
$chats mysql_query($strQuery);
    while(
$chatline mysql_fetch_array($chats)) {
      print 
"<b>" $chatline["theNick"] . ":</b> " swapFaces($chatline["theText"]) . "<br>";
    }
    
$chatLine str_replace(":)""<img src='smile.gif'>"$chatLine);
    
$chatLine str_replace(":(""<img src='frown.gif'>"$chatLine);
    
$chatLine str_replace(":D""<img src='bigsmile.gif'>"$chatLine);
    return 
$chatLine;
  } 
// Cierra GetInput

  
if (empty($action)) ShowLoginForm();
  elseif (
$action == "posts"ShowAddPosts();
  elseif (
$action == "form"GetInput();
  elseif (
$action == "enter"Login();
?>
¿Todo lo de rojo es error? Bueno soy un newbie en php jaja.

Os copio el script tal como esta en la web:

function ShowLoginForm() {

Código PHP:
?>

<b>Enter Your NickName</b>

<form name="chat" method="post" action="chat.php" target="_top">

<input type="text" name="nick" size="20">

<input type="hidden" name="action" value="enter">

<input type="hidden" name="chat" value="<font color=FF0000><b>Enters the Room</b></font>">

<input type="submit" name="Submit" value="Submit">

</form>

<?php


function 
Login() {

global 
$chat;

global 
$nick;



session_start();

session_register("nick"$nick); 

?>

<frameset rows="563,62" cols="*"> 

<frame name="posts" src="chat.php?action=posts&nick=<?php echo $nick?>&chat=<?php echo $chat?>">

<frame name="form" src="chat.php?action=form&nick=<?php echo $nick?>">

</frameset>

<noframes>

<body>

<p>This page uses frames, but your browser doesn't support them.</p>

</body>

</noframes>

</frameset>

<?php

}
function 
doSubmit()

{

if(
document.chatform.chat.value == '') {

alert('Please enter some text!');

document.chatform.chat.focus();

return 
false;

}

document.chatform.chat.value '<font color="'+document.chatform.col[document.chatform.col.selectedIndex].text+'">'+document.chatform.chat.value+'</font>';

document.chatform.submit();

document.chatform.chat.value '';

document.chatform.chat.focus();

return 
true;

}
function 
GetInput() {

global 
$HTTP_SESSION_VARS;

global 
$chat;

global 
$nick;

?>



<form onSubmit="return doSubmit" name="chatform" method="post" action="chat.php" target="posts">

<input type="text" name="chat">

<input type="hidden" name="nick" value="<?php echo $nick?>">

<input type="button" onClick="doSubmit()" name="Submit" value="Say">

<select name="col">

<option>Black</option>

<option>Red</option>

<option>Green</option>

<option>Blue</option>

<option>Orange</option>

</select>



<input type="button" name="DoFace1" value=" :) " onClick="sendFace(1)">

<input type="button" name="DoFace2" value=" :( " onClick="sendFace(2)">

<input type="button" name="DoFace3" value=" :D " onClick="sendFace(3)">

<input type="hidden" name="action" value="posts">

</form>

<script language="JavaScript">

function sendFace(faceNum)

{

switch(faceNum)

{

case 1:

document.chatform.chat.value = ':)';

break;

case 2:

document.chatform.chat.value = ':(';

break;

case 3:

document.chatform.chat.value = ':D';

break;

}



document.chatform.submit();

document.chatform.chat.value = '';

}

function doSubmit()

{

if(document.chatform.chat.value == '') {

alert('Please enter some text!');

document.chatform.chat.focus();

return false;

}

document.chatform.chat.value = '<font color="'+document.chatform.col[document.chatform.col.selectedIndex].text+'">'+document.chatform.chat.value+'</font>';

document.chatform.submit();

document.chatform.chat.value = '';

document.chatform.chat.focus();

return true;

}

</script>

<?php

}

global 
$HTTP_SESSION_VARS;

global 
$chat;

global 
$nick;
print 
'<meta http-equiv="refresh" content="10;URL=chat.php?action=posts&nick=<?php echo $nick; ?>">';
svrConn mysql_connect("localhost""admin""password") or die("<b>Error:</b> Couldnt connect to database");

$dbConn mysql_select_db("chat"$svrConn) or die ("<b>Error:</b> Couldnt connect to database");
if(!empty(
$chat)) {

$strQuery "insert into chatScript values(0, '$chat', '$nick')";

mysql_query($strQuery);

}
$strQuery "select theText, theNick from chatScript order by pk_Id desc limit 20";

$chats mysql_query($strQuery);

while(
$chatline mysql_fetch_array($chats)) {

print 
"<b>" $chatline["theNick"] . ":</b> " swapFaces($chatline["theText"]) . "<br>";

}
function 
swapFaces($chatLine) {

$chatLine str_replace(":)""<img src='smile.gif'>"$chatLine);

$chatLine str_replace(":(""<img src='frown.gif'>"$chatLine);

$chatLine str_replace(":D""<img src='bigsmile.gif'>"$chatLine);

return 
$chatLine;

}
if (empty(
$action))

ShowLoginForm();

elseif (
$action == "posts")

ShowAddPosts();

elseif (
$action == "form")

GetInput();

elseif (
$action == "enter")

Login();
Solo he hecho los cambios de mi base de datos mysql y traducir al español. ¡¡Es lo mismo!!
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:25.