Undefined variable: php mysql error

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
iansane
Forum Commoner
Posts: 62
Joined: Sun Apr 18, 2010 1:26 pm

Undefined variable: php mysql error

Post by iansane »

Hi,

I have a form with several variables and am getting warning about undefined variable. Also when I submit nothing gets added to the database.

Code: Select all

include 'transaction.php';
include 'dbopen.php';

$fName = $_POST['fName'];

begin(); //this is the begin transaction function

$customersql = "INSERT INTO customer (fName) VALUES ($fName);

$custResult = mysql_query($customersql or die (mysql_error()));

	if(!$custResult)
	{
	rollback(); // transaction rolls back
	error_reporting(E_ALL);
	ini_set('display_errors', '1');
	echo "you rolled back";
	exit;
	}
	else
	{
	commit(); // transaction is committed
	echo "Success!";
	}		


include 'db/dbclose.php';
This displays the error:

Notice: Undefined variable: fName in /home/isimmons/public_html/testdir/bonachela/includes/ticketVarsInc.php on line 162



There are actually about 20 variables that all get this error but to make the post short the above code is what is giving me the problem.

Thanks for any suggestions or help
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Undefined variable: php mysql error

Post by requinix »

I'm going to assume the missing quote is a typo in the post.

If $_POST[fName] is undefined then
a) the form was not submitted, or
b) the field in the form is not called "fName" (case-sensitive).
iansane
Forum Commoner
Posts: 62
Joined: Sun Apr 18, 2010 1:26 pm

Re: Undefined variable: php mysql error

Post by iansane »

Yes the missing quote above is a typo. It's not missing in the actual code. Sorry about that.

And also I've double checked the names. The relevant html tags are as follows

Code: Select all

<form name="myForm" id="myForm action="ticketVars.php" method="POST">
<input type="text" name="fName" id="fName" size="25" maxlength="25"></input>
<input type="submit" name="submit" id="submit" value="submit"></input> 
</form>
The only difference is that there are many more input fields but they are all done in the same way. The submit makes the page redirect and I have a test message at the top of "ticketVars.php" that displays so it is submiting.

I had wondered if the error was from mysql but it seems to be from php as it has to do with the line number for the insert statement before the insert is actually executed. and I get the "roll back" message at the end of the list of errors so I think mysql is working as it should.
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: Undefined variable: php mysql error

Post by internet-solution »

You have another quote missing after id="myForm

Code: Select all

<form name="myForm" id="myForm action="ticketVars.php" method="POST">
iansane
Forum Commoner
Posts: 62
Joined: Sun Apr 18, 2010 1:26 pm

Re: Undefined variable: php mysql error

Post by iansane »

Once again, sorry. The quote is not missing from the actual code. I was trying not to have to post the entire code but just an example of what is giving me the error. I'll have to come back and post the actual code in a little while when I get a few free minutes.

Thanks
Post Reply