What I'm trying to do is turn the output:
firstlastemailcountryaddressgender
into a MySQL INSERTable statement... Here is my code so far
if ($newuser) {
$query = mysql_query("select * from reg") or die (mysql_error());
$num = mysql_num_fields($query);
$num = $num - 1;
$i=1;
while ($i <= $num) {
$output = mysql_field_name($query, $i);
$extra1 = "$output, ";
$extra2 = "'\$$output', ";
$i++;
$output1 = $output1.$extra1;
$output2 = $output2.$extra2;
}
$extra2 = "--";
$output1 = $output1.$extra2;
$output2 = $output2.$extra2;
$output1 = ereg_replace(", --", " ", $output1);
$output2 = ereg_replace(", --", " ", $output2);
$sql= "INSERT INTO reg ($output1) VALUES ($output2)";
$query = mysql_query($sql) or die (mysql_error());
if ($query) {
echo "Registration Successful";
exit;
} else {
echo "Registration could not finish";
exit;
}
if i echo all my strings during the process i get these:
$sql = INSERT INTO reg (first, last, email, country, address, gender ) VALUES ('$first', '$last', '$email', '$country',
'$address', '$gender' )
$output1 = first, last, email, country, address, gender
$output2 = '$first', '$last', '$email', '$country', '$address', '$gender'
If i take the echod $sql from my html browser and paste it into my
code instead of... $sql= "INSERT INTO reg ($output1) VALUES ($output2)";
everything works! but my current code write to the database like this:
id first last email country address gender
Edit Delete 29 $first $last $email $c $address $gend
So after countless hours of messing around with quotes and .'s I
believe that my $'s are not recognized as real variables but maybe
under some other ascii code or somethin (dont know to much about it)