I can't insert a row into the table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aneuryzma
Forum Contributor
Posts: 106
Joined: Sat May 17, 2008 7:03 am

I can't insert a row into the table

Post by aneuryzma »

hi,

I don't understand why I can't insert a row into the table:
$con = mysql_connect("localhost","mobileApp","mobileApp");

if (!$con) {
die('Could not connect: ' . mysql_error());
}

mysql_select_db('database', $con);

//I'm sure the connection is well established because I can fetch values, however I can't insert them.

mysql_query("INSERT INTO Users (FirstName, LastName, Age)
VALUES ('pinco', 'pass1', 'pass2')"); //doesn't work, row is not added
thanks
Dodon
Forum Commoner
Posts: 64
Joined: Wed Aug 03, 2011 4:11 am
Location: Netherlands

Re: I can't insert a row into the table

Post by Dodon »

If the Age field is an Interger you can't insert a String.

What is the error you get?

What error do you get if you place the query directly into phpmyadmin?
aneuryzma
Forum Contributor
Posts: 106
Joined: Sat May 17, 2008 7:03 am

Re: I can't insert a row into the table

Post by aneuryzma »

I don't get any error. The fields are VARCHAR.. is ok ?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: I can't insert a row into the table

Post by social_experiment »

Does the username you are using have INSERT access?

Code: Select all

<?php
// try this to see if any errors are present
$qry = mysql_query("INSERT INTO Users (FirstName, LastName, Age)
VALUES ('pinco', 'pass1', 'pass2')") or die(mysql_error());
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply