coutts Posted July 19, 2009 Share Posted July 19, 2009 Hello: The following code moves a series of values from one table to another table as a result of a user clicking on a link that is emailed to them (memebrship signup form) It was working , in fact it still works except it will not being the info on AGENT from the first table (and it is there) to the second table - I have looked this over for hours and cant see anything wrong - would someone have a look and see what I have missed thanks <? $con = mysql_connect("localhost","", ""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("", $con); // Passkey that got from link $passkey=$_GET['passkey']; $tbl_name1=""; // Retrieve data from table where row that match this passkey $sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'"; $result1=mysql_query($sql1); // If successfully queried if($result1){ // Count how many row has this passkey $count=mysql_num_rows($result1); // if found this passkey in our database, retrieve data" if($count==1){ $rows=mysql_fetch_array($result1); $email = $rows["EMAIL"]; $confirm_code = $rows["CONFIRM_CODE"]; $password = $rows["PASSWORD"]; $category = $rows["CATEGORY"]; $price = $rows["PRICE"]; $type = $rows["TYPE"]; $area = $rows["AREA"]; $bedrooms = $rows["BEDROOMS"]; $water = $rows["WATER"]; $land = $rows["LAND"]; $livingarea = $rows["LIVINGAREA"]; $agent = $rows["AGENT"]; $tbl_name2=""; // Insert data that retrieves from "" into table "" $sql2="INSERT INTO $tbl_name2 (EMAIL, PASSWORD, CATEGORY, PRICE, TYPE, AREA, BEDROOMS, WATER, LAND, LIVINGAREA, AGENT) VALUES ('$email', '$password', '$category', '$price', '$type', '$area', '$bedrooms', '$water', '$land', '$livingarea', '$agent')"; $result2=mysql_query($sql2); } // if not found passkey, display message "Wrong Confirmation code" else { echo "Wrong Confirmation code"; } // if successfully moved data from table"" to table "" displays message "Your account has been activated" and don't forget to delete confirmation code from table "" if($result2){ echo "Your account has been activated"; echo( $email ); // Delete information of this user from table "" that has this passkey $sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'"; $result3=mysql_query($sql3); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/ Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 did you check the column data type for the old vs. new AGENT column? Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878156 Share on other sites More sharing options...
coutts Posted July 19, 2009 Author Share Posted July 19, 2009 Hi Yes i am using varchar(50) in both cases Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878157 Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 and if you echo out $agent or $sql2 it shows the expected data? Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878161 Share on other sites More sharing options...
coutts Posted July 19, 2009 Author Share Posted July 19, 2009 No actually it doesnt - bearing in mind that this script works except that the agent variable is not inserted in the new table - I checked by echoing a varaible I nknew was working and AGENT which isnt - neither echoed Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878162 Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 well if both are not echoing that means that your script was/is not working. There's no way it would not echo but be inserted into the new table. Are you sure the data wasn't already in the new table, maybe from some previous attempt or something? Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878164 Share on other sites More sharing options...
coutts Posted July 19, 2009 Author Share Posted July 19, 2009 absolutely know it wasnt left over - i cleared both tables before starting - did the first step and it was all in the first table - used the emailed link and everything is in the second table except AGENT - i cant understand and i dont know why i cant echo out whats going on Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878166 Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 $result1=mysql_query($sql1) or die(mysql_error()); put that on your queries. Any errors show up? Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878169 Share on other sites More sharing options...
coutts Posted July 19, 2009 Author Share Posted July 19, 2009 added die to all such lines - no errors the onlyt screen output is "Your account has been activated" Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878171 Share on other sites More sharing options...
coutts Posted July 19, 2009 Author Share Posted July 19, 2009 other than not adding agent - it added all the other info from table 1 to table and deleted the line from table 1 as its supposed to Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878174 Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 so you're telling me that when you echo out any of these: $email = $rows["EMAIL"]; $confirm_code = $rows["CONFIRM_CODE"]; $password = $rows["PASSWORD"]; $category = $rows["CATEGORY"]; $price = $rows["PRICE"]; $type = $rows["TYPE"]; $area = $rows["AREA"]; $bedrooms = $rows["BEDROOMS"]; $water = $rows["WATER"]; $land = $rows["LAND"]; $livingarea = $rows["LIVINGAREA"]; $agent = $rows["AGENT"]; nothing gets echoed, and yet the data gets inserted into the table? Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878177 Share on other sites More sharing options...
coutts Posted July 19, 2009 Author Share Posted July 19, 2009 yes that is what I am saying - if nothing was getting put in the table I would nt be so confused - I have echoed these after the line that says echo "Your account has been activated" and after the block you copied above Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878178 Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 okay so humor me. If you change this: // Insert data that retrieves from "" into table "" $sql2="INSERT INTO $tbl_name2 (EMAIL, PASSWORD, CATEGORY, PRICE, TYPE, AREA, BEDROOMS, WATER, LAND, LIVINGAREA, AGENT) VALUES ('$email', '$password', '$category', '$price', '$type', '$area', '$bedrooms', '$water', '$land', '$livingarea', '$agent')"; $result2=mysql_query($sql2); } to this: // Insert data that retrieves from "" into table "" $sql2="INSERT INTO $tbl_name2 (EMAIL, PASSWORD, CATEGORY, PRICE, TYPE, AREA, BEDROOMS, WATER, LAND, LIVINGAREA, AGENT) VALUES ('$email', '$password', '$category', '$price', '$type', '$area', '$bedrooms', '$water', '$land', '$livingarea', '$agent')"; echo $sql2; $result2=mysql_query($sql2); } You're saying that the following echoes: INSERT INTO $tbl_name2 (EMAIL, PASSWORD, CATEGORY, PRICE, TYPE, AREA, BEDROOMS, WATER, LAND, LIVINGAREA, AGENT) VALUES ('', '', '', '', '', '', '', '', '', '', '')" and yet the data inserts correctly into $tbl_name2 ? Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878179 Share on other sites More sharing options...
coutts Posted July 19, 2009 Author Share Posted July 19, 2009 no thats not what i'm saying - i'm saying that I never see any response from an echo statement put in that location (and i tried it again) ie I just don't get any echo Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878182 Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 are you running the script from a browser? Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878184 Share on other sites More sharing options...
coutts Posted July 19, 2009 Author Share Posted July 19, 2009 yes - the page is called confirmation.php and a link is sent by earlier parts of the program to the email of the recipient (in this case me) so I get a link confirmation.php?passkey=sdfsdf4t65yrgdg etc. I click on this link and the required things happen minus AGENT and the script echos the usual success thing but nothing else regardless of the echo statements I insert Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878185 Share on other sites More sharing options...
PFMaBiSmAd Posted July 19, 2009 Share Posted July 19, 2009 Your code is inside of a conditional statement if($count==1){ that is FALSE. Find out why the first query is not returning exactly one row. Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878186 Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 Your code is inside of a conditional statement if($count==1){ that is FALSE. Find out why the first query is not returning exactly one row. well the query is inside that condition and he's saying it is executing and all of the data is being inserted except for that one column, so that can't be the issue. Okay so if you're 100% sure you are absolutely sure that all of the other data is being pulled from the old table and put into the new table from this script, all except for AGENT, then let's go back to just that column. So you checked the data type of the old vs. new. Spelling the same? Did you make sure you didn't accidentally set it up as some auto-populated column? Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878188 Share on other sites More sharing options...
coutts Posted July 19, 2009 Author Share Posted July 19, 2009 yes i just added AGENT varchar(50) and the latin1_general_ci as are all the other fields (well they have differnt character lenghts) - but the 2 AGENT fields in both tables are the same Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878189 Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 Think I'm about out of ideas now. Only thing I can think of is maybe your code somehow got changed since the time you posted the snippet in your OP. Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878191 Share on other sites More sharing options...
coutts Posted July 19, 2009 Author Share Posted July 19, 2009 ok i thank you for trying - it seems illogical to me - can you think of any reason why the echo statement produces nothing, even when i know that the variable being echoed must have a value Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878194 Share on other sites More sharing options...
.josh Posted July 19, 2009 Share Posted July 19, 2009 no. unless it is within something greater, like styling making it white or covering it with something. Suppose you can quickly answer that by rightclick > view source and ctrl+f'ing for it. Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878197 Share on other sites More sharing options...
coutts Posted July 19, 2009 Author Share Posted July 19, 2009 yeah i'm at a loss - i will try what usually works - go home, forget about it and come back tomorrow Thanks for your help, I appreciate that you guys really try Robert Quote Link to comment https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/#findComment-878200 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.