0

I wrote the php code below to fetch data from mysql to html table, but no matter how I tried, it always show Internal Server Error, could there anyone can help me to take a look at the code?

And I tested the query in mysql, it works, I don't know why when I add it to php, it just crashed.

$StartDate = date( 'Y-m-d' strtotime($_POST['StartDate']));
$EndDate = date( 'Y-m-d' strtotime($_POST['EndDate']));

$link = mysql_connect('****', '****', '****');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db(****); 

// Search by date query
$SearchByDate = "
    SELECT Order_Info.OrderID, Order_Info.Date, Client_Info.Manager, Material_Info.MateRefNum,       Order_Info.CustomMateName,
    Order_Info.Quantity, Order_Info.Weight, Order_Info.TechRequire, Order_Info.UniPrice, Order_Info.TotPrice,   Order_Info.OtherNote
    FROM Order_Info, Client_Info, Material_Info
    WHERE Order_Info.MateID = Material_Info.MateID
    AND Order_Info.ClientID = Client_Info.ClientID
    AND Order_Info.Date >  '$StartDate' 
    AND Order_Info.Date < '$EndDate'
    ORDER BY Order_Info.Date DESC;
";

$query = mysql_query($SearchByDate,$link);

echo "<div><table>";
echo "<tr><td>OrderID</td><td>Date</td><td>Client</td><td>Material Number</td><td>Material Name</td><td>Quantity</td><td>Weight</td><td>Technical Requirement</td><td>Unit Price</td><td>Total Price</td><td>Notes</td></tr>";

while($row = mysql_fetch_array($query)){
    echo "<tr>";
    echo "<td>".row['Order_Info.OrderID']."</td>";
    echo "<td>".row['Order_Info.Date']."</td>";
    echo "<td>".row['Client_Info.Manager']."</td>";
    echo "<td>".row['Material_Info.MateRefNum']."</td>";
    echo "<td>".row['Order_info.CustomMateName']."</td>";
    echo "<td>".row['Order_Info.Quantity']."</td>";
    echo "<td>".row['Order_Info.Weight']."</td>";
    echo "<td>".row['Order_Info.TechRequire']."</td>";
    echo "<td>".row['Order_Info.UniPrice']."</td>";
    echo "<td>".row['Order_Info.TotPrice']."</td>";
    echo "<td>".row['Order_Info.OtherNote']."</td>";
    echo "</tr>";
}
echo "</table></div>";
?>
7
  • 1
    What have you done to debug this? There's a lot of code there and you should have been able to whittle it down to a much smaller portion of code without our help. Commented Jan 3, 2014 at 2:57
  • "Internal Server Error"?? i think it is nothing do with SQL Commented Jan 3, 2014 at 3:02
  • TT I just use dreamwear for doing this,,, may I ask how to debug it? Thank you~~ Commented Jan 3, 2014 at 3:08
  • which development environment are you in? XAMPP? WAMP? LAMP? Commented Jan 3, 2014 at 3:33
  • Er... What are all these environments? I just use dreamwear or notpad and code and upload to server which support php... Commented Jan 3, 2014 at 3:46

1 Answer 1

1
  1. your variable must be using symbol '$', but you did not
  2. you can use var_dump($row) to help you to know how the structure of the array

the code:

while($row = mysql_fetch_array($query)){
    echo "<tr>";
    echo "<td>".$row['OrderID']."</td>";
    echo "<td>".$row['Date']."</td>";
    echo "<td>".$row['Manager']."</td>";
    echo "<td>".$row['MateRefNum']."</td>";
    echo "<td>".$row['CustomMateName']."</td>";
    echo "<td>".$row['Quantity']."</td>";
    echo "<td>".$row['Weight']."</td>";
    echo "<td>".$row['TechRequire']."</td>";
    echo "<td>".$row['UniPrice']."</td>";
    echo "<td>".$row['TotPrice']."</td>";
    echo "<td>".$row['OtherNote']."</td>";
    echo "</tr>";
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much for your answer! And I feel shame lost the $... But It still shows Internal server error... Is there anything wrong with the query? T T It makes me so stress..
Maybe you add a line die(); after mysql_select_db(****);. Could it return the message of 'Connected successfully' ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.