Page 1 of 1

help with entering info into mysql database

Posted: Thu Apr 02, 2009 8:53 am
by fipp
I am very new to all of this but man I am having fun with it. In advanced thanks for your help.

I have the below code in a file. I am not sure why it is not working. The connection is working. When I run it I get a result echoed "Entered" but the information is not in the database?


Code: Select all

 
<?php
include('dbconnection.php');
        
    //insert into users table
    $name="test";
    $email="testemail@test.com";
    $password="test123";
    
    $sql2="INSERT INTO users SET username='$name', email='$email', password='$password'";
    $result2=mysql_query(sql2);
    
    if($sql2){
        echo"Entered";
    }else{
        echo"failed";
    }
?>
 

Re: help with entering info into mysql database

Posted: Thu Apr 02, 2009 11:47 am
by Reviresco
There's a $ missing before "sql2" here:

Code: Select all

$result2=mysql_query($sql2);
This is working because you're checking the query:

Code: Select all

 
if($sql2) {
        echo"Entered";
    }
instead of the result:

Code: Select all

 
if($result2){
        echo"Entered";
    }
Also, this is helpful:

Code: Select all

$result2=mysql_query($sql2) or die(mysql_error());

Re: help with entering info into mysql database

Posted: Thu Apr 02, 2009 11:57 am
by Mark Baker
INSERT INTO users (username, email, password) VALUES ('$name', '$email', '$password')