0

what i am trying to do is permit the user to claim or reserve a spot with coord
my table has 4 feilds id ,continent,coord,nom id is primary key

what i am trying to do first i check if the coord already exist if they dont i update the database
id they do i want to echo whats in the feild nom for that particular entry

here is the code

  { 
    $db = mysql_connect('localhost', 'xxxxx', 'xxxxxx');  // connect to DB 
    mysql_select_db('xxxxx',$db);                  // select db

    // check if coord already exist
    $sql = "SELECT id FROM test WHERE coord='$coord'"; 
    $req = mysql_query($sql) or die('Erreur SQL !'.$sql.'<br>'.mysql_error());  

    // compting the results 
    $res = mysql_num_rows($req); 

    if($res!=0)  // if coord already exist display the content of the feild nom for that entry 
        { 
 $sql = "SELECT 'nom' FROM test WHERE coord='$coord'"; 
    $req = mysql_query($sql) or die('Erreur SQL !'.$sql.'<br>'.mysql_error()); 
echo $req;

        } 
    else  // if coord dont exist make new data base entry
        {    
        $sql = "INSERT INTO test(id, nom, continent,coord) VALUES('','$nom','$continent','$coord')"; 
        mysql_query($sql) or die('Erreur SQL !'.$sql.'<br>'.mysql_error());  

        // display msg to user
        echo 'GRATS  You Just Claimed IT.'; 

        } 
    mysql_close();  // close connection
    }

this is working well when i just echo a sorry msg
i know the problem is in the folowing 3 lines

          $sql = "SELECT 'nom' FROM test WHERE coord='$coord'"; 
        $req = mysql_query($sql) or die('Erreur SQL !'.$sql.'<br>'.mysql_error()); 
    echo $req;

ty

Edited by jethaya

3
Contributors
3
Replies
19
Views
4 Years
Discussion Span
Last Post by jethaya
0
      $sql = "SELECT 'nom' FROM test WHERE coord='$coord'"; 
    $req = mysql_query($sql) or die('Erreur SQL !'.$sql.'<br>'.mysql_error()); 
    $row=mysql_fetch_assoc($req);
echo $row['nom'];

Edited by urtrivedi

This topic has been dead for over six months. 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.