[SOLVED] Must be really blind

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

[SOLVED] Must be really blind

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");
	}
User avatar
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"); 
   }
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

hehe.. thank you!
Post Reply