Using PHP variables wherever you want inside SQL queries : mysql_query « MySQL Database « PHP






Using PHP variables wherever you want inside SQL queries

 
function simplequery($table, $field, $needle, $haystack) {
            $result = mysql_query("SELECT $field FROM $table WHERE
                     $haystack = $needle LIMIT 1;");

            if ($result) {
                    if (mysql_num_rows($result)) {
                            $row = mysql_fetch_assoc($result);
                            return $row[$field];
                    }
            } else {
                    print "Error in query<br />";
            }
    }
    $firstname = simplequery("usertable", "firstname", "ID", $UserID);
  
  








Related examples in the same category

1.Add record to my_database/my_table
2.Adding a Row to a Table
3.Deleting Data
4.Get data from mysql
5.mysql_query.php
6.function mysql_query() queries the database.
7.Storing Information in a Database
8.Sign the guestbook