Jump to content
xisto Community
Sign in to follow this  
panquetofobia

MySQL Query some help needed

Recommended Posts

i dunno why this query doesn't function..

$sql="SELECT count(*) FROM participantes,sancionados WHERE participantes.No_Ficha = '$no_ficha' or sancionados.No_Ficha='$no_ficha'";$query=($sql);


any suggestion???

Share this post


Link to post
Share on other sites

Try this:-

$sql="SELECT count(*) FROM `participantes`, `sancionados` WHERE `participantes`.`No_Ficha` = '".$no_ficha."' AND `sancionados`.`No_Ficha`='".$no_ficha."'";$query=$sql;

or this:-

$sql="SELECT count(*) FROM `participantes` WHERE `No_Ficha` = '".$no_ficha."'";$query=$sql;

if it still doesn't not work, i will have to get back to you later today or tomorrow.

Share this post


Link to post
Share on other sites

Maybe you're not doing the query, you're just setting $query to $sql, you have to use $query = mysql_query($sql) or die("Maybe you were right?");Other than this, I can't see a problem.MC

Share this post


Link to post
Share on other sites

$sql="SELECT count(*) FROM participantes,sancionados WHERE participantes.No_Ficha = '$no_ficha' or sancionados.No_Ficha='$no_ficha'";

$query=($sql);

See from your query, I figure you are trying to match up the contents of the variable $no_ficha with the table columns participantes.No_Ficha and sancionados.No_Ficha. the query is perfectly fine and wouldn't even need the open-close quotes (``) around the table/column names as shown here.

`participantes`, `sancionados` WHERE `participantes`.`No_Ficha` = '".$no_ficha."' AND `sancionados`.`No_Ficha`='".$no_ficha."'";

My guess is where you are going wrong is the open-close quotes ('') around the $no_ficha.... if you want to match the contents of $no_ficha with your table columns, then you have to enclose $no_ficha in double quotes ("$no_ficha") for PHP to be able to parse it as a variable and extract and use its value. Between single quotes, $no_ficha is treated as a string and you query is trying to find a string called $no_ficha in your tables... Try with double quotes and see....

 

I think breaking up the query like this would help:

$sql="SELECT count(*) FROM participantes,sancionados WHERE participantes.No_Ficha =" . "$no_ficha" . "or sancionados.No_Ficha = " . "$no_ficha";

...

...

And next check your syntax and add what mastercomputers wrote...

Maybe you're not doing the query, you're just setting $query to $sql, you have to use $query = mysql_query($sql) or die("Maybe you were right?");

- coz it seems from your syntax that you aren't doing to query at all...

Share this post


Link to post
Share on other sites

I see where you're coming from microscopic^earthling and I did too pick this up.The only thing if I can explain it to you is that the single quotes are inside double quotes, meaning they play no importance other than being single quotes in a double quoted string. Because the double quoted string is used and there's no closing prior the single quotes, the variables will be processed by PHP as variables inside that double quoted string and not as if they were singluarly quoted.e.g $double_quoted = " '$hello' "; produces 'the_element_contained_in_hello' with the quotes. If it were only $single_quoted = ' "$hello" '; produces only "$hello", with the double quotes around it and not what's contained in the variable $hello.You need to use those quotes in those statements though, so never leave them off.MC

Share this post


Link to post
Share on other sites

// Added Aliases just to avoid those big lengthy names

$sql="SELECT count(*)FROM participantes AS a, sancionados AS bWHERE a.No_Ficha = '$no_ficha'OR b.No_Ficha='$no_ficha';";$sql_result = mysql_query($sql,$connection) || die(mysql_error());
Check the Following,
The Column names are Case-sensitive and they are properly written.
If the things still dont work, Would you please put down the error statement reported by the "mysql_error()" function.

-OpaQue

Share this post


Link to post
Share on other sites

a part of my code...

$sqlcheck="SELECT count(*) FROM participantes AS a, sancionados AS b WHERE a.No_Ficha = '$no_ficha' OR b.No_Ficha='$no_ficha';"; 	 $querycheck=mysql_query($sqlcheck) || die(mysql_error());; if(@mysql_result($querycheck,0,0)>0)    {   	 $merror.="<p style=\"color:#990000; font-weight:bold\">JUGADOR YA REGISTRADO Ó SANCIONADO <img src=\"./imgs/error.gif\" alt=\"\"></p>";     }    else    {	$sql="UPDATE equipos SET integrantes_restantes='$integrantesr' where Centro_de_Trabajo='$centro_trabajo' and Deporte='$deporte'";$query=mysql_query($sql);    $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);    @$merror.="<p>Jugador ".$nombre." ".$ape1." ".$ape2." <strong>Registrado</strong>  <img src=\"./imgs/oki.gif\" alt=\"\"></p>";    }  


the insert query doesn't function either :) ...

thank u guys ...


greetings from MĂŠxico City

Share this post


Link to post
Share on other sites

a part of my code...

 

$sqlcheck="SELECT count(*) FROM participantes AS a, sancionados AS b WHERE a.No_Ficha = '$no_ficha' OR b.No_Ficha='$no_ficha';"; [tab][/tab] $querycheck=mysql_query($sqlcheck) || die(mysql_error());; if(@mysql_result($querycheck,0,0)>0)    {   [tab][/tab] $merror.="<p style=\"color:#990000; font-weight:bold\">JUGADOR YA REGISTRADO Ó SANCIONADO <img src=\"./imgs/error.gif\" alt=\"\"></p>";     }    else    {[tab][/tab]$sql="UPDATE equipos SET integrantes_restantes='$integrantesr' where Centro_de_Trabajo='$centro_trabajo' and Deporte='$deporte'";$query=mysql_query($sql);    $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);    @$merror.="<p>Jugador ".$nombre." ".$ape1." ".$ape2." <strong>Registrado</strong>  <img src=\"./imgs/oki.gif\" alt=\"\"></p>";    }  
the insert query doesn't function either  ;) ...

 

thank u guys ...

greetings from MĂŠxico City

<{POST_SNAPBACK}>


OK for this there's 2 semi-colons in the $sqlcheck line, one that appears before the double quotes is wrong.

 

$querycheck has 2 as well although this wouldn't have any problems, but it's still incorrect to have that.

 

color:#990000; and Ó can't have this semi-colon here, use color:#990000\x3b Ó\x3b

\x3b is the hex value for semi-colon, PHP will understand this.

 

Give your images an alt description just for w3c standards, empty alt tags are incorrect, although not a problem with the execution of these statements.

 

This line

 

@$merror.="<p>Jugador ".$nombre." ".$ape1." ".$ape2." <strong>Registrado</strong>  <img src=\"./imgs/oki.gif\" alt=\"\"></p>";

Can be written as

 

@$merror .= "<p>Jugador $nombre $ape1 $ape2 <strong>Registrado</strong> <img src=\"./imgs/oki.gif\" alt=\"\"></p>";

Well update the problems and post back whether it works or not.

 

 

Cheers,

 

 

MC

Share this post


Link to post
Share on other sites
$sql="INSERT INTO `tablename` (`colname1`, `colname2`) VALUES ('value1', 'value2')";

If you follow the above format, the insert query should work fine.
You may have to define the columns name and data parallel to each other.

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.