SQL PHP HTML ASP JavaScript articles and free scripts to download
 

PHP MySQL Query Functions mysql_query()


This function mysql_query() is used to pass a sql query to mysql database. We can write any sql query like insert , select , update , delete etc and pass the query to mysql database. The result of the execution of the query will be known by monitoring the status. We will get true or false based on the success or failure status of the query. We can specify and connecting link as an optional parameter. If no connecting link is specified it assumes default connection.

We will use our student table which has fields as id, name, class, mark. Table name is student. You can download the sql dump file at that end of this tutorial for the student table.

Here it is assumed that mysql connection is open and we will discuss the query part only.

<?
$query="select name,class,mark from student";
$status=mysql_query($query) or die( "query failed");
if($status){echo "Query is successful";}
else {echo "Qyery failed";}
?>
Related Tutorial
Printing Error message
Posting error message to an email address
PHP MySQL data display


The above lines will print "Query is successful" as the query is correct one. In the above lines replace this line
$query="select name,class,mark from student";

with

$query="select name,class1,mark from student";

Here we have intentionally written the field name as class1 ( actual field name is class). On execution of the query the value of $status will be FALSE so the echo command inside else statement will print "Qyery failed".

Download the SQL group by query file to create the table with data

Discuss this tutorial at forum

List of SQL Tutorials


Scripts
PHP
JavaScript
SQL Tutorial List
SQL (Home)
SQL site Map
Knowledge Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.