I am trying to cut down on the amount of select statements, updates etc in my code so I thought that I would try to create a function for this, however I am puzzled that my efforts are failing at the first hurdle.
I have Googled this issue quite comprehensively (I feel) and I can't find any differences in the examples that I have found.
This is my function complete with print statements to help me diagnose the issue.
function select_statement($action, $table, $where){
print $action.' - ';
switch ($action){
case 'select':
print 'select used - ';
$thequery = 'SELECT * FROM '. $table . ' WHERE '. $where;
case 'insert':
print 'insert used - ';
$thequery = 'INSERT INTO '. $table;
case 'update':
print 'update used - ';
$thequery = 'UPDATE ' . $table . ' SET ';
}
print $thequery;
mysql_query($thequery);
}
This is the line that calls the function:-
$logins = select_statement('select', 'users', 'user_id=1');//calls function
This is the result:-
select - select used - insert used - update used - UPDATE users SET
As you can see the code is triggering each of the print statements and seemingly ignoring the 'case' statements.
I'm really not sure what it is that I am doing wrong here?