|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
need help with php db function
hi all,
i'm an asp developer, but as a favor to friends i'm developing a content management sytem for their bookstore in php. i'm a newbie to this programming language so i hope someone will help me. basically i have a functions in asp which performs a sql inserts and updates regardless of which form submitted the information. i'm hoping i could get some direction on how to convert these functions to php. i stumbling on the $http_post_vars which i know is the rough equivalent to asp's request.form. however, i can't find any documentation on the equivalent of the full request.form collection, ie request.form.count, request.form.key, request.form.item. i've posted the asp update function below, any advice would be greatly appreciated. Code:
function sqlUpdate(table_name,column_name,condition) sqlUpdate = "UPDATE " & table_name & " SET " for x = 1 to request.form.count fieldname = request.form.key(x) sqlUpdate = sqlUpdate & fieldname & " = " fieldvalue = request.form.item(x) fieldvalue = "'" & replace(replace(replace(replace(replace(replace _ (fieldvalue,"!","!"),"%","%"), _ ";",";"),"<","<"),">",">" ),"'","'") & "'" & ", " sqlUpdate = sqlUpdate & fieldvalue next sqlUpdate = StrReverse(sqlUpdate) sqlUpdate = StrReverse(Replace(sqlUpdate, ",", " ",1,1)) sqlUpdate = sqlUpdate & " WHERE " & column_name & " = " & condition & "" end function sTablename = "entries" sColumnname = "entry_id" sCondition = id sqlEdit = sqlUpdate(sTablename, sColumnname, sCondition) set rsEdit = cnnDataConn.execute(sqlEdit) thanx |
|
#2
|
||||
|
||||
|
Try something like the following:
PHP Code:
The list($k,$v)=each($array) bit iterates through the array and sets $k and $v to the key and the value for each iteration. It should be pretty easy to find equivalent logic in PHP to do the rest of what you're doing. |
|
#3
|
||||
|
||||
|
There's also my favourite:
PHP Code:
PHP Manual Reference: http://www.php.net/foreach |
|
#4
|
|||
|
|||
|
an-ath, please post back whether the solutions worked, did not work, or if you need more clarification.
Thanks,
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
|
#5
|
|||
|
|||
|
hi again,
sorry i didn't post back sooner. the solutions posted do work, and I thank everyone for their assistance. i was just a little embarassed to post back because i'm getting a sql error. here is the code i constructed for test purposes: PHP Code:
and here is the output: Code:
UPDATE cds SET title = 'Kind of Blue', artist = 'Miles Davis Quintet', year = '1956', WHERE id = '8' Error 1064 : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id = '8'' at line 1 after doing a google search, i've run the query with and without $id single quoted, with and without the single quotes escaped. the same error persists. can't believe i'm this close and i can't make it work. |
|
#6
|
||||
|
||||
|
the problem relates to how you're concatonating the comma onto the different fields...
if you notice in your SQL string, there's a comma before the WHERE clause... One of the ways I've dealt with this in the past is by switching thigns around a bit... PHP Code:
I haven't tested this code exactly (just typing it out on the fly), but I believe it should work. |
|
#7
|
|||
|
|||
|
doh, the comma! you just can't put a value on another pair of eyes looking at the code.
your solution works great. thanks again for your help, for everyone's help. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > need help with php db function |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|