MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 16th, 2008, 07:18 AM
fleppar fleppar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 29 fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 10 h 26 m 39 sec
Reputation Power: 0
Question Update All Records in a Row - Query Help

I first have a page with 80 fields the user types in, then they can run a search on all entries, and then click a button to modify any one user. The "update page" runs by inserting all data from the database in to text fields and then the user can click "Submit Changes" to update all the fields. I need help with the query used to run the update - I think I may be close but I'm still getting errors, and I'm really not sure why.

PHP Code:
 $sql "update student set
(stuf_name,
stul_name,
stum_name,
stu_addy,
stu_addy2,
info_other,
info_moreschools,
info_pc,
info_release,
info_register) = 
(\"$stuf_name\",
\"$stul_name\",
\"$stum_name\",
\"$stu_addy\",
\"$stu_addy2\",
\"$info_other\",
\"$info_moreschools\",
\"$info_pc\",
\"$info_release\",
\"$info_register\") where hid_stuuser = $user"



Now I have about 70 more fields but I didn't write them all for simplicity purposes (and I dont think the error is in the fields). Thanks a lot guys!

Reply With Quote
  #2  
Old July 16th, 2008, 07:32 AM
NimirRamon NimirRamon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 21 NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 17 h 27 m 18 sec
Reputation Power: 0
Try the ansi correct update syntax

Update student
SET stuf_name= \"$stuf_name\",
stul_name= \"$stul_name\",
.
.
.
.
Where .....

plus maybe enclose your
where clause hid_stuuser = \"$user\"


EDIT:: I hope your stripping out special characters, you have potential for an SQL-injection attack here.

If your using MS SQL (or a database that supports them) use stored procedures where possible

Reply With Quote
  #3  
Old July 16th, 2008, 07:58 AM
fleppar fleppar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 29 fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 10 h 26 m 39 sec
Reputation Power: 0
The fix worked, for whatever reason I didn't think I had to go column by column and that I chould shortcut it like that.

Please read my PM when you get a second also - thanks a lot for the help.

Reply With Quote
  #4  
Old July 16th, 2008, 07:59 AM
r937's Avatar
r937 r937 is online now
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,919 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 12 h 51 m 6 sec
Reputation Power: 1018
it's probably mysql, not ms sql, because of the doublequotes used to delimit strings

only mysql allows that nonsense

__________________
r937.com | rudy.ca

Reply With Quote
  #5  
Old July 16th, 2008, 08:13 AM
fleppar fleppar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 29 fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 10 h 26 m 39 sec
Reputation Power: 0
Quote:
Originally Posted by r937
it's probably mysql, not ms sql, because of the doublequotes used to delimit strings

only mysql allows that nonsense



I'm using MSSQL and PHP but everything I learned is from a MYSQL book. I basically came into a situation where MSSQL server was already installed, I had no background experience using it really, and then I was asked to create a web interface to add, delete, modify, etc to our records. If I'm running into security problems and this form needs to be internal only - I couldn't imagine that being a problem.

So everything I'm learning is pretty much on the fly, and I want to give big props to this community for all the help.

Reply With Quote
  #6  
Old July 16th, 2008, 08:19 AM
r937's Avatar
r937 r937 is online now
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,919 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 12 h 51 m 6 sec
Reputation Power: 1018
Quote:
Originally Posted by fleppar
I'm using MSSQL and PHP but everything I learned is from a MYSQL book.
you'll have to unlearn a whole bunch of stuff that mysql does wrong

starting with the proper way to delimit strings

Reply With Quote
  #7  
Old July 16th, 2008, 08:32 AM
fleppar fleppar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 29 fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 10 h 26 m 39 sec
Reputation Power: 0
Quote:
Originally Posted by r937
you'll have to unlearn a whole bunch of stuff that mysql does wrong

starting with the proper way to delimit strings


So in short, you’re saying it's time I invest a little money into amazon.com. MSSQL for Dummies for Dummies any one?

If you know any good books for beginners let me know - I wouldn't mind getting in to this stuff and trying to learn it legitimately.

Reply With Quote
  #8  
Old July 16th, 2008, 08:38 AM
r937's Avatar
r937 r937 is online now
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,919 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 12 h 51 m 6 sec
Reputation Power: 1018
you won't need a book if you've already learned sql via mysql

yes, there are many subtle differences in the dialects of mysql's sql and mssql's sql (that's the beauty of standards -- there are so many to choose from)

looking stuff up in da mssql manual (Books OnLine, or BOL as it is affectionately known) is probably all you need

Reply With Quote
  #9  
Old July 16th, 2008, 08:46 AM
fleppar fleppar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 29 fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 10 h 26 m 39 sec
Reputation Power: 0
Quote:
Originally Posted by r937
you won't need a book if you've already learned sql via mysql

yes, there are many subtle differences in the dialects of mysql's sql and mssql's sql (that's the beauty of standards -- there are so many to choose from)

looking stuff up in da mssql manual (Books OnLine, or BOL as it is affectionately known) is probably all you need


I think saying I've already learned SQL via mysql is a long strech. I know the very basics - but really wouldnt mind getting into advanced basics and then maybe some intermediate things.

I see these references to BOL all the time, and I'm guessing you guys mean the MSDN SQL Server Dev site? It's the only site I could Google that made any sense. I really wouldn't mind getting a couple books for learning and reference though - maybe a PHP/SQL book or something. If you have anything in mind let me know, and again thanks for all the help.

Reply With Quote
  #10  
Old July 16th, 2008, 09:06 AM
r937's Avatar
r937 r937 is online now
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,919 r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level)r937 User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 12 h 51 m 6 sec
Reputation Power: 1018
if you're using SQL Server in any form (except perhaps the free version), BOL comes with the install, look around on your hard drive

Sam's Teach Yourself SQL in 10 Minutes (LOL!!!) is actually pretty good

O'Reilly's SQL pocket guide is also good

Reply With Quote
  #11  
Old July 16th, 2008, 09:46 AM
NimirRamon NimirRamon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 21 NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 17 h 27 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by fleppar
The fix worked, for whatever reason I didn't think I had to go column by column and that I chould shortcut it like that.

Please read my PM when you get a second also - thanks a lot for the help.


Err I've read the PM but currently cant reply to them as I don't have enough posts made here. I'll write something up later regarding it.

As for general database advice ..... dont do what I did about 30 minutes ago and truncate a live table ... Thank goodness for backups

EDIT :: Yes I know I should of been using transactions and wasn't, though I thought I was on the Dev system at the time.

Reply With Quote
  #12  
Old July 16th, 2008, 11:00 AM
fleppar fleppar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 29 fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level)fleppar User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 10 h 26 m 39 sec
Reputation Power: 0
Quote:
Originally Posted by NimirRamon
Err I've read the PM but currently cant reply to them as I don't have enough posts made here. I'll write something up later regarding it.

As for general database advice ..... dont do what I did about 30 minutes ago and truncate a live table ... Thank goodness for backups

EDIT :: Yes I know I should of been using transactions and wasn't, though I thought I was on the Dev system at the time.


And I'm taking advice from this guy? hah thanks for the help.

One more question, then I'm done honestly. I need a query that does four things.
First Name = Frank
Last Name = Leppar
User ID = 300503

I need a fourth field that grabs the fi of first name, fi of last name, makes them both lower case, and then combines it with the student id:

eq: fl300503

Not hard right?

*Edit* - I apologize on this one but I have no idea where to even get started on this. Again this is on a PHP site so I'm sure that will help.

Reply With Quote
  #13  
Old July 16th, 2008, 11:04 AM
NimirRamon NimirRamon is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 21 NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level)NimirRamon User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 17 h 27 m 18 sec
Reputation Power: 0
Quote:
Originally Posted by fleppar
And I'm taking advice from this guy? hah thanks for the help.

One more question, then I'm done honestly. I need a query that does four things.
First Name = Frank
Last Name = Leppar
User ID = 300503

I need a fourth field that grabs the fi of first name, fi of last name, makes them both lower case, and then combines it with the student id:

eq: fl300503

Not hard right?



Ok About to leave for the day so I dont have time to work out the exact syntax, but it should be something like

LOWER(SUBSTRING(0,1,[First Name]) + LOWER(SUBSTRING(0,1,[Last Name]) + [User ID]

Where the items in [] are the fields, check the substring syntax on BOL though

Reply With Quote