Jump to content

Recommended Posts

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);

}

}
?>

Link to comment
https://forums.phpfreaks.com/topic/166523-one-variable-wont-insert-to-table/
Share on other sites

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?

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

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?

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 ?

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

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.