473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help with sql update

I have the following php code:
echo $iyear;

$query = "UPDATE users set
title='$ititle',
lastname='$ilastname',
firstname='$ifirstname',
middleinit='$imiddleinit',
year='$iyear',
hs_lastname='$ihs_lastname',
hs_firstname='$ihs_firstname',
street1='$istreet1',
street2='$istreet2',
city='$icity',
state='$istate',
postal='$ipostal',
country='$icountry',
share_email='$ishare_email',
occupation='$ioccupation',
marital_status='$imarital_status',
kids='$ikids',
spouse_lastname='$ispouse_lastname',
spouse_firstname='$ispouse_firstname',
spouse_middleinit='$ispouse_middleinit',
spouse_born_year='$ispouse_born_year',
phone='$iphone',
webpage='$iwebpage',
comment='$icomment'
WHERE user_name='$valid_user'";
$query_result = @mysql_query($query);
All of the $ixxxx vars are coming from a web form.

$iyear echo's correctly with what the user has entered into the forum,
however it is not updated in the table. All other fields are updated
correctly, but year is emptied.

Any ideas on where I can look?


Here is the table it's trying to update.

describe users;

MemberID int(11) PRI NULL auto_increment
user_name varchar(100)
title varchar(10)
lastname varchar(40)
firstname varchar(40)
middleinit char(1)
year int(4) YES NULL
hs_lastname varchar(40)
hs_firstname varchar(40)
street1 varchar(40)
street2 varchar(40)
city varchar(40)
state char(2)
postal varchar(9)
country char(2)
share_email char(1)
occupation varchar(100)
marital_status char(1)
kids char(1)
thenphoto varchar(200)
nowphoto varchar(200)
spouse_lastname varchar(40)
spouse_firstname varchar(40)
spouse_middleinit char(1)
spouse_born_year varchar(4)
spouse_photo varchar(200)
phone varchar(20)
webpage varchar(200)
comment text
Password varchar(40)
PassQuestion varchar(100)
LastUpdated date 0000-00-00
PassAnswer varchar(100)
Active char(1) N
ActiveCode varchar(15)

Jul 17 '05 #1
5 1280
NC
mb***@yahoo.com wrote:

I have the following php code:

$query = "UPDATE users set
title='$ititle', ... year='$iyear', ... comment='$icomment'
WHERE user_name='$valid_user'";
$query_result = @mysql_query($query);

$iyear echo's correctly with what the user has entered into
the forum, however it is not updated in the table. All other
fields are updated correctly, but year is emptied.

Any ideas on where I can look?
In the table definition:
year int(4) YES NULL


Earlier versions of MySQL interpret single quotes around
a value as an indication of that value being a text. Since
you are trying to update a numeric field, you might try to
remove single quotes around $iyear...

Cheers,
NC

Jul 17 '05 #2
No luck on that. I'll also tried converting the field to char. with
the same results.

Running: MySQL 4.1.9-standard

The edit page loads fine and displays the current year correctly. When
you submit it then displays the updated year correctly but the field
ends up empty in the database. So it is trying to store something but
failing.

Jul 17 '05 #3
NC
m...@yahoo.com wrote:

No luck on that. I'll also tried converting the field to char. with
the same results.

Running: MySQL 4.1.9-standard


OK, scratch that... There is a MySQL function called YEAR(),
so if you have a field called year, you must refer to it as
`year` (that is, include it in backticks)...

Cheers,
NC

Jul 17 '05 #4
hmm, that was probably it. I renamed the field to "classyear" and it's
working now. Thanks for the help!

Jul 17 '05 #5
mb***@yahoo.com writes:
[snip]
$query_result = @mysql_query($query);


Get rid of that @ before the above call if you want to see
error/warning messages (if any).

Then either check your error logs and/or browser window if
display_errors is ON.

--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Randy Harris | last post by:
I imported records into a table, later found out that many of them had trailing spaces in one of the fields. If I'd caught it sooner, I could have trimmed the spaces before the import. This...
10
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
1
by: Sajid | last post by:
Hello! Experts, I have the following piece of code in VB.NET that I want to use to update any records in the database. I would like to use a code as well as DataGrid to update the records....
1
by: cindy | last post by:
this is the call private void Page_Load(object sender, System.EventArgs e) { OdbcConnection connection = new OdbcConnection ("DSN=PFW52"); CreateDataAdapter(connection); } this is the code,...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
2
by: Hexman | last post by:
Hello All, Well I'm stumped once more. Need some help. Writing a simple select and update program using VB.Net 2005 and an Access DB. I'm using parameters in my update statement and when trying...
6
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
1
by: corsibu | last post by:
hello , i just wanted to ask if there's anyone who could help me do the following thing : i have an empty temporary table, this table will have a row filled with data grabbed by a querry at this...
9
by: SAL | last post by:
Hello, I have a Dataset that I have table adapters in I designed using the designer (DataLayer). I have a business logic layer that immulates the DataLayer which may/may not have additional logic...
4
by: charmeda103 | last post by:
i have this program that i am almost done with, i am one part away from being done. the last part is putting the results together; here is the results that i need to put in code. do u have any...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.