Jump to content

clay1

Members
  • Posts

    161
  • Joined

  • Last visited

    Never

Everything posted by clay1

  1. I am having some difficulty wrapping my head around this. I want to select a single value from a table for example: pg_query($conn, "select email from markets where market = richmond"); I want to assign that to variable $email pg_query gives me resource id #9 What do I need to do to get assign the email to the variable?
  2. Thanks! That worked the only thing I needed to change was it needs the date for both $sql = "SELECT * from \"leads\" WHERE \"event city\" ~* '{$_POST['select']}' and \"date\" {$_POST['operator']} '{$y1}-{$m1}-{$d1}' OR \"event city\" ~* 'alexandria' and \"date\" {$_POST['operator']} '{$y1}-{$m1}-{$d1}'"; Thanks a lot
  3. I have a form which produces an postgresql query. It selects all the records where the event city = the posted variable As such: $sql = "SELECT * from \"leads\" WHERE \"event city\" ~* '{$_POST['select']}' and \"date\" {$_POST['operator']} '{$y1}-{$m1}-{$d1}'"; This works fine-- however sometimes I need to select more than just the posted variable. For example if the post is washington dc, I also want the query to select alexandria I tried: if ($_POST['select'] == 'washington dc'){ $sql = "SELECT * from \"leads\" WHERE \"event city\" ~* '{$_POST['select']}' OR 'alexandria' and \"date\" {$_POST['operator']} '{$y1}-{$m1}-{$d1}'"; But I get an invalid syntax error. How can I do this?
  4. Thanks for the tip I've got it working using this code.. is there anything I could do better here? $email = $line[$emailkey]; $checkdupes = "SELECT * from \"leads\" WHERE \"e-mail\" = '{$email}'"; $emailresult = pg_query($conn, $checkdupes); if ($dupes = pg_fetch_row($emailresult)){ echo 'Line: ' . $row . ' ' . $line[$namekey] . ' ' . $line[$emailkey] . ' is a duplicate<br><br>'; $rowsinserted--; } elseif(empty($email)){ echo 'Line: ' . $row . ' ' . $line[$namekey] . ' ' . $line[$emailkey] . ' has no email address<br><br>'; $rowsinserted--; } elseif(empty($telephone)){ echo 'Line: ' . $row . ' ' . $line[$namekey] . ' ' . $line[$emailkey] . ' has no phone number<br><br>'; $rowsinserted--; } else { if ($age < 25){ echo 'Line: ' . $row . ' ' . $line[$namekey] . ' ' . $line[$emailkey] . ' is a under 25 years old<br><br>'; $rowsinserted--; } $status = insertRow('leads', $vars, $nulls, $format, $types);
  5. I don't understand your answer-- could you explain?
  6. I have a script which takes a file of customers and inserts the records into my postgres table. The email column in my table is set as a unique key, as I only want new records inserted into the table. If the file has a duplicate email-- how can I get a report of which records are excluded? Currently I get this error: Query failed: ERROR: duplicate key value violates unique constraint "leads_e-mail_key" I'd like to suppress that and instead display which records already existed
  7. I debugged the script I was trying to copy, went through line by line with echo statements until I could get my output to match it.. finally got everything working.
  8. I basically scrapped everything and started over and got it working.
  9. This is related but a different issue than my other thread so I started a new topic When I run my script, I am ending up with a table which looks like this: a b c d a NULL NULL NULL NULL b NULL NULL NULL NULL c NULL $insertSql = "INSERT INTO test ($fields[$col]) VALUES ('$vars[$col]')"; $result = pg_query($conn, $insertSql); The echoed statement lines everything up correctly. Column A B C have the appropriate values and so forth echo $insertSql; Displays: INSERT INTO test (a) VALUES ('a')INSERT INTO test (b) VALUES ('b')INSERT INTO test (c) VALUES ('c') Each time it's moving down a row and over 1 column and inserting null values, instead of over each column and then down a row with the correct values. I imagine this is somehow related to my loops, but can't figure out why it would echo correctly but not hit the DB correct
  10. OK great. That fixed that error. Now I am getting a similar error which I believe is caused by spaces in my column names, my data or both. Warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "River" LINE 1: INSERT INTO leads (name) VALUES (De River) Warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "address" LINE 1: INSERT INTO leads (street address) VALUES (6 High Dr) pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "id" LINE 1: INSERT INTO leads (party id) VALUES (1076) pg_query() [function.pg-query]: Query failed: ERROR: column "astn" does not exist LINE 1: INSERT INTO leads (market) VALUES (ASTN)
  11. When I run $insertSql = "INSERT INTO leads ('$fields[$col]') VALUES ('$vars[$col]')"; $result = pg_query($conn, $insertSql); I get this error: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "'name'" LINE 1: INSERT INTO leads ('name') VALUES ('name of a person') If I print $fields[$col] no quotes are printed just the value Can anyone tell me what my syntax error is?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.