السلام عليكم ورحمة الله وبركاته
انا بدأت اتعلم لغة ال php وفى درس عاملى مشكله ومش عارفلها حل خالص برجاء المساعده فيها لمن يملك المعرفه.
اولا دى صفحة الاتصال بالداتا بيز وجلب البيانات من الجدول.
<?php
/**
* connect to server and database.
*/
function connectToDb($server, $username, $password, $db)
{
$connection = mysql_connect($server, $username, $password);
if($connection){
$db = mysql_select_db($db);
if(!db){
echo "ERROR Selecting database $db, " . mysql_error();
}
} else {
echo "Error Connecting to server." . mysql_error();
}
return $connection;
}
function getAllRecords($tableName, $linkId = null)
{
$query = "SELECT * FROM $tableName";
$resource = ($linkId) ? mysql_query($query, $linkId) : mysql_query($query);
return ($resource) ? $resource : FALSE;
}
function renderCustomers($resource)
{
$output = "";
while ($record = mysql_fetch_assoc($resource)) {
$output .= "<tr>";
$output .= "<td>" . $record['name'] . "</td>";
$output .= "<td><a href=\"project.php?id=" . $record['id'] . "$task=edit\">Edit</a> | <a href=\"project.php?id=" . $record['id'] . "$task=delete\">Delete</a> </td>";
$output .= "</tr>";
}
return $output;
}
?>ودى صفحة ال form نفسه
<?php
require_once '../application/settings.php';
require_once "../application/functions.php";
require_once "../application/db.php";
//Connect to database
$connection = connectToDb($server, $username, $password, $db);
$results = getAllRecords("customers");
?>
<!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=utf-8" />
<title>php first project</title>
</head>
<body>
<form action="" method = "post" class="form" id="customers">
<fieldset><legend>Coustomers</legend>
<p>Please use the following from to add new coustomers.</p>
<br />
<table width="300">
<tr>
<td width="144" height="33" align="left" valign="middle">
<label for="name">Name:</label></td>
<td width="269" align="left" valign="top"><input name="name" id="name"
type="text" class="input" value="" /></td>
</tr>
<tr>
<td width="144" height="33" align="left" valign="middle">
<label for="email">Email:</label></td>
<td width="269" align="left" valign="top"><input name="email" id="email"
type="text" class="input" value="" /></td>
</tr>
<tr>
<td width="144" height="33" align="left" valign="middle">
<label for="address">Address:</label></td>
<td width="269" align="left" valign="top"><input name="Address" id="Address"
type="text" class="input" value="" /></td>
</tr>
<tr>
<td width="144" height="33" align="left" valign="middle">
<label for="gender">Gender:</label></td>
<td width="269" align="left" valign="top"><select name="gender"
class="dropdown" id="gender">
<option value="0">Choose Gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select></td>
</tr>
<tr>
<td width="144" height="33" align="left" valign="middle">
<label for="age">Age:</label></td>
<td width="269" align="left" valign="top"><input name="age" id="age"
type="text" class="smallinput" value="" /></td>
</tr>
<tr>
<td width="144" height="33" align="left" valign="middle">
<label for="interests">Interestes:</label></td>
<td width="269" align="left" valign="top"><textarea id="Address"
name="interestes"></textarea></td>
</tr>
<tr>
<td align="left" valign="top"> </td>
<td align="left" valign="top"><input name="submit"
type="submit" class="submit" value="submit" /></td>
</tr>
<tr>
<td colspan="2" align="left" valign="top"</td>
</tr>
</table>
</fieldset>
</form>
<table class="tableControl">
<caption>Customers in your database</caption>
<tr>
<th>Customers Name</th>
<th>Control</th>
</tr>
<?php
echo renderCustomers($results);
?>
<tr>
<th><a href="project.php">+ Add Coustomer</a></th>
</tr>
</table>
</body>
</html>المشكله كل مااشغل الصفحه يجيبلى الت error ده :
( ! ) Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\FirstProJect\application\db.php on line 28
ياريت الى عنده حل للموضوع ده يقولوا, ولكم وافر التقدير والشكر .