The mysql_query( ) FunctionNow we need a way to send this query to the server and for the server to let us know if all went well. We can use the mysql_query( ) function to do this. As in the code we just discussed, we will again set this function to a variable and this time we will name the variable $result. However, you can use any name for this variable. As before, it is not necessary to do this, but it does make the code much easier to read. The code for the mysql_query( ) function itself is placed after the equal size but no quotation marks are needed. The statement ends with a semicolon.
As you can see, this statement uses two variables that are placed between the parenthesis. ($sql_send and $connection). We initialized the $sql_send variable in the sql INSERT statement. The $connection variable was created in the mysql_connect( ) function from a previous tutorial. Also, we reused some of the things you learned in this same previous tutorial. This new mysql_query( ) function also uses the @ to suppress the default error message and the die( ) statement to customized an error message for the possibility that we cannot connect to the database. When you are using PHP, the connection to the server is automatically closed for you. ← Back The MySQL Database and Rules for Using SQL Queries Personal Activities Calendar Program – Use the strtotime and mysql_select_db Functions How to Connect to the MySQL Server with the PHP mysql_connect Function | |