Hi all,
I’ve got a bunch of code, but it doesn’t work for some reason. It show this “Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /xxx/requires/functions.php on line 25”
index.php
<?php
require('requires/header.php');
$dataToDisplay = getData();
for($i = 0; $i < count($dataToDisplay); $i++)
{
if(isset($_POST['sb'.$i]))
{
writeData($_POST['userName'.$i], $_POST['password'.$i], $_POST['languageId'.$i]);
header("location: ".$_SERVER['PHP_SELF']."");
}
}
echo '<h1>Demo Website</h1>';
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post"><fieldset>';
echo '<table>
<tr>
<th>Username</th>
<th>Password</th>
<th>Language ID</th>
</tr>';
for($i = 0; $i < count($dataToDisplay); $i++)
{
echo '<tr>';
echo '<td><input type="text" name="userName'.$i.'" readonly="readonly" value="'.$dataToDisplay[$i]['userName'].'" /></td>';
echo '<td><input type="text" name="password'.$i.'" value="'.$dataToDisplay[$i]['password'].'" /></td>';
echo '<td><input type="text" name="languageId'.$i.'" value="'.$dataToDisplay[$i]['languageId'].'" /></td>';
echo '</tr>';
}
echo '</table>';
echo '</fieldset>
</form>';
require('requires/footer.php');
?>
functions.php
<?php
require('dbHandler.php');
function getData()
{
// Connect to MySQL
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWD);
// Check connection
if (!$link)
{
return FALSE;
}
// Select DB
mysql_select_db(DB_IC, $link);
$dataQuery = mysql_query(QR_GETDATA);
// Bind results
$dataArray = array();
$i = 0;
while($row = mysql_fetch_array($dataQuery))
{
$dataArray[$i]['userName'] = $row["userName"];
$dataArray[$i]['password'] = $row["password"];
$dataArray[$i]['languageId'] = $row["languageId"];
$i++;
}
// Close connection
mysql_close($link);
return $dataArray;
}
function writeData($userName, $password, $languageId)
{
// Connect to MySQL
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWD);
// Check connection
if (!$link)
{
return FALSE;
}
// Select DB
mysql_select_db(DB_IC, $link);
mysql_query("UPDATE user SET userName = '$userName' WHERE Id = $id");
// Close connection
mysql_close($link);
return TRUE;
}
?>
Thanks for help.
BTW- MySql database is set up correctly.