Insert into

Sorry to be back so soon :frowning:

I cant seem to get some variables collected from $_GET method into my DB, I think its to do with my string but could be some UTF8 thing, Ive tried a lot more than below.

[php]<?php
$user = $_GET[‘user’];
$code = $_GET[‘code’];// not a password
$type = $_GET[‘type’];
$email = $_GET[‘email’];
echo $user;
echo $code;// these all show up fine
echo $type;
echo $email;

$con = mysql_connect(“localhost”,“user”,“pass”);
if (!$con)
{
echo ‘error 2’;
exit;
}

$db = mysql_select_db(“mydb”,$con);
if (!$db)
{
echo ‘error 3’;
mysql_close($con);
exit;
}

$string = “INSERT INTO mytbl (user,code,type,email) VALUES ($user,$code,$type,$email)”
$query = mysql_query($string,$con);

//$query = mysql_query( “INSERT INTO mytbl (user,code,type,email) VALUES ($user,$code,$type,$email)”,$con);
//the above wont work either

//$query = mysql_query( “INSERT INTO mytbl (user,code,type,email) VALUES (‘user’,‘code’,‘type’,‘email’)”,$con);
//the above does

if (!$query)
{
echo ‘error 4’;
mysql_close($con);
exit;
}

mysql_close($con);
echo ‘success’;
?>[/php]

Any advice very welcome.

no matter, I got it

[php]$string = “INSERT INTO mytbl (user,code,type,email) VALUES (’$user’,’$code’,’$type’,’$email’)”;
$query = mysql_query($string,$con);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service