Jump to content
xisto Community
Sign in to follow this  
panquetofobia

Php/mysql Script Some help please

Recommended Posts

hello guys.

the problem with this script is that the insert query dosen't function properly as it depends on the result of a count(*) query. ;)
the update query works fine....

here's some code:

$code=md5($codea);if(@$codigo!=$code)// no autenticado - not authenticated{	header ("Location: main.php");}elseif($deporte=="" || $rama=="" || $enc_reg=="" || $centro_trabajo==""){	header ("Location: reg1.php?codigo=$code&enc_reg=$enc_reg");}else //todo bien - everything is ok{// PRINCIPAL - MAIN //	echo "<link href=\"./css/base.css\" rel=\"stylesheet\" type=\"text/css\" />";	echo "<body style=\"background-image:url(./imgs/regbg.gif)\x3b background-repeat: no-repeat\x3b background-position: top right\x3b background-attachment:fixed\x3b \">";	echo "<p><img src=\"./imgs/paso3.gif\" border=\"0\" alt=\"\"></p>";	echo "<p>Gracias por identificarse <b>$enc_reg</b></p><p>Registro de Jugadores de $deporte $rama para el Centro de Trabajo $centro_trabajo </p>";	$fecha=date("Y-m-d");	$sqlcheck="SELECT integrantes_restantes FROM equipos WHERE Centro_de_Trabajo='$centro_trabajo' and Deporte='$deporte'"; 	$querycheck=mysql_query($sqlcheck);	$A=mysql_fetch_object($querycheck);	@$merror.="Hasta $A->integrantes_restantes jugadores por registrar.";	if (@$ddok)//enviado - submitted	{    if(@$ape1=="" || $ape2=="" || $nombre=="" || $no_ficha=="" || @$sit_cont=="" || @$sub_sit_cont=="" || $anios=="" || $talla=="")   { 	 @$merror.="<p style=\"color:#990000\x3b font-weight:bold\">Por Favor Llene el Formulario completamente.</p>";   }  else //lleno - filled  {   	 //sql ya registrado Ăł sancionado?? - sql registered or punished ?? 	 $sqlcheck="SELECT COUNT(*) FROM sancionados,participantes WHERE sancionados.No_Ficha='$no_ficha' AND participantes.No_Ficha='$no_ficha'";  	 $querycheck=mysql_query($sqlcheck) || die(mysql_error()); 	 if($A->integrantes_restantes==0)//no hay lugares libres? - no positions left? 	 {    @$merror.="<p style=\"color:#990000\x3b  font-weight:bold\">CENTRO DE TRABAJO COMPLETO. NO HAY REGISTROS DISPONIBLES. <img src=\"./imgs/error.gif\" alt=\"\"></p>";    echo "<meta http-equiv=\"refresh\" content=\"3\x3burl=index.php\">"; 	 } 	 elseif(@mysql_result($querycheck,0,0)>0) //ya registrado Ăł sancionado?? - registered or punished ?? 	 {	    $merror.="<p style=\"color:#990000\x3b  font-weight:bold\">JUGADOR SANCIONADO, IMPOSIBLE REGISTRAR. <img src=\"./imgs/error.gif\" alt=\"\"></p>";  	 } 	 else //no registrado ni sancionado. hay cupo. - neither registered nor punished. positions availables 	 {    $situacionc="$sit_cont $sub_sit_cont";    $sql="INSERT INTO participantes VALUES ( 0 , '$nombre','$ape1','$ape2','$no_ficha','$situacionc','$talla','$anios','$deporte','$rama','$centro_trabajo','$enc_reg','$fecha')";    $query=mysql_query($sql) || die(mysql_error()); // registro de jugador - storing player info    $sql="UPDATE equipos SET integrantes_restantes=(integrantes_restantes - 1) where Centro_de_Trabajo='$centro_trabajo' and Deporte='$deporte'";     $query=mysql_query($sql) || die(mysql_error()); // una posiciĂłn menos - minus one position    @$merror.="<p>Jugador $nombre $ape1 $ape2 <strong>Registrado</strong>  <img src=\"./imgs/oki.gif\" alt=\"\"></p>"; 	 }  }	}form_jugadores(@$desp,$code,@$enc_reg,@$merror,@$deporte,@$rama,@$centro_trabajo);}// FIN PRINCIPAL - END MAIN //



thank u very much for your help ;)

Share this post


Link to post
Share on other sites

It sure seems to be getting more problems,first line maybe incorrect, I don't see $codea declared anywhere, so it's probably meant to be $codeYou really need to learn when to use single quoted items compared to double quoted items just for performance sake.header('Location: main.php'); performs better than header("Location: main.php");again with setting variables to empty strings or doing comparisons use $deporte = '' although you may want to check the empty() function for these.Things likeecho '<link href="./css/base.css" rel="stylesheet" type="text/html" />'; is easier to do is it not? There's no need to escape any double quotes.I think instead of me going over this code, I'll copy it and rewrite it how I would as it's just too much to read in.Cheers,MC

Share this post


Link to post
Share on other sites
$code = md5($code); // IS THIS CORRECT?if(@$codigo != $code)	header('Location: main.php');elseif($deporte . $rama . $enc_reg . $centro_trabajo == '')	header("Location: reg1.php?codigo=$code&amp\x3benc_reg=$enc_reg");else{	//PRINCIPAL - MAIN?><link href="/css/base.css" rel="stylesheet" type="text/css" /><body style="background: url(/img/regbg.gif) no-repeat fixed top right;"><p><img src="./imgs/paso3.gif" border="0" alt=""></p><p>Gracias por identificarse <strong><?php echo $enc_reg; ?></strong></p><p>Registro de Jugadores de <?php echo $deporte . ' ' . $rame; ?> para el Centro de Trabajo <?php echo $centro_trabajo; ?></p><?php }$fecha = date('Y-m-d');$sqlcheck = "SELECT integrantes_restantes FROM equipos WHERE Centro_de_Trabajo = '$centro_trabajo' AND Deporte = '$deporte'";$querycheck = mysql_query($sqlcheck) or die(mysql_error());$A = mysql_fetch_object($querycheck);@$merror .= "Hasta $A -> integrantes_restantes jugadores por registrar.";if(@$ddok) // enviado - submitted{	if(@$ape1 . $ape2 . $nombre . $no_ficha . @$sit_cont . @$sub_sit_cont . $anios . $talla == '')  @$merror .= '<p style="color: #990000' . "\x3b" . ' font-weight: bold' . "\x3b" . '">Por Favor Llene el Formulario completamente.</p>';	else // lleno - filled	{  // sql ya registrado ó sancionado?? - sql registered or punished??  $sqlcheck = "SELECT COUNT(*) FROM sancionados, participantes WHERE sancionados.No_Ficha = '$no_ficha' AND participantes.No_Ficha = '$no_ficha'";  $querycheck = mysql_query($sqlcheck) or die(mysql_error());  // IS THERE SUPPOSE TO BE $A = mysql_fetch_object($querycheck); HERE?  if($A -> integrantes_restantes == 0) // no hay lugares libres? - no positions left?  { 	 @$merror .= '<p style="color: #990000' . "\x3b" . 'font-weight: bold' . "x3b" . '">JUGADOR SANCIONADO, IMPOSIBLE REGISTRAR. <img src="/imgs/error.gif" alt=""></p>'; 	 echo '<meta http-equiv="refresh" content="3' . "\x3b" . 'url=index.php" />';  }  else // no registrado ni sancionado. hay cupo. - neither registered nor punished. positions availables  { 	 $situancionc = $sit_cont . ' ' . $sub_sit_cont; 	 $sql = "INSERT INTO participantes VALUES (0, '$nombre', '$ape1', '$ape2', '$no_ficha', '$situancionc', '$talla', '$anios', '$deporte', '$rama', '$centro_trabajo', '$enc_reg', '$fecha')"; 	 $query = mysql_query($sql) or die(mysql_error()); // registro de jugador - storing player info 	 $sql = "UPDATE equipos SET integrantes_restantest = (integrantes_restantest - 1) WHERE Centro_de_Trabajo = '$centro_trabajo' AND Deporte = '$deporte'"; 	 $query = mysql_query($sql) or die(mysql_error()); 	 @$merror .= '<p>Jugador ' . $nombre . ' ' . $ape1 . ' ' . $ape2 . ' <strong>Registrado</strong> <img src="/imgs/oki.gif" alt=""></p>';  }	}}form_jugadores(@$desp, $code, @$enc_reg, @$merror, @$deporte, @$rama, @$centro_trabajo);} // WHAT IS THIS CLOSING?// FIN PRINCIPAL - END MAIN //

Share this post


Link to post
Share on other sites

the problem is with the count(*) query.

 

everything else works fine.

 

@MC

 

what's the difference in performance between

 

header('Location: main.php'); and header("Location: main.php"); ??? :P

 

i know there r some easy ways... but i learned php using google. ;)

it doesn't

please read my comments below. hope u'll find out the solution ;) ..

 

 

$code = md5($code); // IS THIS CORRECT?-> yes it is. no problem with this line.if(@$codigo != $code)	header('Location: main.php');elseif($deporte . $rama . $enc_reg . $centro_trabajo == '')	header("Location: reg1.php?codigo=$code&amp\x3benc_reg=$enc_reg");else{	//PRINCIPAL - MAIN?><link href="/css/base.css" rel="stylesheet" type="text/css" /><body style="background: url(/img/regbg.gif) no-repeat fixed top right;"><p><img src="./imgs/paso3.gif" border="0" alt=""></p><p>Gracias por identificarse <strong><?php echo $enc_reg; ?></strong></p><p>Registro de Jugadores de <?php echo $deporte . ' ' . $rame; ?> para el Centro de Trabajo <?php echo $centro_trabajo; ?></p><?php }$fecha = date('Y-m-d');$sqlcheck = "SELECT integrantes_restantes FROM equipos WHERE Centro_de_Trabajo = '$centro_trabajo' AND Deporte = '$deporte'";$querycheck = mysql_query($sqlcheck) or die(mysql_error());$A = mysql_fetch_object($querycheck);@$merror .= "Hasta $A -> integrantes_restantes jugadores por registrar.";if(@$ddok) // enviado - submitted{	if(@$ape1 . $ape2 . $nombre . $no_ficha . @$sit_cont . @$sub_sit_cont . $anios . $talla == '')  @$merror .= '<p style="color: #990000' . "\x3b" . ' font-weight: bold' . "\x3b" . '">Por Favor Llene el Formulario completamente.</p>';	else // lleno - filled	{  // sql ya registrado ó sancionado?? - sql registered or punished??  $sqlcheck = "SELECT COUNT(*) FROM sancionados, participantes WHERE sancionados.No_Ficha = '$no_ficha' AND participantes.No_Ficha = '$no_ficha'"; // here's the problem.   $querycheck = mysql_query($sqlcheck) or die(mysql_error());  // IS THERE SUPPOSE TO BE $A = mysql_fetch_object($querycheck); HERE? -> no, i take the object from the first mysql_fetch object. works fine. no problem here.  if($A -> integrantes_restantes == 0) // no hay lugares libres? - no positions left?  {  	@$merror .= '<p style="color: #990000' . "\x3b" . 'font-weight: bold' . "x3b" . '">JUGADOR SANCIONADO, IMPOSIBLE REGISTRAR. <img src="/imgs/error.gif" alt=""></p>';  	echo '<meta http-equiv="refresh" content="3' . "\x3b" . 'url=index.php" />';  }  else // no registrado ni sancionado. hay cupo. - neither registered nor punished. positions availables  {  	$situancionc = $sit_cont . ' ' . $sub_sit_cont;  	$sql = "INSERT INTO participantes VALUES (0, '$nombre', '$ape1', '$ape2', '$no_ficha', '$situancionc', '$talla', '$anios', '$deporte', '$rama', '$centro_trabajo', '$enc_reg', '$fecha')"; this query works, but its function depends on the count(*) query above.....  	$query = mysql_query($sql) or die(mysql_error()); // registro de jugador - storing player info  	$sql = "UPDATE equipos SET integrantes_restantest = (integrantes_restantest - 1) WHERE Centro_de_Trabajo = '$centro_trabajo' AND Deporte = '$deporte'"; //works fine.  	$query = mysql_query($sql) or die(mysql_error());  	@$merror .= '<p>Jugador ' . $nombre . ' ' . $ape1 . ' ' . $ape2 . ' <strong>Registrado</strong> <img src="/imgs/oki.gif" alt=""></p>';  }	}}form_jugadores(@$desp, $code, @$enc_reg, @$merror, @$deporte, @$rama, @$centro_trabajo);} // WHAT IS THIS CLOSING?- the end of the firt 'else'// FIN PRINCIPAL - END MAIN //

<{POST_SNAPBACK}>


greetings from MĂŠxico.

Share this post


Link to post
Share on other sites

you asked:---------------------what's the difference in performance betweenheader('Location: main.php'); and header("Location: main.php"); ??? ----------------------------------Answer: No difference, they work as well.As for your "Count(*)" problem, i will get back to you later.

Share this post


Link to post
Share on other sites

There is a performance difference indeed, hardly noticable on such a small scaled script, but when you get into large scaled projects, you're bound to find better performing ways for your server.doube quotes tells the PHP interpreter that it may have to interpolate, so it checks everything within the double quotes looking for things it can interpolate, like variables and escaped characters. e.g. $string = "This $variable will be interpolated, as well as this newline character.\n";$variable will be replaced by whatever is contained within it's elements and \n will be replaced with a newline.single quotes are shown as is, no interpolation at all. e.g. $string = 'This $variable will not be interpolated, nor would this newline character.\n';If you echoed this single quoted string out, all you should see is:This $variable will not be interpolated, nor would this newline character.\nAnd that's it, displayed as is, without checking the innards of the variables or newline character.So the main difference is that double quotes requires the interpreter to thoroughly check within the string, looking for certain things it can change.Maybe if you test it out for yourself?<?php$variable = 'VaRiAbLe';$string1 = "This $variable.\nAnd Newline"; // check HTML source to see the newline.$string2 = 'This $variable.\nAnd Newline';$string3 = 'This ' . $variable . '.' . "\n" . 'And Newline';$string4 = 'This ' . $variable . '.\nAnd Newline';echo 'String 1: ' . $string1 . '<br /> ';echo 'String 2: ' . $string2 . '<br />';echo 'String 3: ' . $string3 . '<br />';echo 'String 4: ' . $string4 . '<br />';?>Hopefully you'll understand the results, in testing these out. Just remember, if an item needs interpolation, it might be easier to do the whole string in double quotes like String 1 or just do parts of it like in String 3. String 2 and String 4 would not be your desired results.Cheers,MC

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.