Languages :: PHP :: SQL & PHP problems. |
|||
| By: PHP newbee |
Date: 28/12/2002 00:00:00 |
Points: 100 | Status: Answered Quality : Excellent |
|
Here is the php coding. I have done. Basically what happens is a form gets submitted and this is the action page that gets loaded up after. All variables appear to get read in successfully. The problem is that is is not updating the database. I can insert and delete in the field but I can't use this line to update. It doesn't even give me a error. Can anyone help me please. ######################################## HERE ARE THE VARIABLES ############################### $id = $_POST["id"]; $info_title = $_POST["info_title"]; $info_first_name = $_POST["info_first_name"]; $info_m_name = $_POST["info_m_name"]; $info_last_name = $_POST["info_last_name"]; $info_degrees = $_POST["info_degrees"]; $info_address1 = $_POST["info_address1"]; $info_address2 = $_POST["info_address2"]; $info_city = $_POST["info_city"]; $info_province = $_POST["info_province"]; $info_postal_code = $_POST["info_postal_code"]; $info_phone_home = $_POST["info_phone_home1"].$_POST["info_phone_home2"]; $info_phone_work = $_POST["info_phone_work1"].$_POST["info_phone_work2"]; $info_phone_cell = $_POST["info_phone_cell1"].$_POST["info_phone_cell2"]; $info_phone_fax = $_POST["info_phone_fax1"].$_POST["info_phone_fax2"]; $info_email = $_POST["info_email"]; $info_webpage = $_POST["info_webpage"]; $info_comp = $_POST["info_comp"]; $info_prof = $_POST["info_prof"]; $info_market_desc = $_POST["info_market_desc"]; $info_title_1 = $_POST["info_title1"]; $info_title_2 = $_POST["info_title2"]; $info_title_3 = $_POST["info_title3"]; $info_title_4 = $_POST["info_title4"]; $info_title_5 = $_POST["info_title5"]; $info_title_6 = $_POST["info_title6"]; $info_title_7 = $_POST["info_title7"]; $info_show1 = $_POST["info_show1"]; $info_show2 = $_POST["info_show2"]; $info_show3 = $_POST["info_show3"]; $info_show4 = $_POST["info_show4"]; $info_show5 = $_POST["info_show5"]; $info_show6 = $_POST["info_show6"]; $info_show7 = $_POST["info_show7"]; $info_show8 = $_POST["info_show8"]; $info_show9 = $_POST["info_show9"]; $info_show10 = $_POST["info_show10"]; $info_show11 = $_POST["info_show11"]; $info_speak1 = $_POST["info_speak1"]; $info_speak2 = $_POST["info_speak2"]; ############################################################################################### #THIS CREATES THE SQL STATEMENT TO UPDATE THE ACCOUNT $sql = "update tblInfo "; $sql.="set info_title = '".$info_title."' , "; $sql.="info_first_name = '".$info_first_name."' , "; $sql.="info_m_name = '".$info_m_name."' , "; $sql.="info_last_name = '".$info_last_name."' , "; $sql.="info_degrees = '".$info_degrees."' , "; $sql.="info_address1 = '".$info_address1."' , "; $sql.="info_address2 = '".$info_address2."' , "; $sql.="info_city = '".$info_city."' , "; $sql.="info_province = '".$info_province."' , "; $sql.="info_postal_code = '".$info_postal_code."' , "; $sql.="info_phone_home = '".$info_phone_home."' , "; $sql.="info_phone_work = '".$info_phone_work."' , "; $sql.="info_phone_cell = '".$info_phone_cell."' , "; $sql.="info_phone_fax = '".$info_phone_fax."' , "; $sql.="info_email = '".$info_email."' , "; $sql.="info_webpage = '".$info_webpage."' , "; $sql.="info_comp = '".$info_comp."' , "; $sql.="info_prof = '".$info_prof."' , "; $sql.="info_market_desc = '".$info_market_desc."' , "; $sql.="info_title1 = '".$info_title1."' , "; $sql.="info_title2 = '".$info_title2."' , "; $sql.="info_title3 = '".$info_title3."' , "; $sql.="info_title4 = '".$info_title4."' , "; $sql.="info_title5 = '".$info_title5."' , "; $sql.="info_title6 = '".$info_title6."' , "; $sql.="info_title7 = '".$info_title7."' , "; $sql.="info_show1 = '".$info_show1."' , "; $sql.="info_show2 = '".$info_show2."' , "; $sql.="info_show3 = '".$info_show3."' , "; $sql.="info_show4 = '".$info_show4."' , "; $sql.="info_show5 = '".$info_show5."' , "; $sql.="info_show6 = '".$info_show6."' , "; $sql.="info_show7 = '".$info_show7."' , "; $sql.="info_show8 = '".$info_show8."' , "; $sql.="info_show9 = '".$info_show9."' , "; $sql.="info_show10 = '".$info_show10."' , "; $sql.="info_show11 = '".$info_show11."' , "; $sql.="info_speak1 = '".$info_speak1."' , "; $sql.="info_speak2 = '".$info_speak2."' "; $sql.="where info_id = ".$id.";"; $db = mysql_connect("localhost", "username", "password"); mysql_select_db("empinfo",$db); mysql_query($sql,$db); |
|||
| By: PHP newbee | Date: 28/12/2002 03:54:00 | Type : Comment |
|
| Here is what I have found out. If I try and submit info_comp or anything after it nothing happens. When I include info_comp then it doesn't do a update. I have checked the database and it has all those fields. Here is what I think may have happened. I had a database with 15 fields. I then altered the table started at info_comp and added all those fields. Is there something I have to do after the table has been altered for it to be recognized. This is run on mysql. |
|||
| By: VGR | Date: 28/12/2002 05:09:00 | Type : Answer |
|
| suggestion to sort things out : first do this i.s.o. your currect way : $sql.="set info_title='$info_title', info_first_name='$info_first_name', info_m_name='$info_m_name', "; // more concise, clearer too $sql.= [etc etc etc] then do this : echo "query is $sql "; mysql_query($sql); and check out (or copy-paste here, please) the correctness of the print-out. My guess is that you have numerical (non-text) fields and that you submit a request with quotes all along. Also possible is that "magic_quoting" having happened at the FORm's submission time has mangled your query with slashes, backslashes, and so on, and that the DB is choking on them. You definitely should see by yourself what's wrong by echoing the query first, then executing it. |
|||
| By: PHP newbee | Date: 28/12/2002 19:23:00 | Type : Comment |
|
| Here are the results from that query. I have checked the table and I have made everything into a text field. The only number is the id which is a primary key. All varchar are of various sizes. update tblInfo2 set info_title = 'Mr' , info_first_name = 'Mike' , info_m_name = 'T' , info_last_name = 'McDonnald' , info_degrees = 'None' , info_address1 = '333 Mains St. ,' info_address2 = '' info_city = 'Winnipeg' , info_province = 'MB' , info_postal_code = 'R2K1H4' , info_phone_home = '2045556654' , info_phone_work = '' , info_phone_cell = '' , info_phone_fax = '' , info_email = '' , info_webpage = '' , info_comp = '' , info_prof = '' , info_market_desc = '' , info_title1 = '' , info_title2 = '' , info_title3 = '' , info_title4 = '' , info_title5 = '' , info_title6 = '' , info_title7 = '' , info_show1 = '' , info_show2 = '' , info_show3 = '' , info_show4 = '' , info_show5 = '' , info_show6 = '' , info_show7 = '' , info_show8 = '' , info_show9 = '' , info_show10 = '' , info_show11 = '' , info_speak1 = '0' , info_speak2 = '0' where info_id = 3; |
|||
| By: VGR | Date: 28/12/2002 20:08:00 | Type : Comment |
|
| Is this normal ? '333 Mains St. ,' info_address2=... it should read '333 Mains St.', info_address2=... If yes, then you ***perhaps*** have encountered a built-in limitation of the DB regarding the queries' maximal length |
|||
| By: PHP newbee | Date: 29/12/2002 10:31:00 | Type : Comment |
|
| I have found the problem. The problem was actually with mysql. I created the table and fields and found out that it does not trim off the spacess before or after the column. So I thought the field was "info_comp" where it actually was "info_comp ". Notice the space at the end. I had no idea that MySQL had no error chechking for this type of thing,. |
|||
| By: VGR | Date: 30/12/2002 21:21:00 | Type : Comment |
|
| VERY surprising. I just did the test and I did not suceed in creating a column name containing a space ! that's theoretically impossible given the CREATE TABME syntax... |
|||
| By: PHP newbee | Date: 30/12/2002 21:59:00 | Type : Comment |
|
| I am very surprised my self. However the syntax for the create table is different then what i am use to. Here is how to crate the table: create table products ('mfr_id' char(3), 'product_id' varchar(20)). The variables are in quotes. Talk about very strange. |
|||
| By: VGR | Date: 30/12/2002 22:10:00 | Type : Comment |
|
| yes. You should not use quotes for column names, AFAIK |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








