Jump to content

Querry MySQL Database and Return Multiple Results - PLEASE PLEASE HELP


Recommended Posts

Hi Everyone,

 

Well I have a bit of a problem... I have created a search page that I would like to return results from my MySQL database. However for some reason I can not get my page to display the results. Instead I am getting an error page. Below is the code I am using:

 

In addition to this, should I wish for a user to be able to edit the returned results by clicking a link, how would I do that? :'( :'(

 

<?php
session_start();
?>
<link rel="stylesheet" type="text/css" href="css/layout.css"/>
<html>

<?php
$record = $_POST['record'];
echo "<p>Search results for: $record<br><BR>";

$host = "localhost";
$login_name = "root";
$password = "P@ssword";

//Connecting to MYSQL
MySQL_connect("$host","$login_name","$password");

//Select the database we want to use
mysql_select_db("schedules_2010") or die("Could not find database");

$result = mysql_query("SELECT * 
FROM schedule_september_2010 
WHERE 
champ LIKE '%$record%' ") 
or die(mysql_error());  


// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
        // Print out the contents of each row
echo "<br><p>Your Schedule<BR></p><br>";
echo "<table border=1>\n";
echo "<tr>
<td bgcolor=#444444 align=center><p><b>Champ</p></td>
<td bgcolor=#444444 align=center><p><b>Date</p></td>
<td bgcolor=#444444 align=center><p><b>Start Time</p></td>
<td bgcolor=#444444 align=center><p><b>End Time</p></td>
<td bgcolor=#444444 align=center><p><b>Department</p></td>
<td bgcolor=#444444 align=center><p><b>First Break</p></td>
<td bgcolor=#444444 align=center><p><b>Second Break</p></td>
<td bgcolor=#444444 align=center><p><b>Login ID</p></td>
</tr>\n";
do {




printf("<tr>
<td><p>%s</p></td>
<td><p>%s</p></td>
<td><p>%s</p></td>
<td><p>%s</p></td>
<td><p>%s</p></td>
<td><p>%s</p></td>
<td><p>%s</p></td>
<td><p>%s</p></td>
</tr>\n"
, $row["champ"]
, $row["date_time"]
, $row["start_time"]
, $row["end_time"]
, $row["department"]
, $row["first_break"]
, $row["second_break"]
, $row["login_id"]
);

} while ($row = mysql_fetch_array($result));
echo "</table>\n";
} else {
echo "$champ No Records Found"; 
} 

mysql_free_result($result);
mysql_close($con);
?>
</html>

I'm only a noob so I hope I'm not wrong here.

 

I have learnt pretty quickly that its good practice to have error checking of some sort.

 

for example

$record = $_POST['record'];

if (!$record) {
echo 'Error. <br />Error # ', mysql_errno(), ' Error msg: ', mysql_error();
exit;
}
echo "<p>Search results for: $record<br><BR>";

 

It makes it easier to debug the code.

I'm only a noob so I hope I'm not wrong here.

 

I have learnt pretty quickly that its good practice to have error checking of some sort.

 

for example

$record = $_POST['record'];

if (!$record) {
echo 'Error. <br />Error # ', mysql_errno(), ' Error msg: ', mysql_error();
exit;
}
echo "<p>Search results for: $record<br><BR>";

 

It makes it easier to debug the code.

 

This is correct, place this under your querry and it should report the problem!

just for a start:

 

- You have several syntax/construction  mistakes in your code.

- Unbalanced {}'s...

- Missing if clause and remaining of it still there (last else).

- bad use of while(2 times)/do sentences...

 

try to review your code and find the mistakes that I'm mentioning ...

 

 

Hi guys, thanks for the replies. I put the error check into my code but still I am getting an HTTP 500 error page. I know that the query works perfectly as if I run it without the table formatting it returns the desired results, however the information is displayed in such a way that it is difficult t understand.

 

I'm still very new to php/mysql coding and thus I am aware that unfortunately my code is very very untidy and thus I appreciate all the help that everyone is providing me.

 

It will be really awesome if you guiys could help me solve this mystry

The HTTP 500 error page just means that an incomplete response was generated. Php does this on purpose when you have a fatal parse or fatal runtime error and the error_reporting/display_errors settings set to hide errors.

 

You should set error_reporting to E_ALL and display_errors to ON in your master php.ini so that all the errors php detects will be reported and displayed to help you find problems in your code. Stop and start your web server to get any change made to the master php.ini to take effect.

Ok, so I now t the error message to display. I tried making some changes on line 72 as the error messages say, but still no resolve. Here is the error mesasge:

 

Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Helsinki' for '2.0/no DST' instead in C:\Server\Apache2.2\htdocs\schedules\champ_search_september202.php on line 72 Parse error: syntax error, unexpected T_ELSE in C:\Server\Apache2.2\htdocs\schedules\champ_search_september202.php on line 72

 

LINE 72 is the last part of the script where it refers to closing the table and the else should there be no results.

 

 

Please post the new code that you have now.

 

Did you review the comments that I did post before?... if you are maintaining the same code than before your errors still related to what I mentioned before.

 

post your code again and will check.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.