We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Sql error
Topic Started: May 8 2005, 07:29 PM (345 Views)
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
I am new to sql so I don't see an error, but there is one:
Quote:
 
<?
$dbh=mysql_connect ("localhost", "dasein_dasein", "**********") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("dasein_dasdata");

CREATE TABLE MEMBERS
(username VARCHAR(30),
password VARCHAR(30),
type CHAR(9))
?>


I get
Quote:
 
Parse error: parse error, unexpected T_STRING in /home/dasein/public_html/createtabel.php on line 5

Am I missing something blantantly odvious?
Offline Profile Quote Post Goto Top
 
Seth
Member Avatar
I has a pony
[ *  *  *  *  *  *  *  *  * ]
Yes. You have to send queries via mysql_query().

http://php.net/mysql_query
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
How would mysql_query() be used in this instance? I thought query was used to get infromation. I am trying to Create the table not get anything from it.

Sorry for being a n00b if I am missing something.
Offline Profile Quote Post Goto Top
 
Ben
Member Avatar
Quantum-locked when observed.

Das Ein
May 8, 2005 08:12 PM
How would mysql_query() be used in this instance? I thought query was used to get infromation. I am trying to Create the table not get anything from it.

Sorry for being a n00b if I am missing something.

A query is used for anything that will alter the database:

Code:
 
<?
$dbh=mysql_connect ("localhost", "dasein_dasein", "**********") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("dasein_dasdata");

mysql_query("CREATE TABLE MEMBERS
(username VARCHAR(30),
password VARCHAR(30),
type CHAR(9))");
?>
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
EDIT: Figured it out, but now a new question.
Quote:
 
$memberget = mysql_query("SELECT * FROM MEMBERS WHERE username = 'Dasein'");

$ACCOUNT_INFORMATION = mysql_fetch_array($memberget)

$password = $ACCOUNT_INFORMATION['password'];

echo "Das Eins password is $password";

I am trying to see if everything worked properly. I keep getting an error on "$password = $ACCOUNT_INFORMATION['password'];" . Do I need to query it too?
Offline Profile Quote Post Goto Top
 
Ben
Member Avatar
Quantum-locked when observed.

Missed a semicolon: :D
Quote:
 
$memberget = mysql_query("SELECT * FROM MEMBERS WHERE username = 'Dasein'");

$ACCOUNT_INFORMATION = mysql_fetch_array($memberget);

$password = $ACCOUNT_INFORMATION['password'];

echo "Das Eins password is $password";
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
Now all I get is
Quote:
 
Das Eins password is
how come the password isn't dispylaing?

Also is there a way to see if something is already in the database?
EX: if ($bob == 'script to check if it is already in the db') { ...
Offline Profile Quote Post Goto Top
 
JoeC
Euch! IE tastes horrible!
[ *  *  *  *  * ]
I don't do PHP and SQL, but in the original script:

Quote:
 
echo "Das Eins password is $password";


Do you not need to do something like (not sure of syntax)

Code:
 
echo "Das Eins password is " $password;


As I say, I''m not sure that'll work, but it may be worth a try.
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
Actually it would be
Quote:
 
echo "Daseins password is" . $PASSWORD;


It doesn't work, but good thought ;)
Offline Profile Quote Post Goto Top
 
Seth
Member Avatar
I has a pony
[ *  *  *  *  *  *  *  *  * ]
Variable names are case sensitive. Das, your example is bad.

However either method should work. Check your result variable to see if it returns > 0.
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
EDIT: I think I delete my old incorrect one, but now it still isn't showing up. Is there a way I can delete everything and try again?
Offline Profile Quote Post Goto Top
 
JoeC
Euch! IE tastes horrible!
[ *  *  *  *  * ]
Run the SQL query "drop" on your table, and it'll delete all the contents, then insert a new record.

Or, if you can use something like PHPmyAdmin, that's really easy to get rid of stuff in.
Offline Profile Quote Post Goto Top
 
Das
Member Avatar
Smells of rich mahogany
[ *  *  *  *  *  *  * ]
I just killed the entire database. I will try again when I learn more.
Offline Profile Quote Post Goto Top
 
JoeC
Euch! IE tastes horrible!
[ *  *  *  *  * ]
I did say that was what "drop" did. I don't know much, but I know that.

I'm kinda hoping the db wasn't important, and if it was just a testing one, then if you add a new record, you can use this:

Code:
 
INSERT INTO mytable
VALUES (column1value, column2value, ...)


And then do your outputting off that.
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply