63227

SQL statement not deleting in PHP

Question:

echo $_POST['IDnum']; $result = pg_prepare($conn, "city_delete", "DELETE FROM lab5.city WHERE lab5.city.id = $1"); $result = pg_execute($conn, "city_delete", array($_POST['IDnum']));

This displays the correct ID number for the row to be deleted and will delete it inside PSQL, but will not delete when implemented inside the PHP? Any ideas?

Answer1:

Try this:

$result = pg_prepare($conn, "city_delete", 'DELETE FROM lab5.city WHERE lab5.city.id = $1');

The double quotes you used make the $1 a PHP variable instead of a string.

See the example for pg_prepare here: <a href="http://php.net/manual/en/function.pg-prepare.php" rel="nofollow">http://php.net/manual/en/function.pg-prepare.php</a>

Recommend

  • trying to remove and store and object with detach()
  • Managing two roles in codeigniter
  • To improve login code in PHP by Sessions
  • JPA - getting distinct value from one column
  • php regex remove digits
  • Add delivery info to query in SAP Crystal Reports
  • Update a record where _id = :id with Mongoose
  • Microsoft Excel Pivot miscalculation in Sum for positive and negative numbers
  • CSS - Cannot get one spanned style to override another inherited style and align left
  • Suppressing passwd when calling sqlplus from shell script
  • Web.config system.webserver errors
  • Is there a javascript serializer for JSON.Net?
  • Using $this when not in object context
  • Sails.js/waterline: Executing waterline queries in toJSON function of a model?
  • Deselecting radio buttons while keeping the View Model in synch
  • Why is the size of this struct 32?
  • Getting last autonumber in access
  • Counter field in MS Access, how to generate?
  • Incrementing object id automatically JS constructor (static method and variable)
  • How to check if every primary key value is being referenced as foreign key in another table
  • Where to put my custom functions in Wordpress?
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • jquery mobile loadPage not working
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • Rearranging Cells in UITableView Bug & Saving Changes
  • 0x202A in filename: Why?
  • Unanticipated behavior
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Buffer size for converting unsigned long to string
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Benchmarking RAM performance - UWP and C#
  • Angular 2 constructor injection vs direct access
  • How to stop GridView from loading again when I press back button?
  • File not found error Google Drive API
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Can't mass-assign protected attributes when import data from csv file
  • Binding checkboxes to object values in AngularJs
  • Unable to use reactive element in my shiny app