PFMaBiSmAd Posted November 29, 2007 Share Posted November 29, 2007 The table name in the query is enclosed in single-quotes, making it a literal string, not a table name, even if the variable contained the correct name. Putting error checking on the mysql_query() will help find why the query is failing. The code is currently blindly continuing execution of the loop with the mysql_fetch_array() in it even though the query failed due to a syntax error or a problem with the database connection. Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-401935 Share on other sites More sharing options...
mikebyrne Posted November 29, 2007 Author Share Posted November 29, 2007 I'm getting the error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\confirm.php on line 26 with the code <?php include('config.php'); $passkey=$_GET['passkey']; // Passkey that got from link ## added here if (!isset($_GET['passkey'])) { echo "Error here :: PASSKEY NOT FOUND "; } else { ## table name $tbl_name="temp_users"; // after connecting succesfully: $query = "SELECT * FROM '$tbl_name'"; $result = mysql_query($query) or die(mysql_error()); // while there is a result, fetch it into an array... while ($row = mysql_fetch_array($result)) { echo "$row['address']"; echo "$row['address1']"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402199 Share on other sites More sharing options...
adam291086 Posted November 29, 2007 Share Posted November 29, 2007 echo "$row['address']"; echo "$row['address1']"; change to echo "$row[address]"; echo "$row[address1]"; Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402200 Share on other sites More sharing options...
mikebyrne Posted November 29, 2007 Author Share Posted November 29, 2007 just change that Getting the errror 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 ''temp_users'' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402207 Share on other sites More sharing options...
PFMaBiSmAd Posted November 29, 2007 Share Posted November 29, 2007 Remove the single-quotes from around the table name in the query, like you were previously told. Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402211 Share on other sites More sharing options...
revraz Posted November 29, 2007 Share Posted November 29, 2007 $query = "SELECT * FROM '$tbl_name'"; to $query = "SELECT * FROM $tbl_name"; Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402213 Share on other sites More sharing options...
mikebyrne Posted November 29, 2007 Author Share Posted November 29, 2007 It gives me 1299fe5f959effd9d59d5g9d5g91299fe5f959effd9d59d5g9d5g91299fe5f959effd9d59d5g9d5g91299fe5f959effd9d59d5g9d5g91299fe5f959effd9d59d5g9d5g91299fe5f959effd9d59d5g9d5g9444445klgklklklkghfgfgfgfyrtrt dgcb,jkuiuyiyutggrtjyjyjtjyhtjhjhgrtjyjyjtjyhtjhjhmhjkuou4e64er4rjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkssssssssssssssssssssssssssssssssssssssssss which seems to be Address + Address1 in a loop THINK WERE GETTING SOMEWHERE!! (What I originally want to do was post the values over from temp_users to users once the confirmation email is clicked) Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402219 Share on other sites More sharing options...
revraz Posted November 29, 2007 Share Posted November 29, 2007 Put a <br /> inbetween your echos. Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402228 Share on other sites More sharing options...
mikebyrne Posted November 29, 2007 Author Share Posted November 29, 2007 put a in between the echos?? Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402289 Share on other sites More sharing options...
revraz Posted November 29, 2007 Share Posted November 29, 2007 Bah, i didnt use code tags put a <br /> between echos echo "$row[address]<br />"; echo "$row[address1]<br />"; Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402295 Share on other sites More sharing options...
mikebyrne Posted November 29, 2007 Author Share Posted November 29, 2007 Ok so at leasst we know we can see the varibles!! Now how can i just show the ones specific to the confirmation code rather then looping everyting?? If i can get this bit then all i have to do is pass the varible to the users table Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402300 Share on other sites More sharing options...
mikebyrne Posted November 29, 2007 Author Share Posted November 29, 2007 I've change the SQL to $query = "SELECT * FROM $tbl_name WHERE confirm_code ='$passkey'"; This brings up the correct figures! If i wanted to then post them to the Users table what would the code be? Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402309 Share on other sites More sharing options...
revraz Posted November 29, 2007 Share Posted November 29, 2007 Which items did you want to pass to the new table? Right now you are selecting all columns. Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402313 Share on other sites More sharing options...
mikebyrne Posted November 29, 2007 Author Share Posted November 29, 2007 I think this code should do it but where would I place it? $sql="INSERT INTO $tbl_name2(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password)VALUES('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')"; $result=mysql_query($sql)or die(mysql_error()); I'd have to also put in $tbl_name2="users"; Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402319 Share on other sites More sharing options...
mikebyrne Posted November 29, 2007 Author Share Posted November 29, 2007 With this code <?php include('config.php'); $passkey=$_GET['passkey']; // Passkey that got from link ## added here if (!isset($_GET['passkey'])) { echo "Error here :: PASSKEY NOT FOUND "; } else { ## table name $tbl_name="temp_users"; $tbl_name2="users"; // after connecting succesfully: $query = "SELECT * FROM $tbl_name WHERE confirm_code ='$passkey'"; $result = mysql_query($query) or die(mysql_error()); $sql="INSERT INTO $tbl_name2(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password)VALUES('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')"; $result=mysql_query($sql)or die(mysql_error()); // while there is a result, fetch it into an array... while ($row = mysql_fetch_array($result)) { echo "$row[address]<br />"; echo "$row[address1]<br />"; } } ?> I get the following error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\confirm.php on line 28 Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402380 Share on other sites More sharing options...
mikebyrne Posted November 29, 2007 Author Share Posted November 29, 2007 The SQL for the table I'm trying to post to is: CREATE TABLE `users` ( `id` int(4) NOT NULL auto_increment, `name` varchar(65) NOT NULL default '', `address` varchar(65) NOT NULL default '', `address1` varchar(65) NOT NULL default '', `address2` varchar(65) NOT NULL default '', `address3` varchar(65) NOT NULL default '', `address4` varchar(65) NOT NULL default '', `county` varchar(25) NOT NULL default '', `zip` varchar(65) NOT NULL default '', `telephone` varchar(25) NOT NULL default '', `email` varchar(25) NOT NULL default '', `username` varchar(65) NOT NULL default '', `password` varchar(15) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=latin1; The code I have now is: <?php include('config.php'); $passkey=$_GET['passkey']; // Passkey that got from link ## added here if (!isset($_GET['passkey'])) { echo "Error here :: PASSKEY NOT FOUND "; } else { ## table name $tbl_name="temp_users"; $tbl_name2="users"; // after connecting succesfully: $query = "SELECT * FROM $tbl_name WHERE confirm_code ='$passkey'"; $result = mysql_query($query) or die(mysql_error()); $sql="INSERT INTO $tbl_name2(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password)VALUES('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')"; $result2=mysql_query($sql)or die(mysql_error()); // while there is a result, fetch it into an array... while ($row = mysql_fetch_array($result)) { echo "$row[address]<br />"; echo "$row[address1]<br />"; } } ?> The output is: Test:Address1 Test:Address2 It all seems to work ok but its not PASSING INFO INTO THE "USERS" Table Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402408 Share on other sites More sharing options...
revraz Posted November 29, 2007 Share Posted November 29, 2007 Move $sql="INSERT INTO $tbl_name2(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password)VALUES('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')"; $result2=mysql_query($sql)or die(mysql_error()); and put it in your while loop I'm glad you caught that you had to change $result to $result2 Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402427 Share on other sites More sharing options...
mikebyrne Posted November 29, 2007 Author Share Posted November 29, 2007 The only value that passes to the "user" table is the username. The id field increments each time i click on the confirmation so its as if blank fields are being passed Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402436 Share on other sites More sharing options...
revraz Posted November 29, 2007 Share Posted November 29, 2007 You need to either make $name = $row[address] each time or set your VALUES to the $row array. Right now your variables are empty. Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402449 Share on other sites More sharing options...
mikebyrne Posted November 29, 2007 Author Share Posted November 29, 2007 I've changed it to <?php include('config.php'); $passkey=$_GET['passkey']; // Passkey that got from link ## added here if (!isset($_GET['passkey'])) { echo "Error here :: PASSKEY NOT FOUND "; } else { ## table name $tbl_name="temp_users"; $tbl_name2="users"; // after connecting succesfully: $query = "SELECT * FROM $tbl_name WHERE confirm_code ='$passkey'"; $result = mysql_query($query) or die(mysql_error()); // while there is a result, fetch it into an array... while ($row = mysql_fetch_array($result)) { $sql="INSERT INTO $tbl_name2(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password)VALUES('".$row['name'] . "', '".$row['name'] . "', '".$row['address'] . "', '".$row['address1'] . "', '".$row['address2'] . "', '".$row['address3'] . "', '".$row['address4'] . "', '".$row['county'] . "', '".$row['zip'] . "', '".$row['telephone'] . "', '".$row['email'] . "', '".$row['username'] . "', '".$row['password'] . "')"; $result2=mysql_query($sql)or die(mysql_error()); echo "$row[address]<br />"; echo "$row[address1]<br />"; echo "$row[name]<br />"; echo "$row[password]<br />"; } } ?> But now im getting the error Column count doesn't match value count at row 1 Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402488 Share on other sites More sharing options...
mikebyrne Posted November 29, 2007 Author Share Posted November 29, 2007 I'VE GOT IT WORKING NOW THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! The code was <?php include('config.php'); $passkey=$_GET['passkey']; // Passkey that got from link ## added here if (!isset($_GET['passkey'])) { echo "Error here :: PASSKEY NOT FOUND "; } else { ## table name $tbl_name="temp_users"; $tbl_name2="users"; // after connecting succesfully: $query = "SELECT * FROM $tbl_name WHERE confirm_code ='$passkey'"; $result = mysql_query($query) or die(mysql_error()); // while there is a result, fetch it into an array... while ($row = mysql_fetch_array($result)) { $sql="INSERT INTO $tbl_name2(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password)VALUES('".$row['name'] . "', '".$row['address'] . "', '".$row['address1'] . "', '".$row['address2'] . "', '".$row['address3'] . "', '".$row['address4'] . "', '".$row['county'] . "', '".$row['zip'] . "', '".$row['telephone'] . "', '".$row['email'] . "', '".$row['username'] . "', '".$row['password'] . "')"; $result2=mysql_query($sql)or die(mysql_error()); echo "$row[address]<br />"; echo "$row[address1]<br />"; echo "$row[name]<br />"; echo "$row[password]<br />"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402494 Share on other sites More sharing options...
revraz Posted November 30, 2007 Share Posted November 30, 2007 Nice job Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402527 Share on other sites More sharing options...
dewey_witt Posted November 30, 2007 Share Posted November 30, 2007 <?php $sql1="SELECT * FROM ".$tbl_name." WHERE confirm_code='".$passkey."'"; ?> Maybe thats the issue, Im not sure but that the only part looks wrong. Quote Link to comment https://forums.phpfreaks.com/topic/79238-solved-unknown-column-in-where-clause-error/page/2/#findComment-402554 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.