...

View Full Version : PHP to MySQL Form



digitalparrot77
05-28-2004, 03:25 PM
All,

I am relativly new to PHP and MySQL but know enough to get the job done. My problem is that I cannot debug a problem which led me here to post a question.

I have an HTML form that Posts to a PHP script that points to a MySQL database. My Problem is that when i submit the form a new line is generated in my table but the data from the form is not there. what is there is the name of the field in the form.

check out the form here.
LRC Builder Form (http://www.lrcproducts.com/forms/builders/builderinfo.html)

I will post my code if needed but this seems like a easy problem to solve since something is getting written to the database just not the correct data.

Thanks,

Curt

raf
05-28-2004, 03:45 PM
Welcome here !

sadly, the forms code is of no use for us.

Your PHP code for the insert should look like

$insert=”INSERT INTO yourtablename (yourfirstcolumnsname, yoursecondscolumnname, …) value (‘” . $_POST[‘id’] .”’, ‘” . addslashes($_POST[‘name’]) . ‘”, …)”;

digitalparrot77
05-28-2004, 03:56 PM
Raf, Thanks for the welcome. I am pretty excited that I have gotten this to work as well as I have...

This might be more of a MySQL question than a PHP question after reviewing the last post.

<?
$DBhost = "lrcweb01";
$DBuser = "curt";
$DBpass = "";
$DBName = "onlinesignup";
$table = "online_builder_signup";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select
database $DBName");

$sqlquery = "INSERT INTO $table
VALUES
('id','company_name','address','city','state','zip','primary_contact','phone','fax','email','comment s')";

$results = mysql_query($sqlquery);

mysql_close();

?>

carl_mcdade
05-28-2004, 04:05 PM
You have forgotten to pick up your form variables via $_POST:



<?
$DBhost = "lrcweb01";
$DBuser = "curt";
$DBpass = "";
$DBName = "onlinesignup";
$table = "online_builder_signup";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select
database $DBName");

$sqlquery = "INSERT INTO $table VALUES('".$_POST['id']."','".$_POST['company_name']."','".$_POST['address']."','".$_POST['city']."','".$_POST['state']."','".$_POST['zip ']."','".$_POST['primary_contact']."','".$_POST['phone']."','".$_POST['fax']."','".$_POST['email']."','".$_POST['comments']."')";

$results = mysql_query($sqlquery);

mysql_close();

?>

digitalparrot77
05-28-2004, 04:55 PM
Here is the error that I am getting...

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in E:\ALLMANAGEDWEBS\lrcproducts\forms\builders\builder1.php on line 14

Line 14 is VALUES

Thanks,

Curt

<?
$DBhost = "lrcweb01";
$DBuser = "curt";
$DBpass = "";
$DBName = "onlinesignup";
$table = "online_builder_signup";
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@mysql_select_db("$DBName") or die("Unable to select
database $DBName");

$sqlquery = "INSERT INTO $table
VALUES
('$_POST['id']','$_POST['company_name']','$_POST['address']','$_POST['city']','$_POST['state']','$_POST['zip ']','$_POST['primary_contact']','$_POST['phone']','$_POST['fax']','$_POST['email']','$_POST['comments']')";

$results = mysql_query($sqlquery);

mysql_close();

?>

carl_mcdade
05-28-2004, 05:34 PM
The code got broken with carriage returns because I forgot to use a code box. Try again. There should be no breaks in the query rows

digitalparrot77
05-28-2004, 08:25 PM
Thanks all for the help. I think I am getting closer...

Curt

carl_mcdade
05-28-2004, 08:47 PM
Ooop! :o

I checked that string in the parser. It was wrong. It's fixed now.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum