Topic: Help with MYSQL and getting records by id

Hello, I was wondering if anyone can help me out..... I am trying to get records from mySQL database by id.....but I don't know what I am doing wrong and why it is not working.....can anyone help me? please?
here is the code.....

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>members area</title>
</head>

<?php
//===============================================
//CONNECT TO MY DATABASE AND SELECT MY DATABASE
$con = mysql_connect('localhost','root','');
$sel = mysql_select_db('calendar');
//===============================================
//DEFINE VARIABLES FOR MYSQL ROWS
$id = $_GET['ff_id'];

//BUILD MY QUERY
$Q = "SELECT * FROM ps69_school_registration WHERE ff_id = '$id'";
$res = mysql_query($Q);
$my_rows;

//NOW I WILL CREATE A LOOP COMMAND
while($row = mysql_fetch_array($res,MYSQL_ASSOC)){
$my_rows = $my_rows . "id: " . $row['ff_id'] . " Student Name: " . $row['Student_full_name'];
}

?>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="get">
student id: <input type="text" name="id"/><input type="submit" value="get record"/>
</form>

<body>
<?php echo $my_rows; ?>
</body>
</html>

Vote up Vote down

Re: Help with MYSQL and getting records by id

What error message are you receiving?

Vote up Vote down

Re: Help with MYSQL and getting records by id

I never got an error, I just wasn't able to display records from mySQL but I fixed the problem big_smile thanx any way

Vote up Vote down

Re: Help with MYSQL and getting records by id

jbwebdesign wrote:

I never got an error, I just wasn't able to display records from mySQL but I fixed the problem big_smile thanx any way

What was your solution?

.... Good for the forum to have the answer.

Thanks,

Stefan

Practical web design training videos: KillerSites University

Vote up Vote down

Re: Help with MYSQL and getting records by id

Hey stephan, To answer your question about what I did to fix my problem,.........

<?php
//===============================================
//CONNECT TO MY DATABASE AND SELECT MY DATABASE
$con = mysql_connect('localhost','root','');
$sel = mysql_select_db('calendar');
//===============================================
//DEFINE VARIABLES FOR MYSQL ROWS
$id = $_GET['ff_id'];
$get_record = $_GET['get_records'];

if(isset($get_record)){
echo $my_rows;
}

//BUILD MY QUERY
$Q = "SELECT * FROM ps69_school_registration WHERE ff_id = '$id'";
$res = mysql_query($Q);
$my_rows;

//NOW I WILL CREATE A LOOP COMMAND
while($row = mysql_fetch_array($res,MYSQL_ASSOC)){
$my_rows = $my_rows . '<div class="tablerow1"><b>Student id: </b>' . $row['ff_id'] . '<br><b> Student Name: </b>' . $row['Student_full_name'] . '<br><b>Route Number: </b>' . $row['Route_number'] . '<br><b>Begining Service Date: </b>' . $row['Begining_service_date'] . '</div>' . '<form method="POST"> <input type="submit" value="Check Payment" name="cap" class="searchbutton"/></form>';
}

?>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="get">
student id: <input type="text" name="ff_id"/><input type="submit" value="get record" name="get_records"/>
</form>
</div>
<?php
echo $my_rows;
?>

Vote up Vote down

Re: Help with MYSQL and getting records by id

I added an input name to the submit button, then i added this

//DEFINE VARIABLES FOR MYSQL ROWS
$id = $_GET['ff_id'];
$get_record = $_GET['get_records'];

if(isset($get_record)){
echo $my_rows;
}

Vote up Vote down