Jump to content

[SOLVED] Unknown column in 'where clause' error


mikebyrne

Recommended Posts

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.

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']"; 

} 
}
?> 

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)

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

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

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

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

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

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

 

 

I'VE GOT IT WORKING NOW THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  ;D

 

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 />"; 
} 
}
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.