insert 1 field instead of 10??

They have: 164 posts

Joined: Nov 2001

can i insert only one field in a table which consists of 10 fields??

wat i am trying to do here is to see whether table have this record ornot??

<?php
$sql
= \"select * from biocontact where uname = '$uname'\";
$result = mysql_query($sql);
?>

if no record, insert uname to the table:

<?php
if ($result == 0)
{
   
$sql_contact = \"insert into biocontact (uname) values ('$uname')\";
   
$result_contact = mysql_query($sql_contact);

   
}
?>

the problem is, i can't seem to insert the record. wat is wrong here??

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I don't see anything wrong...

<?php
if ($result == 0) {
   
$sql_contact = \"INSERT INTO biocontact (uname) VALUES ('$uname')\";
   
$result_contact = mysql_query($sql_contact);
    if (!
$result_contact) {
        echo \"\n\n<!--\n\";
        echo \"File: \" . __FILE__ . \"\n\";
        echo \"Line: \" . __LINE__ . \"\n\n\";
        echo \"QUERY ERROR:\n\" . query_error() . \"\n\n\";
        echo \"QUERY:\n
$sql_contact\n\";
        echo \"-->\n\n\";
    }
}
?>
Does this print an error? Have you tried running the query in phpMyAdmin or at the mysql prompt?

Mark Hensler
If there is no answer on Google, then there is no question.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.