954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Modifying existing php and database

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.

threebluIdboys
Newbie Poster
6 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

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!

darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
 

Thanks,
I will try to modification.

threebluIdboys
Newbie Poster
6 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You