Page 1 of 1

Undefined variable: php mysql error

Posted: Sat Jun 26, 2010 10:01 pm
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

Re: Undefined variable: php mysql error

Posted: Sat Jun 26, 2010 11:49 pm
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).

Re: Undefined variable: php mysql error

Posted: Sun Jun 27, 2010 8:37 am
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.

Re: Undefined variable: php mysql error

Posted: Sun Jun 27, 2010 8:42 am
by internet-solution
You have another quote missing after id="myForm

Code: Select all

<form name="myForm" id="myForm action="ticketVars.php" method="POST">

Re: Undefined variable: php mysql error

Posted: Sun Jun 27, 2010 9:18 am
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