Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
-
ol4pr0
- Forum Regular
- Posts: 926
- Joined: Thu Jan 08, 2004 11:22 am
- Location: ecuador
Post
by ol4pr0 »
Cant seem to find why i have this error
Notice: Undefined variable: query
$query infront of INSERT
in this
Code: Select all
$host = 'localhost';
$usr = 'root';
$pwd = '';
$db = 'testdb';
$link =mysql_connect($host, $usr, $pwd)
or die ( "Execute error: " .mysql_error());
$dbconnect = mysql_select_db($db, $link);
$query = "INSERT INTO test (code,name,amt,inv_num,check_num,date) VALUES (".$_POST['code'].",".$_POST['name'].",".$_POST['amt'].",".$_POST['inv_num'].",".$_POST['check_num'].",".$_POST['date'].")";
}
$result = mysql_query($query) or die(mysql_error());
if (!$query)
{
die ("DB prolly down, you might wanna email the site admin");
}
-
JayBird
- Admin
- Posts: 4524
- Joined: Wed Aug 13, 2003 7:02 am
- Location: York, UK
-
Contact:
Post
by JayBird »
What is the extra Curly Brace for? I have commented it in your code
Code: Select all
$host = 'localhost';
$usr = 'root';
$pwd = '';
$db = 'testdb';
$link =mysql_connect($host, $usr, $pwd)
or die ( "Execute error: " .mysql_error());
$dbconnect = mysql_select_db($db, $link);
$query = "INSERT INTO test (code,name,amt,inv_num,check_num,date) VALUES (".$_POST['code'].",".$_POST['name'].",".$_POST['amt'].",".$_POST['inv_num'].",".$_POST['check_num'].",".$_POST['date'].")";
} // <------What does this relate to?
$result = mysql_query($query) or die(mysql_error());
if (!$query)
{
die ("DB prolly down, you might wanna email the site admin");
}
-
ol4pr0
- Forum Regular
- Posts: 926
- Joined: Thu Jan 08, 2004 11:22 am
- Location: ecuador
Post
by ol4pr0 »
hehe.. thank you!