Jump to content

PHP can't insert data in MySQL but can Select


jwpryor

Recommended Posts

We have had to recreate our server when the original went down and have moved all of our databases and websites over to the new server.

 

I have recreated multiple databases and all but one works just fine - I can select, update, insert on all the database, etc.

 

EXCEPT FOR 1 DATABASE:

---If I'm in one of the MySQL GUI (like SQLYog or MySQL Admin), I can insert a record just fine.

---BUT, when I try to use a php file to insert a record, it dies and will never insert it. I really don't think there is an error in the php (it worked fine on the old server).

 

I have even totally recreated the database by manually recreating the tables and used Insert statements within MySQL GUI to bring in the data.

 

 

Any ideas on what to look for?

Why would the php be able to execute a Select statement, but not an Insert in the MySQL?

Is this a php issue, MySQL, or Web Site issue?

 

Thank you.

Julia

 

ADDITIONAL DETAILS

PHP 5

MySQL 5

Windows server

IIS

Grant on the user/password I'm using in the PHP allows everything but Grant permission

Link to comment
Share on other sites

Here is the code I'm using to Insert a record:

---------------------------

$hostname_connFLRW = "wql2";

$database_connFLRW = "mydb";

$username_connFLRW = "yser1";

$password_connFLRW = "slkdi22";

$connFLRW = mysql_connect($hostname_connFLRW, $username_connFLRW, $password_connFLRW) or die(mysql_error());

 

 

$updateSQL = "Insert INTO enrollment (firstName, lastName, tier1,area,relationship,employeeId,userName,password,ssnIdflag, dateReg, tier1ID, tier2ID )VALUES ('$firstName', '$lastName', '$tier1', '$area', '$relationship', '$employeeId', '$userName', '$password', '$ssnIdflag', $tempDateCreated,$tier1ID, $tier2ID)";

 

mysql_select_db($database_connFLRW, $connFLRW);

 

$ResultInsEnr = mysql_query($updateSQL, $connFLRW) or die(mysql_error());

 

------------------Here is an example of one of the Insert statements with the actual values

Insert INTO enrollment (firstName, lastName, tier1,area,relationship,employeeId,userName,password,ssnIdflag, dateReg, tier1ID, tier2ID )VALUES ('test', 'test5432', 'CC', 'BCC', '', '111111111', 'ttest54321111', '111111111', '1', 20071009,000001, 000028)

 

 

Link to comment
Share on other sites

Are you getting any error? Your query needs a bit of cleaning up, try...

 

$updateSQL = "INSERT INTO enrollment (firstName, lastName, tier1,area,relationship,employeeId,userName,`password`,ssnIdflag, dateReg, tier1ID, tier2ID ) VALUES ('$firstName', '$lastName', '$tier1', '$area', '$relationship', '$employeeId', '$userName', '$password', '$ssnIdflag', $tempDateCreated,$tier1ID, $tier2ID)";

Link to comment
Share on other sites

No, I am not getting an error - just when the mysql_query with the (Insert) is executed, the query dies.

If I remove the "or die(mysql_error())" at the end of the mysql_query, the result  doesn't return anything (see variable

$ResultInsEnr).

 

I don't see any difference in the code I was sent except for an extra set of single quotes around one of the fields (password) and capitalizing the "INSERT" word. (I've inserted both below again). I have made those changes and no difference.

 

NOTE again: that I can use this INSERT INTO statement within SQLYog or another MySQL GUI and it works fine.

Just when it is executed within a php script does it not work - and no error is returned.

Julia

 

Original code

$updateSQL = "Insert INTO enrollment (firstName, lastName, tier1,area,relationship,employeeId,userName,password,ssnIdflag, dateReg, tier1ID, tier2ID )VALUES ('$firstName', '$lastName', '$tier1', '$area', '$relationship', '$employeeId', '$userName', '$password', '$ssnIdflag', $tempDateCreated,$tier1ID, $tier2ID)";

Code sent by thorpe

$updateSQL = "INSERT INTO enrollment (firstName, lastName, tier1,area,relationship,employeeId,userName,`password`,ssnIdflag, dateReg, tier1ID, tier2ID ) VALUES ('$firstName', '$lastName', '$tier1', '$area', '$relationship', '$employeeId', '$userName', '$password', '$ssnIdflag', $tempDateCreated,$tier1ID, $tier2ID)";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.