Hi,
I am very new the whole php and mysql scene. I am trying to teach myself and so far everything has gone smooth, that is until today.
I am trying to modify an existing php form that of course adds to a database and then displays the results for everyones viewing pleasure.
All this works fine but if I try to modify the same form (to show different information in a different location) I am getting errors from my mysql code. I created a new table definition in my database to go along with the changed form but am stumped...

Here it is the code for my connection but my error messages come from the second set of code.

function safe_query($query) {
    $pass = 'needless info';
    $user = 'needless info';
    $destination = 'localhost';
    $database = 'asumh';
    $table = 'eventStudent';

    mysql_connect($destination,$user,$pass) or die("Error: unable to connect to the database");
    mysql_select_db($database);
    return mysql_query($query);

$order_by = $_GET['order_by'];
$query = "select idStudent, titleStudent from eventStudent order by start_yearStudent desc, start_monthStudent desc, start_dayStudent desc";


$result = safe_query($query);

$num = mysql_num_rows($result);

I hope I have included enough information to get some help and please remember this is all very new to me.

Edited 3 Years Ago by Dani: Formatting fixed

Hi threebluldboys and welcome to DaniWeb :)

The line

return mysql_query($query);

comes before you have defined what $query is. It should probably come at the end of the function as it is returning something.

Hope this helps and happy php'ing!

This article has been dead for over six months. Start a new discussion instead.