Hey evryone. For some reason, I can't seem to insert anything into this table that I have in a database It connects just fine and the variables that I'm retrieving are just fine, which leads me to believe that my INSERT statement is incorrect. Any ideas? Here's the code:

function createrma2() {

require("deps.php");
require("common.php");

$from = pv($_REQUEST['from']);
$custname = pv($_REQUEST['custname']);
$custstreet = pv($_REQUEST['custstreet']);
$custcity = pv($_REQUEST['custcity']);
$custcity = pv($_REQUEST['custstate']);
$custzip = pv($_REQUEST['custzip']);
$custnum = pv($_REQUEST['custnum']);
$coname = pv($_REQUEST['coname']);
$cocontact = pv($_REQUEST['cocontact']);
$conum = pv($_REQUEST['conum']);
$costreet = pv($_REQUEST['costreet']);
$cocity = pv($_REQUEST['cocity']);
$costate = pv($_REQUEST['costate']);
$cozip = pv($_REQUEST['cozip']);
$coweb = pv($_REQUEST['coweb']);
$part = pv($_REQUEST['part']);
$partdes = pv($_REQUEST['partdes']);
$rmanum = pv($_REQUEST['rmanum']);
$comments = pv($_REQUEST['comments']);
$status = pv($_REQUEST['status']);

require_once("validate.php");

if (function_exists('date_default_timezone_set')) {
date_default_timezone_set("$pcrt_timezone");
}

$s1t = date('Y-m-d H:i:s');
$s1u = $_COOKIE["username"];

$rs_connect = @mysql_connect($dbhost, $dbuname, $dbpass) or die("Couldn't connect the db");
$rs_select_db = @mysql_select_db($dbname, $rs_connect) or die("Couldn't select the db");
$rs_insert_scan = "INSERT INTO rma (from, custname, custstreet, custcity, custstate, custzip, custnum, coname, cocontact, conum, costreet, cocity, costate, cozip, coweb, part, partdes, rmanum, comments, status, s1u, s1t) VALUES (\'$from\',\'$custname\',\'$custstreet\',\'$custcity\',\'$custstate\',\'$custzip\',\'$custnum\',\'$coname\',\'$cocontact\',\'$conum\',\'$costreet\',\'$cocity\',\'$costate\',\'$cozip\',\'$coweb\',\'$part\',\'$partdes\',\'$rmanum\',\'$comments\',\'$status\',\'$s1u\',\'$s1t\')";
@mysql_query($rs_insert_scan, $rs_connect);

echo "$from <br> $custname <br> $custstreet <br> $custcity <br> $custstate <br> $custzip <br> $custnum <br> $coname <br> $cocontact <br> $conum <br> $costreet <br> $cocity <br> $costate <br> $cozip <br> $coweb <br> $part <br> $partdes <br> $rmanum <br> $comments <br> $status <br> $s1u <br> $s1t";
}

The echo statement comes out correctly with everything correct and the connection to the database is not erroring out. All help is appreciated. Thanks :)

try rewriting

VALUES (\'$from\',\'$custname\',

to something like this..

 VALUES ('".$from."','".$custname."',

Do the same for the rest of it..

It is so easy to fall into this coding style

  {$from}, {$custname},

but that would be slower than just using concatenation operator . Using concatenation operator is a good practice, in eliminating any possible escaping problems..

e.g.

$thisString = 'Some string';

echo "This string". $thisString."<br/>";

echo 'This string '.$thisString.'<br/>';

## bad coding style below

echo "This string \'$thisString \'";

It still doesn't work. Also when I copied and pasted the code, I forgot to omit the backslashes that I put in there. I put them in as a last ditch attempt even though I didn't think they'd work. Sorry about that. Omit the backslashes in that statment. Thanks for the future reference though.

Here's the actual code:

function createrma2() {

    require("deps.php");
    require("common.php");

    $from = pv($_REQUEST['from']);
    $custname = pv($_REQUEST['custname']);
    $custstreet = pv($_REQUEST['custstreet']);
    $custcity = pv($_REQUEST['custcity']);
    $custcity = pv($_REQUEST['custstate']);
    $custzip = pv($_REQUEST['custzip']);
    $custnum = pv($_REQUEST['custnum']);
    $coname = pv($_REQUEST['coname']);
    $cocontact = pv($_REQUEST['cocontact']);
    $conum = pv($_REQUEST['conum']);
    $costreet = pv($_REQUEST['costreet']);
    $cocity = pv($_REQUEST['cocity']);
    $costate = pv($_REQUEST['costate']);
    $cozip = pv($_REQUEST['cozip']);
    $coweb = pv($_REQUEST['coweb']);
    $part = pv($_REQUEST['part']);
    $partdes = pv($_REQUEST['partdes']);
    $rmanum = pv($_REQUEST['rmanum']);
    $comments = pv($_REQUEST['comments']);
    $status = pv($_REQUEST['status']);

    require_once("validate.php");

    if (function_exists('date_default_timezone_set')) {
    date_default_timezone_set("$pcrt_timezone");
    }

    $s1t = date('Y-m-d H:i:s');
    $s1u = $_COOKIE["username"];

    $rs_connect = @mysql_connect($dbhost, $dbuname, $dbpass) or die("Couldn't connect the db");
    $rs_select_db = @mysql_select_db($dbname, $rs_connect) or die("Couldn't select the db");
    $rs_insert_scan = "INSERT INTO rma (from, custname, custstreet, custcity, custstate, custzip, custnum, coname, cocontact, conum, costreet, cocity, costate, cozip, coweb, part, partdes, rmanum, comments, status, s1u, s1t) VALUES ('$from','$custname','$custstreet','$custcity','$custstate','$custzip','$custnum','$coname','$cocontact','$conum','$costreet','$cocity','$costate','$cozip','$coweb','$part','$partdes','$rmanum','$comments','$status','$s1u','$s1t')";
    @mysql_query($rs_insert_scan, $rs_connect);

    echo "$from <br> $custname <br> $custstreet <br> $custcity <br> $custstate <br> $custzip <br> $custnum <br> $coname <br> $cocontact <br> $conum <br> $costreet <br> $cocity <br> $costate <br> $cozip <br> $coweb <br> $part <br> $partdes <br> $rmanum <br> $comments <br> $status <br> $s1u <br> $s1t";
    }

bump

Echo $rs_insert_scan before mysql_query() statement and see what returns. Is it the right query syntax what you're expecting ?

I found that during my requests, I had custcity twice; when I changed it to cust state like it should be, I got the expected syntax, but it still didn't store. There are other parts of the program that store just fine to the database. Just not this part for some odd reason. Here was the output:

INSERT INTO rma (from,custname,custstreet,custcity,custstate,custzip,custnum,coname,cocontact,conum,costreet,cocity,costate,cozip,coweb,part,partdes,rmanum,comments,status,s1u,s1t) VALUES ('Customer','Chris Smith','1826 Main St.','Delphos','OH','45833','4192034567','Seagate','Jim Nelson','4192034567','1826 Main St.','Delphos','OH','45833','http://www.seagate.com','UDJF Seagate Hardrive','Disk stopped spinning.','473reg8984','Customer is concerned about the warranty.','1','admin','2012-07-13 13:26:03')

Hi,

I have to re-read this question tomorrow. They just finished frying my brain at CALTECH all summer long :).

bump

I figured it out! Finally! After throwing the code in myphpadmin, I discovered that instead of it referring to the column from, it was using the word from as a keyword, so I just changed that column name. Thanks for all the help guys :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.