|
|
|
| Web Hosting Guide |
![]() ![]() |
Php/mysql Script, Some help please! |
Feb 7 2005, 06:50 AM
Post
#1
|
|
|
Newbie [ Level 2 ] Group: [HOSTED] Posts: 25 Joined: 5-September 04 From: MEXICO DF Member No.: 260 |
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 $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 |
|
|
|
Feb 7 2005, 07:56 AM
Post
#2
|
|
|
Making IT Happen Group: Members Posts: 678 Joined: 1-September 04 From: Auckland, New Zealand Member No.: 27 myCENTs:69.15 |
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 $code You 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 like echo '<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 |
|
|
|
Feb 7 2005, 08:46 AM
Post
#3
|
|
|
Making IT Happen Group: Members Posts: 678 Joined: 1-September 04 From: Auckland, New Zealand Member No.: 27 myCENTs:69.15 |
CODE $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&\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 // |
|
|
|
Feb 7 2005, 04:09 PM
Post
#4
|
|
|
Newbie [ Level 2 ] Group: [HOSTED] Posts: 25 Joined: 5-September 04 From: MEXICO DF Member No.: 260 |
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"); ??? 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 $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&\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 // greetings from México. |
|
|
|
Feb 7 2005, 09:29 PM
Post
#5
|
|
|
Advanced Member Group: Members Posts: 160 Joined: 27-October 04 Member No.: 1,260 |
you asked:---------------------
what's the difference in performance between header('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. |
|
|
|
Feb 11 2005, 11:03 AM
Post
#6
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 4 Joined: 11-February 05 Member No.: 2,603 |
o copied an used it and with me it wrosk perfect i don't understand what doens't work/.
|
|
|
|
Feb 11 2005, 10:54 PM
Post
#7
|
|
|
Making IT Happen Group: Members Posts: 678 Joined: 1-September 04 From: Auckland, New Zealand Member No.: 27 myCENTs:69.15 |
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.\n And 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 |
|
|
|
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
4 | HannahI | 136 | 1st March 2010 - 12:34 AM Last post by: magiccode9 |
|||
![]() |
2 | 8ennett | 149 | 25th February 2010 - 11:42 AM Last post by: 8ennett |
|||
![]() |
7 | Niru | 4,423 | 20th February 2010 - 07:04 AM Last post by: iG-suresh |
|||
![]() |
19 | Feelay | 9,095 | 18th February 2010 - 08:47 AM Last post by: iG-Tsholofelo |
|||
![]() |
7 | Jonnyabc | 170 | 17th February 2010 - 08:31 AM Last post by: mastercomputers |
|||
![]() |
3 | clovis | 1,447 | 15th February 2010 - 12:17 PM Last post by: iG-zet |
|||
![]() |
12 | Houdini | 2,649 | 14th February 2010 - 09:44 AM Last post by: mastercomputers |
|||
![]() |
7 | kenjvalip | 2,721 | 13th February 2010 - 02:28 PM Last post by: magiccode9 |
|||
![]() |
10 | nakulgupta | 2,888 | 12th February 2010 - 06:25 AM Last post by: iG-Nancy Johnson |
|||
![]() |
10 | Eggie | 8,366 | 10th February 2010 - 06:47 AM Last post by: iG- |
|||
![]() |
6 | Skepticus | 176 | 7th February 2010 - 02:16 AM Last post by: 8ennett |
|||
![]() |
0 | 8ennett | 60 | 30th January 2010 - 11:10 PM Last post by: 8ennett |
|||
![]() |
25 | JohnNitro | 15,330 | 26th January 2010 - 11:30 AM Last post by: iG-mdshare |
|||
![]() |
4 | Manu Dhanda | 1,182 | 6th January 2010 - 12:39 PM Last post by: iG-medhatalbashaa |
|||
![]() |
10 | jedipi | 6,128 | 27th December 2009 - 11:44 AM Last post by: iG-marc |
|||
|
Lo-Fi Version | Time is now: 14th March 2010 - 02:40 PM |
© 2010 AstaHost: Free Web Hosting & Technical Discussion, Free Web Hosting. a member of xisto.
Powered by Invision Board. Skin: IPB Forum Skins
Expand / Collapse Navigation



Feb 7 2005, 06:50 AM







