Greetings,
I have two tables named 'copyright' and 'logs'.
Table : copyright
Field : Copyr_md5
Table : logs
Field : md5checksum
Problem 1
Say i have a value stored in $md5check in php , now i want to check if the value stored in $md5check is found in field Copyr_md5.If found , then display a message

Problem 2
I want to check if $md5check is found in the field md5checksum.If yes then i want to retrieve the data of 3 fields(say field1,field2,field3) in the row where value in $md5check has been found.

I am a beginner in mysql and i am having trouble with these..
Thanks for helping me out

For the first problem:

<?php
$q = 'SELECT anything
    FROM copyright
    WHERE copyr_md5 = "' . mysql_real_escape_string($md5check) . '"
    LIMIT 1';
$rq = mysql_query($q);
$fetch = mysql_fetch_assoc($rq);

if($fetch)
{
    // A record that matches $md5check has been found.
}
?>

For the second problem:

<?php
$q = 'SELECT field1,
    field2,
    field3
    FROM table
    WHERE md5checksum = "' . mysql_real_escape_string($md5check) . '"
    LIMIT 1';
$rq = mysql_query($q);
$fetch = mysql_fetch_assoc($rq);

if($fetch)
{
    // A record that matches $md5check has been found.
    $field1 = $fetch['field1']; // etc.
}

Thanks dude i will try this out and let you know
why is mysql_real_escape_string necessary here...No value is being taken from users , so i suppose there is no risk of sql injection.
Thanks for all

$q = 'SELECT anything
    FROM copyright
    WHERE copyr_md5 = "' . mysql_real_escape_string($md5check) . '"
    LIMIT 1';

I am quite confused here
what is anything .
Is it the column name or data i need to find
The copyright table has only 1 column called copyr_md5 .All i want to do is to check whether the value stored in $md5hash in found in column copyr_md5(No need to retrieve data or anything else)

He probably used anything because he didn't know your columns. You can replace it with * to get all columns from the table. You query should be:

$query = "SELECT * FROM copyright WHERE copyr_md5 = '$md5check' LIMIT 1";

For more information on how to use mysql, read this.

Thank you for such an informative thread pritaeas
Question solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.