Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 UNDEFINED VARIABLE ERROR

Author  Topic 

jennifer_ann
Starting Member

8 Posts

Posted - 2006-04-11 : 22:16:10
I have the following form

<head>
<title>Mapleside Farms</title>
<link rel="stylesheet" href="mapleside.css" type="text/css" />
</head>


<form name = "account" action="account.php" method = "post">

Enter information

<input type=text name="lastname">
<br>
<input type=text name="firstname">
<br>
<input type=text name="address">
<br>
<input type=text name="city">
<br>
<input type=text name="state">
<br>
<input type=text name="zipcode">
<br>
<input type=text name="email">
<br>
<input type=text name="username">
<br>
<input type=text name="password">
<br>
</form>


And the following php page
<?php

$Customer_Lname=$_POST['lastname'];
$Customer_Fname=$_POST['firstname'];
$Customer_address=$_POST['address'];
$Customer_city=$_POST['city'];
$Customer_state=$_POST['state'];
$Customer_zipcode=$_POST['zipcode'];
$Customer_email=$_POST['email'];
$Customer_username=$_POST['username'];
$Customer_password=$_POST['password'];


// open connection to database
$db = mysql_connect("localhost", "root", "");
if (!$db)
{
print "unable to connect!";
exit;
}

//select database to use
$db= mysql_select_db ("mapleside");
if (!$db)
{
print "could not select database";
exit;
}

// create SQL query string
$query = "INSERT INTO customer (Customer_Lname, Customer_Fname, Customer_address, Customer_city, Customer_state, Customer_zipcode, Customer_email, Customer_username, Customer_password) VALUES ($Customer_Lname, $Customer_Fname, $Customer_address, $Customer_city, $Customer_state, $Customer_zipcode, $Customer_email, $Customer_username , $Customer_password)";
$result = mysql_query($query);

mysql_query($query) or die
('Error, insert query failed');
echo('Data inserted successfully' );

//close connection
mysql_close();


?>


However, when I run my form and php pages, I get undefined variable errors. Can anyone lead me in the right direction????

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2006-04-12 : 00:16:25
$Customer_Lname etc are parameters defined within your form. How on Earth do you expect SQL Server to know what they are or what they represent? You need to review the concept of scope.
In the meantime, to get your code to work you will need to use your variable to construct a string containing an INSERT statement with the actual values you are submitting. But I will also tell you that it is considered bad practice to do direct inserts to production tables using dynamic SQL from the interface. You should define a stored procedure to handle your insert, and then call the procedure from your interface with the appropriate parameters.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-12 : 04:14:50
You should use '" & variable & "'. Also consider using sp with parameters as suggested

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -