Jump to content

[SOLVED] Warning: mysql_fetch_array(): supplied argument is not a valid MySQL ...


DannyM

Recommended Posts

Hello everyone.

 

I've been recieving this strange warning message in my scripts recently - Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\EasySwipeTimeSystems\addEmployee.php on line 23 - and I have no clue why they are popping up. It is connecting to the database just fine, and entering everything into the tables. However, it still wants to complain. Any ideas why? Or should I just suppress it with the @ sign? I've bolded the line of code where the error pops up

 

<?php
if($_COOKIE["User"] != "0001" || !$_COOKIE["User"])
{
header("Location: Login.php");
}

if(isset($_POST["back"]))
{
header("Location: userCP.php");
}

//connect to the database
$con=mysql_connect("********","****","*********");
//Select the database
mysql_select_db("easyswipe_timecardtest",$con);

//Check to see what they clicked
if(isset($_POST["submit"]))
{
$sql="SELECT * FROM employees";
mysql_query($sql,$con);
[b]while($row = mysql_fetch_array($sql))[/b]
{
if($row['ID'] == $_POST["ID"])
{
echo "<b>ID already taken!</b>";
}
else
{



//Insert into everything
$sql=mysql_query("INSERT INTO employees(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");


$sql=mysql_query("INSERT INTO Jan(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO Feb(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO Mar(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO Apr(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO May(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO Jun(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO Jul(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO Aug(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO Sep(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO M1(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO Nov(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO M2(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

}
}
}




//Center everything
echo'<center>
<img src="logo.png"/>';

echo "<form action='addEmployee.php' method='POST'>";
echo '<b>Employee Name</b> - <input type="text" name="Name"/>';
echo '<br/>';
echo '<b>Employee Phone</b> - <input type = "text" name = "phone"/>';
echo '<br/>';
echo '<b>Employee Address</b> - <input type = "text" name = "Address"/>';
echo '<br/>';
echo '<b>Employee ID</B> - <input type="text" name="ID"/>';
echo '<br/>';
echo '<input type="submit" name="submit" value="Add Employee"/>';
echo '<input type="submit" name="back" value="Return"/>';
echo '</form>';


?>


Your variables are a little off...needs to be:

$sql="SELECT * FROM employees";
$result = mysql_query($sql,$con) or die(mysql_error());
while($row = mysql_fetch_array($result))
{

 

Ahh, I see. Nobody had informed me that the variable within mysql_fetch_array() had to be $result, I thought it was just an example that was used. I'll make note of this!

 

Thanks everyone! Case solved.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.