help with entering info into mysql database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fipp
Forum Newbie
Posts: 9
Joined: Thu Apr 02, 2009 8:48 am

help with entering info into mysql database

Post 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";
    }
?>
 
Reviresco
Forum Contributor
Posts: 172
Joined: Tue Feb 19, 2008 4:18 pm
Location: Milwaukee

Re: help with entering info into mysql database

Post 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());
Last edited by Reviresco on Thu Apr 02, 2009 11:59 am, edited 1 time in total.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: help with entering info into mysql database

Post by Mark Baker »

INSERT INTO users (username, email, password) VALUES ('$name', '$email', '$password')
Post Reply