phpfreakjav Posted July 24, 2009 Share Posted July 24, 2009 Notice in the mysql query it says, values, how to I insert variables here. <?php // Get the PHP file containing the DbConnector class require_once('DbConnector.php'); // Create an instance of DbConnector $connector = new DbConnector(); // Use the query function of DbConnector to run a database query // (The arrow -> is used to access a function of an object) in other words to grab the variables in the Methods //$result = $connector->query('SELECT x FROM coordinates where x >0');//MySQL query goes here $result = $connector->query('INSERT INTO coordinates (x,y,t) VALUES(1,2,3)'); //coordinates is the table name, xyt are the //columns, and values are the values recorded by the mouse //script. // Get the result $row = $connector->fetchArray($result); ?> Quote Link to comment https://forums.phpfreaks.com/topic/167322-inserting-a-php-variable-into-mysql-inserto-into-command/ Share on other sites More sharing options...
Maq Posted July 24, 2009 Share Posted July 24, 2009 Use double quotes around the query string or else you will have to escape the single quotes around the vars. VALUES('$var1', '$var2', '$var3') Quote Link to comment https://forums.phpfreaks.com/topic/167322-inserting-a-php-variable-into-mysql-inserto-into-command/#findComment-882246 Share on other sites More sharing options...
phpfreakjav Posted July 24, 2009 Author Share Posted July 24, 2009 lol thanks Quote Link to comment https://forums.phpfreaks.com/topic/167322-inserting-a-php-variable-into-mysql-inserto-into-command/#findComment-882267 Share on other sites More sharing options...
vineld Posted July 24, 2009 Share Posted July 24, 2009 If the variables come from user input also make sure to escape them properly before inserting them into the database. Quote Link to comment https://forums.phpfreaks.com/topic/167322-inserting-a-php-variable-into-mysql-inserto-into-command/#findComment-882272 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.