Undefined variable.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gsashwin
Forum Newbie
Posts: 4
Joined: Thu Nov 18, 2010 12:11 am

Undefined variable.

Post by gsashwin »

Hi,

I am trying to execute the below code but getting these errors :


Notice: Undefined variable: mysql_query in C:\wamp\www\process.php on line 16

Fatal error: Function name must be a string in C:\wamp\www\process.php on line 16


Code:


<html><body>
<?php

mysql_connect("localhost","root","");
mysql_select_db("encryption") or die(mysql_error());

$username = $_POST['username'];
$password = $_POST['password'];

$mysql_query("INSERT INTO login (username,password) VALUES ('$username','$password')") or die(mysql_error());

?>
</body></html>
`
$_POST['username'] &
$_POST['password'] come from a previous page. I have no problem with that. Please help.. Thanks in advance.
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: Undefined variable.

Post by Neilos »

Hello,

Correct me if I'm wrong but that code isn't 16 lines long. Could you post the entire code for process.php and put some 'PHP Code' tags round it please.

Example

Code: Select all

<?php
$var1 = 1;
$var2 = 1;
$var3 = 3;

$sum = $var1 + $var2;

if($sum != $var3) {
	echo "The world is still sane";
} else {
	echo "Run for the hills!!!";
}
?>
:D
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Undefined variable.

Post by Celauran »

gsashwin wrote:$mysql_query("INSERT INTO login (username,password) VALUES ('$username','$password')") or die(mysql_error());
mysql_query is a function, not a variable. Lose the leading $
Post Reply