--- Joshua <[EMAIL PROTECTED]> wrote:
> I was hoping someone could help me with my PHP script I have listed
> below. It seems to go through the entire script and navigates to the
> /messagesent.htm page, however, no records are being inserted in the
> database.... what gives? Please check out the script below and let me
> know your thoughts. Thanks for your assistance!
>
> Thanks,
> Josh
>
> ----------------------------------------------------SCRIPT
> BELOW-----------------------------------------------------------------------
>
> <?php
>
> $name = $_POST['NAME'];
> $title = $_POST['TITLE'];
> $company = $_POST['COMPANY'];
> $address = $_POST['ADDRESS'];
> $city = $_POST['CITY'];
> $zip = $_POST['ZIP'];
> $phone = $_POST['PHONE'];
> $fax = $_POST['FAX'];
> $email = $_POST['EMAIL'];
> $quote = $_POST['QUOTE'];
> $mod1 = $_POST['MOD1'];
> $mod2 = $_POST['MOD2'];
> $mod3 = $_POST['MOD3'];
> $mod4 = $_POST['MOD4'];
> $mod5 = $_POST['MOD5'];
> $mod6 = $_POST['MOD6'];
> $mod7 = $_POST['MOD7'];
> $mod8 = $_POST['MOD8'];
> $mod9 = $_POST['MOD9'];
> $mod10 = $_POST['MOD10'];
> $mod11 = $_POST['MOD11'];
> $mod12 = $_POST['MOD12'];
> $workstations = $_POST['WORKSTATIONS'];
> $forms = $_POST['FORMS'];
> $submit = $_POST['SUBMIT'];
>
> $con = pg_connect("host=127.0.0.1 port=5432 dbname=dbone user=joshua
> password=jnw08jnw") or
> die("Couldn't Connect ".pg_last_error());
>
> pg_query("INSERT INTO demorequest (name, title, company, address,
> city, state, zip, phone, fax, email, quote, mod_guestprospecting,
> mod_fni, mod_lease, mod_parts, mod_service, mod_payroll, mod_vehinvmgt,
> mod_accounting, mod_appraisal_control, mod_autocreditbureau,
> mod_leaserresidual, mod_creditbureau, workstations, forms)
> VALUES ('$name', '$title', '$email', '$phone', '$fax', '$email',
> '$quote', '$mod1', '$mod2', '$mod3', '$mod4', '$mod5', '$mod6', '$mod7',
> '$mod8', '$mod9', '$mod10', '$mod11', '$mod12', '$workstations',
> '$forms')");
>
> pg_close($con);
>
> header("Location: http://www.mywebsite.com/messagesent.htm");
> exit;
>
> ?>
I use MySQL and if I were coding with that I would put the query in a string
and follow the query statement with a clause like:
$db = mysql_connect(...);
$q = "INSERT INTO demorequest (name, title, company, address, city, state,
zip, phone, fax, email, quote, mod_guestprospecting, mod_fni, mod_lease,
mod_parts, mod_service, mod_payroll, mod_vehinvmgt, mod_accounting,
mod_appraisal_control, mod_autocreditbureau, mod_leaserresidual,
mod_creditbureau, workstations, forms) VALUES ('$name', '$title', '$email',
'$phone', '$fax', '$email', '$quote', '$mod1', '$mod2', '$mod3', '$mod4',
'$mod5', '$mod6', '$mod7', '$mod8', '$mod9', '$mod10', '$mod11', '$mod12',
'$workstations', '$forms')";
$r = mysql_query($q, $db) or die(mysql_error() . "<br />$q<br />");
With this type of code you will get an error message which shows you the
complaint from the database if it doesn't like your query. It will also show
the query so you can copy-paste it to see if it works differently at your
command line tool to interact with the database.
You seem to be doing a lot of extra work at the top of the code with the
variable assignments. One way to get around this is something like:
$expected = array('NAME', 'TITLE', 'COMPANY', 'ADDRESS', 'CITY', 'ZIP',
'PHONE', 'FAX', 'EMAIL', 'QUOTE', 'MOD1', 'MOD2', 'MOD3', 'MOD4', 'MOD5',
'MOD6', 'MOD7', 'MOD8', 'MOD9', 'MOD10', 'MOD11', 'MOD12', 'WORKSTATIONS',
'FORMS', 'SUBMIT');
foreach ($expected as $postvar)
{
$varname = strtolower($postvar);
$$varname = $_POST[$postvar];
}
You might want to look at the "INSERT INTO table SET column1=value1,
column2=value2, ..." syntax for more legibility. More than likely you have a
mismatch in the number of columns and values which SQL doesn't like at all.
If you used the same capitalization for the POST variables and the internal
ones you could do something with extract. This one is risky because it takes
every POST variable and makes it a local one. You'd run this at the top of the
program.
extract($_POST);
However, if you want to know which variables are going to be set, you could do
something with your list of variables and a modified version of extract():
$NAME = $TITLE = $COMPANY = $ADDRESS = $CITY = $ZIP = $PHONE = $FAX = $EMAIL =
$QUOTE = $MOD1 = $MOD2 = $MOD3 = $MOD4 = $MOD5 = $MOD6 = $MOD7 = $MOD8 = $MOD9
= $MOD10 = $MOD11 = $MOD12 = $WORKSTATIONS = $FORMS = $SUBMIT = "";
extract($_POST, EXTR_IF_EXIST);
This will set each variable to an empty string. The EXTR_IF_EXIST option on
extract() says that only variables which already exist will be pulled.
These don't bear on your original problem but it makes for more concise code.
James