 |
|
|
03-06-2005, 12:51 PM
|
N00b problem
|
Posts: 7
|
PHP Code:
<?php
include "logindb.php";
$sql_table = "demo";
$sql = "INSERT into demo (fname, lname, email, sadrs, city, state, zip, phone, demo) VALUES('$fname', '$lname', '$email', '$sadrs', '$city', '$state', $zip', '$phone', '$demo')";
?>
I am real n00b when it comes to inserting info into the database. That code doesn't seem to put anything in the database. I have a table called demo, and everything in logindb.php is correct. I have all the fields in the databse correct, so I would guess that something is wrong with the code.
|
|
|
|
03-06-2005, 12:55 PM
|
|
Posts: 3,189
|
Are you executing the query anywhere? All I see above is an include and two variables. Nothing that would execute the mysql query. In other words, are you using this function anywhere...
PHP Code:
mysql_query($sql)
|
|
|
|
03-06-2005, 01:02 PM
|
|
Posts: 7
|
nope, I added it though, I dont if I did it correctly, but it doesn't seem to give me an error, but it still doesn't insert the info to the database:
PHP Code:
<?php
include "logindb.php";
$sql_table = "demo";
mysql_query($sql) == "INSERT into demo ('', 'fname', 'lname', 'email', 'sadrs', 'city', 'state', 'zip', 'phone', 'demo') VALUES('', '$fname', '$lname', '$email', '$sadrs', '$city', '$state', $zip', '$phone', '$demo')";
?>
my fields within my table demo in order is:
id int(11)
fname vachar(30)
lname vachar(30)
email vachar(50)
sadrs vachar(50)
city vachar(15)
state vachar(15)
zip int(5)
phone int(10)
demo vachar(30)
Last edited by Hawkallica; 03-06-2005 at 01:07 PM..
|
|
|
|
03-06-2005, 03:26 PM
|
|
Posts: 1,832
Location: Somewhere else entirely
|
mysql_query() is a function call, and you need to get your query string in between the brackets - this is passing a parameter to the function.
In your first attempt, you never called the function, in the second try, you have changed things around so that $sql is never set. You need to rewrite it as you had in the first example, and just add the line that cptnwinky gave you:
PHP Code:
<?php
include "logindb.php";
$sql_table = "demo";
//This sets your variable
$sql = "INSERT into demo (fname, lname, email, sadrs, city, state, zip, phone, demo) VALUES('$fname', '$lname', '$email', '$sadrs', '$city', '$state', $zip', '$phone', '$demo')";
//This calls the function, using the variable we set above
mysql_query($sql);
?>
Make sense?
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';
Please login or register to view this content. Registration is FREE (aka MSN handwriting for forums)
|
|
|
|
|
« Reply to N00b problem
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|