new to php - please help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jo_project08
Forum Newbie
Posts: 7
Joined: Thu Apr 03, 2008 8:16 am

new to php - please help

Post by jo_project08 »

Hi All,

I am rather new to php and am currently doing a project where I have set up a website along with mysql and php.

I am trying to do the following:

one one page I have a number of options with a sumbit button at the side:

<!--submit button -->
<td><form action="<?= $php_SELF ?>" method="POST">
</form><h5>navigation & search</h5></label>
<?php function trainee_course () {} ?>
<input name="trainee_course" type="submit" onclick="MM_goToURL('parent','individual_course_info2.php');return document.MM_returnValue" value="submit" />

then on the following page (which is linked) I am trying to display all training courses which are called 'navigation & search':

<!-- connect to the database -->

<?php

$con = mysql_connect("localhost","root","joanne");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("training", $con);

// perform the SQL query

function submit($query)
{}
function trainee_course()
{}
if(isset($trainee_course))
submit($query);



$trainee_course= "navigation & search";

$query = "select trainee_course, course_date from trainee_courses where trainee_course= '$trainee_course' ";

$result= mysql_query ($query)
or die("couldnt execute query.");
?>

everytime i run this it brings back my own error. Please help!!!

jo
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: new to php - please help

Post by it2051229 »

on the die('couldn't execute query').. would you mind changing it to "or die(mysql_error())" and then post the result here
jo_project08
Forum Newbie
Posts: 7
Joined: Thu Apr 03, 2008 8:16 am

Re: new to php - please help

Post by jo_project08 »

Hi,

Thanks for replying, i get:

Unknown column 'trainee_course' in 'field list'

Cheers!
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: new to php - please help

Post by it2051229 »

check your database, seems like you did not create a COLUMN with that "field name" OR maybe you have misspelled it
jo_project08
Forum Newbie
Posts: 7
Joined: Thu Apr 03, 2008 8:16 am

Re: new to php - please help

Post by jo_project08 »

I changed it and not getting any error now :) thanks!

although I am still not getting the output.
I am wishing to display the course name and date.

cheers.
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: new to php - please help

Post by it2051229 »

Code: Select all

 
$query = "select trainee_course, course_date from trainee_courses where trainee_course= '$trainee_course' ";
 
for($i=0; $i<mysql_num_rows($query); $i++)
{
   $traineeCourse = mysql_result($query,$i, "trainee_course");
   $courseDate = mysql_result($query,$i, "course_date");
 
  echo $traineeCourse."<---- Trainee Course";
  echo $courseDate."<----  Course Date";
}
 
is that what you're looking for?? or something else
jo_project08
Forum Newbie
Posts: 7
Joined: Thu Apr 03, 2008 8:16 am

Re: new to php - please help

Post by jo_project08 »

this is what I have :

<!-- connect to the database -->
<?php

$con = mysql_connect("localhost","root","joanne");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("training", $con);

// perform the SQL query
function submit($query)
{}
function course_name($course_name)
{}
if(isset($course_name))
submit($query);

$course_name= "navigation & search";

$query = "select course_name, course_date from trainee_courses where course_name= '$course_name' ";

for($i=0; $i<mysql_num_rows($query); $i++)
{
$course_name = mysql_result($query,$i, "course_name");
$course_date = mysql_result($query,$i, "course_date");

echo $traineeCourse."<---- Trainee Course";
echo $courseDate."<---- Course Date";
}

$result= mysql_query ($query)
or die(mysql_error());

?>


I am now getting the error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\project\Admin\individual_course_info2.php on line 81

sorry for the hastle!
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: new to php - please help

Post by it2051229 »

wait you have done it wrong.... the QUERY should COME FIRST before the display of data something like

Code: Select all

 
$query = mysql_query("SELECT blah blah blah...") or die(mysql_error());
 
for($i=0; $i<mysql_num_rows($query); $i++)
{
  echo "... blah blha blah";
}
 
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: new to php - please help

Post by it2051229 »

here.. i modified your code.. give it a try

Code: Select all

 
<!-- connect to the database -->
<?php
 
$con = mysql_connect("localhost","root","joanne");
if (!$con)
{
     die('Could not connect: ' . mysql_error());
}
 
mysql_select_db("training", $con);
 
// perform the SQL query
function submit($query)
{}
function course_name($course_name)
{}
if(isset($course_name))
submit($query);
 
$course_name= "navigation & search";
 
$query = "select course_name, course_date from trainee_courses where course_name= '$course_name' ";
 
$result= mysql_query ($query)
or die(mysql_error());
 
for($i=0; $i<mysql_num_rows($result); $i++)
{
$course_name = mysql_result($result,$i, "course_name");
$course_date = mysql_result($result,$i, "course_date");
 
echo $traineeCourse."<---- Trainee Course";
echo $courseDate."<---- Course Date";
}
?>
 
jo_project08
Forum Newbie
Posts: 7
Joined: Thu Apr 03, 2008 8:16 am

Re: new to php - please help

Post by jo_project08 »

yeah im getting the same error message as before along with the echoed line..any further suggestions???
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: new to php - please help

Post by it2051229 »

ok seems like there is no queried data..
to check try this..

Code: Select all

 
if(mysql_num_rows($result) > 0)
{
   // place the display for loop code here
   for($i=0; $i<mysql_num_rows($result); $i++)
   {
         /// blah blah blah
   }
}
else
{
  echo "SORRY THERE AIN'T NO DATA BOY!!";
}
 
jo_project08
Forum Newbie
Posts: 7
Joined: Thu Apr 03, 2008 8:16 am

Re: new to php - please help

Post by jo_project08 »

no luck :(

$query = "select course_name, course_date from trainee_courses where course_name= '$course_name' ";

if(mysql_num_rows($query) > 0)
{
$course_name = mysql_result($query,$i, "course_name");
$course_date = mysql_result($query,$i, "course_date");

echo $course_name."<---- Trainee Course";
echo $course_date."<---- Course Date";

for($i=0; $i<mysql_num_rows($query); $i++)

else
echo "SORRY THERE AIN'T NO DATA BOY!!";
}

{
or die(mysql_error());
}
?>

its giving me an error for the else now!!!
User avatar
it2051229
Forum Contributor
Posts: 312
Joined: Tue Dec 25, 2007 8:34 pm

Re: new to php - please help

Post by it2051229 »

lol..
.. try this

Code: Select all

 
$query = mysql_query("select course_name, course_date from trainee_courses where course_name= '$course_name' ") or die(mysql_error());
 
if(mysql_num_rows($query) > 0)
{
   for($i=0; $i<mysql_num_rows($query); $i++)
   {
      $course_name = mysql_result($query,$i, "course_name");
      $course_date = mysql_result($query,$i, "course_date");
 
      echo $course_name."<---- Trainee Course";
      echo $course_date."<---- Course Date";
   }
}
else 
{
   echo "SORRY THERE AIN'T NO DATA BOY!!";
}
?>
 
Post Reply