I’m using the code:
function insertV($deptx, $coursex, $secx, $isbnx,$titlex, $authorx,$usedpx,$newpx)
{
$sql = "INSERT INTO `$deptx` (`course`, `sec`, `isbn`, `title`, `author`, `usedp`, `newp`)
VALUES ('$coursex','$secx','$isbnx','$titlex','$authorx','$usedpx','$newpx')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
}
$dept = "ACCOUNTG";
$course = "340";
$sec = "101";
$isbn = "9780324651140";
$title = "FINANCIAL ACCOUNTING";
$author = "STICKNEY";
$usedp = "$129.75";
$newp = "$199.75";
insertV($dept,$course,$sec,$isbn,$title,$author,$usedp,$newp);
But I keep getting an error:
Warning: mysql_query(): supplied
argument is not a valid MySQL-Link
resource in
/home/public_html/mysite.com/myscript.php
on line 14 Error:
I’m guessing it has to do with me trying to access a table using a var?
Any help would be appreciated, I’m still new to PHP if you couldn’t tell 😛
EDIT: Oh yeah, line 14 is
if (!mysql_query($sql,$con))
You aren’t defining your
$conwithin the function. This is part of PHP’s scoping rules. Variables defined outside a function are not visible within a function unless you declare themglobal, you’d need something like this:So, the error is due to $con being null within the function, which is “not a valid MySQL-link resource”