954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Can not insert into SQL

this is the code to email confirm. The user clicks on the link in the email, passing the code through url to this page. Then the data is transferred from a tmp table to main one.

I have queried in phpmyadmin and it works fine. But when i actually use the php i get the "else {echo "error";}" suggesting that the INSERT query is not working. Any suggestions?

include("db_config_db.php");

$code=$_GET['code'];

$sql1="SELECT * FROM table1 WHERE code ='$code'";
$result1=mysql_query($sql1);

if($result1){
$count=mysql_num_rows($result1);

if($count==1){

while($rows=mysql_fetch_array($result1)){
$username = $rows['username'];
$name = $rows['name'];
$email = $rows['email'];
$address = $rows['address'];
$city = $rows['city'];
$state = $rows['state'];
$zip = $rows['zip'];
$phone = $rows['phone'];
$birthday = $rows['birthday'];
$country = $rows['country'];
$description = $rows['description'];
$keywords = $rows['keywords'];
$setup = $rows['setup'];
}

$sql2="INSERT INTO table2 (name, email, address, city, state, zip, phone, birthday, country, description, username, code, keywords, setup)VALUES('$name', '$email', '$address', '$city', '$state', '$zip', '$phone', '$birthday', '$country', '$description', '$username', '$code', '$keywords', '$setup')";
$result2=mysql_query($sql2);

if($result2){
$sql3="DELETE FROM table1 WHERE code = '$code'";
$result3=mysql_query($sql3);
header("location:index.php");
}
else{ echo "error";
}
}
else {
echo "Wrong Confirmation code";
}
}
megachip04
Light Poster
34 posts since Jul 2011
Reputation Points: 10
Solved Threads: 1
 

Snip im an idiot.. nvm lol

G&G Designing
Junior Poster in Training
90 posts since Aug 2011
Reputation Points: 17
Solved Threads: 11
 

Not completely sure what you mean, but yes, mysql typically works. The first SELECT is working, but the INSERT INTO is not.

megachip04
Light Poster
34 posts since Jul 2011
Reputation Points: 10
Solved Threads: 1
 

Post ur html file from where u send the info......

rv1990
Junior Poster in Training
51 posts since Aug 2011
Reputation Points: 17
Solved Threads: 7
 

do use die function every mysql statement such as
mysql_query("select * from fdf) or die("not working1");
u can able to detect which function is not working....
Tell me if u find any error

rv1990
Junior Poster in Training
51 posts since Aug 2011
Reputation Points: 17
Solved Threads: 7
 

$username = $rows['username'];
$name = $rows['name'];
$email = $rows['email'];
$address = $rows['address'];
$city = $rows['city'];
$state = $rows['state'];
$zip = $rows['zip'];
$phone = $rows['phone'];
$birthday = $rows['birthday'];
$country = $rows['country'];
$description = $rows['description'];
$keywords = $rows['keywords'];
$setup = $rows['setup'];
}

make sure ur html textboxes names is same as ur given index name

ex.
$setup = $rows['setup']; =

uselessninja
Junior Poster
115 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
 

i'm not posting to the page through the form. I'm selecting them from the database

megachip04
Light Poster
34 posts since Jul 2011
Reputation Points: 10
Solved Threads: 1
 
G&G Designing
Junior Poster in Training
90 posts since Aug 2011
Reputation Points: 17
Solved Threads: 11
 

Tell me the error you get while parsing in php?

rv1990
Junior Poster in Training
51 posts since Aug 2011
Reputation Points: 17
Solved Threads: 7
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: