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>';


?>


Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.