0

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

3
Contributors
5
Replies
6
Views
4 Years
Discussion Span
Last Post by Khav
0

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.
}
0

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

0
$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)

0

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.

Edited by pritaeas

0

Thank you for such an informative thread pritaeas
Question solved

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.