Edward Posted April 5, 2007 Share Posted April 5, 2007 Hi, I'm trying to set up a connection to my database and insert some information while using mysql_real_escape_string. This is the demo I've seen: $link = mysql_connect('localhost', 'root', 'root'); $sql = sprintf("INSERT INTO board ('id', 'name', 'password') VALUES ('%d', '%s', '%s', '%s') LIMIT 1", $id, $name, mysql_real_escape_string($description), mysql_real_escape_string($message)); if ($result = mysql_query($sql, $link)) { echo 'ok'; } However, I already have a function I want to use to connect, so once conntected, can I just do this?: $sql = sprintf("INSERT INTO board ('id', 'name', 'password') VALUES ('%d', '%s', '%s', '%s') LIMIT 1", $id, $name, mysql_real_escape_string($description), mysql_real_escape_string($message)); if ($result = mysql_query($sql)) { echo 'ok'; } Link to comment https://forums.phpfreaks.com/topic/45779-mysql_real_escape_string-and-database-selectionconnection/ Share on other sites More sharing options...
Edward Posted April 5, 2007 Author Share Posted April 5, 2007 Another reason I want to do this is because I don't see how you select your database in the first example? That aside I would still prefer to use my own connect function if it's possible and appropriate. Link to comment https://forums.phpfreaks.com/topic/45779-mysql_real_escape_string-and-database-selectionconnection/#findComment-222408 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.