We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Cant insert values into mySQL using php

Hi all...

Im having some trouble inserting values to my mySQL database.
I have the following installed on my local system.

MySQL
Server: localhost via TCP/IP
Server version: 5.1.43-community
Protocol version: 10
User: root@localhost
MySQL charset: UTF-8 Unicode (utf8)
Web server
Apache/2.2.14 (Win32) PHP/5.2.12
MySQL client version: 5.0.51a
PHP extension: mysql
phpMyAdmin
Version information: 3.2.5

COMPUTER

Windows 7 Home Premium

System
--------------------------------------------------------------------------------

Manufacturer Hewlett-Packard
Model HP Pavilion dv6 Notebook PC
Total amount of system memory 4.00 GB RAM
System type 64-bit operating system
Number of processor cores 2

Storage
--------------------------------------------------------------------------------

Total size of hard disk(s) 466 GB
Disk partition (C:) 388 GB Free (452 GB Total)
Disk partition (D:) 2 GB Free (13 GB Total)
Disk partition (E:) 92 MB Free (99 MB Total)
Media drive (F:) CD/DVD

Graphics
--------------------------------------------------------------------------------

Display adapter type Intel(R) Graphics Media Accelerator HD
Total available graphics memory 1696 MB
Dedicated graphics memory 32 MB
Dedicated system memory 32 MB
Shared system memory 1632 MB
Display adapter driver version 8.15.10.1968
Primary monitor resolution 1366x768
Secondary monitor resolution 1280x1024
DirectX version DirectX 10

Network
--------------------------------------------------------------------------------

Network Adapter Intel(R) WiFi Link 1000 BGN

I can connect to the database fine.
I can select data and display it on any page with no problems.
I can even update an entry in the database from php.
I can insert, update, delete, and do any normal function from phpMyAdmin.

The problem comes when I try to insert a new set of values in a table that exists using PHP.

This is the code im using.

<?php
$con = mysql_connect("localhost","username","pass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("thisismydb", $con);

mysql_query("INSERT INTO news (date, title, suredel) VALUES ('2010-02-12','test','89339')");

mysql_close($con);
?>

Again.. I want to stress the fact that I can use the exact same info above to view and update data in the database.

The above code works fine if I use it on my hosted .com

Ive tried to come at this thing from every direction I can think of with no luck..

any help would be very appreciated.

Thanks so much,
LTT

3
Contributors
4
Replies
10 Hours
Discussion Span
3 Years Ago
Last Updated
6
Views
LTT
Newbie Poster
13 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Hi,
My suggestion is simple and may u feel silly too.But just try it .

mysql_query("INSERT INTO news (date, title, suredel) VALUES ('2010-02-12','test','89339')",$con);


Thank you,
prem2

prem2
Posting Whiz in Training
228 posts since Feb 2010
Reputation Points: 8
Solved Threads: 4
Skill Endorsements: 0

Nope... that didnt solve it..

LTT
Newbie Poster
13 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Use mysql_error() to identify the error in the following way.

mysql_query("INSERT INTO news (date, title, suredel) VALUES ('2010-02-12','test','89339')") or die ("Error in query. Error: ".mysql_error());
mwasif
Posting Whiz
315 posts since Dec 2007
Reputation Points: 29
Solved Threads: 48
Skill Endorsements: 0

Duplicate

mwasif
Posting Whiz
315 posts since Dec 2007
Reputation Points: 29
Solved Threads: 48
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0893 seconds using 2.69MB