3 Replies - 1166 Views - Last Post: 04 January 2012 - 11:11 AM Rate Topic: -----

#1 foulish121   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-January 12

PHP to MySQL table -> Inserting into wrong fields

Posted 04 January 2012 - 11:04 AM

I have created a page that allows insertation of data into a MySQL database, and for some reason it is putting it into the wrong fields (Even though I am fairly sure I have told it which fields to put it in). I suspect the problem lays with defining a primary key (Again, I am sure this is done).

I am able to add it properly though PhpMyAdmin, but the form is having none of it.


Image of PhpMyAdmin
http://imageshack.us...pmyadminqd.png/


function insert_owner($GPID, $FIRST_NAME, $LAST_NAME, $SURGERY_NAME , $SURGERY_ADDRESS)
        {
        $esc_GPID = mysql_real_escape_string($GPID, $this->conn);
        $esc_FIRST_NAME = mysql_real_escape_string($FIRST_NAME, $this->conn);
        $esc_LAST_NAME = mysql_real_escape_string($LAST_NAME, $this->conn);
        $esc_SURGERY_NAME = mysql_real_escape_string($SURGERY_NAME, $this->conn);
        $esc_SURGERY_ADDRESS = mysql_real_escape_string($SURGERY_ADDRESS, $this->conn);
        $sql="INSERT INTO GPs (GPID , FIRST_NAME, LAST_NAME, SURGERY_NAME, SURGERY_ADDRESS)
VALUES ('{$esc_GPID}','{$esc_FIRST_NAME}','{$esc_LAST_NAME}','{$esc_SURGERY_NAME}','{$esc_SURGERY_ADDRESS}')";
        $result=mysql_query($sql, $this->conn);
        if(!$result)


<?php
}
else
{
$GPID = $_POST['GPID'];
$FIRST_NAME = $_POST['FIRST_NAME'];
$LAST_NAME = $_POST['FIRST_NAME'];
$SURGERY_NAME = $_POST['SURGERY_NAME'];
$SURGERY_ADDRESS = $_POST['SURGERY_ADDRESS'];
$db1 = new GP_Information();
$db1->openDB();
$numofrows = $db1->insert_owner($GPID, $FIRST_NAME, $SURGERY_NAME, $SURGERY_ADDRESS);
echo "Success. Number of rows affected: <strong>$numofrows<strong>";
$db1->closeDB();
}
?>


Sorry, forgot to mention (And couldn't find an ediot button. Doh!)

Top segment of code is from a document called GP_Information, bottom segment of code is from a document called GP_Information_Update

Is This A Good Question/Topic? 0
  • +

Replies To: PHP to MySQL table -> Inserting into wrong fields

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4297
  • View blog
  • Posts: 13,637
  • Joined: 08-June 10

Re: PHP to MySQL table -> Inserting into wrong fields

Posted 04 January 2012 - 11:06 AM

in the first block there are 5 function parameters, in the second block there are only 4. if that’s the same function, PHP should error out.

This post has been edited by Dormilich: 04 January 2012 - 11:09 AM

Was This Post Helpful? 1
  • +
  • -

#3 foulish121   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-January 12

Re: PHP to MySQL table -> Inserting into wrong fields

Posted 04 January 2012 - 11:10 AM

View PostDormilich, on 04 January 2012 - 11:06 AM, said:

in the first block there are 5 function parameters, in the second block there are only 4. if thatís the same function, PHP should error out.


>:@ I'm really annoyed with myself. Thank you very much!
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6260
  • View blog
  • Posts: 24,029
  • Joined: 23-August 08

Re: PHP to MySQL table -> Inserting into wrong fields

Posted 04 January 2012 - 11:11 AM

YOUR LOVE OF ALL CAPS MAKES YOUR CODE VERY DIFFICULT TO READ!!!!

Caps should be reserved for constants.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1