Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unusual PHP problem, request assistance.

Status
Not open for further replies.

CHeighlund

Programmer
Jun 11, 2007
163
US
I have a rather unusual problem with a webform I'm working on, and I'm hoping someone here can point me to what it is I'm doing wrong.

Code segment going weird:

Code:
$SQL_INTERIOR = "insert into int_form values ('$KEY', '$IntScore', $T1X1, $T1X2, $T1X3, $T1X4, $T1X5, $T1X6, $T1X7, default, default);";
echo "<br/>$SQL_INTERIOR<br/>";
$result1 = @pg_query($connect,$SQL_INTERIOR) or die("could not complete query interior");

$KEY is the value of a foreign key, generated earlier in the page then immediately called back up to fill the variable.

I have a database set up to receive the results of the page. I'm getting constant 'could not complete query' errors when I try to submit the information, but I have no problem inserting it into the database when I manually copy it from the page (the reason for the echo line).

structure of int_form:
Code:
  Column  |         Type         |   Modifiers
----------+----------------------+---------------
 rcrd_key | integer              |
 score    | character varying(3) |
 item1    | boolean              | default false
 item2    | boolean              | default false
 item3    | boolean              | default false
 item4    | boolean              | default false
 item5    | boolean              | default false
 item6    | boolean              | default false
 item7    | boolean              | default false
 item8    | boolean              | default false
 item9    | boolean              | default false
Foreign-key constraints:
    "int_form_rcrd_key_fkey" FOREIGN KEY (rcrd_key) REFERENCES survey_form(form_key)

Would someone please suggest what I might be doing here that's causing these problems, or at least something I can look into on them?
 
I would for starters remove the @ from the call to pg_Query. Why are you suppressing errors when you are developing?
See if that gives you more information on what may be going wrong wit the query call.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I find that escaping double-quotes sometimes fixes problems with unexpected characters in the data. Surround each field with \"$variable\" rather than using the single quote.

It's worth a try anyway.

Mark
 
@vacunita

"Why are you suppressing errors when you are developing?"
Mostly because I'm getting my code by copying it from programs that I know do work, rather than typing it in myself. Thank you for the suggestion to drop that; it lead me to the problem and correct solution.
 
Glad you figured it out, might you share the error with us, so that if someone else has a similar problem they know what may have caused it?

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Sheer ignorance on my part.

The nature of the page I'm working with requires a bit of jigsaw-like orientation. (Page has four possible layouts, three of which used that particular set of code, but in different places.) I'd attempted to make that easier on myself by building function routines that I could call whenever necessary, each of which could handle one segment of the code.

I was creating my connection string inside the main body of the code, without realizing that it wouldn't be carried into the subroutines by default. To make matters worse, I had realized that about one of the values I needed for the sql statement; I guess I was thinking of the connection as something other than a variable. Adding the 'global $connect' line at the beginning of the function(s) solved the problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top