-
Posts
476 -
Joined
-
Last visited
Everything posted by xProteuSx
-
zanus, I have tried what you suggest, though I cannot find where I didn't close the quote: [code] fwrite($connectfile, " <---opening quote <?php \$dbh=mysql_connect (\"$serverurl\", \"$nameofuser\", \"$passofuser\") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db (\"$databasename\");?>" <---closing quote); [/code] I changed the snippet to what you posted above, and I still get an error if I have the DROP TABLE users line in index2.php. Without that line everything is fine. This is what confuses the crap out of me (among many other things): if the DROP TABLE command is not present and the table 'users' does not exist all goes smooth meaning that a new table named 'users' is created. If the table 'users' does exist before the code is executed I simply get a message stating that 'Table 'users' already exists'. Now, if I add the line "DROP TABLE users;" above "CREATE TABLE users (..." the code should delete the table 'users' then create a new one, right? Instead I get the error "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '; CREATE TABLE users ( users_id int(6) NOT NULL auto_increment,". If I remove the semicolon I simply get the error "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TABLE users ( users_id int(6) NOT NULL auto_increment, u" I am at a total loss. And what about the fact that mysql_select_db does take 2 arguments? You only show one in your code. Is this correct? Thanks zanus!
-
I am really stuck on my project, and no one has been able to help me with this: I wrote code to create a table in MySQL but once I have created the table I am not able to DROP, TRUNCATE, or do anything else except for add and query records. I have all rights to the DB and I am sure that my connection snippet is correct. Could someone please take 5 minutes to help? I'll post all the code below. Its very amateur so it is easy to understand. Index.php collects four variables ($serverurl, $nameofuser, $passofuser, and $databasename). It then goes to index2.php. Index2.php uses the fwrite command to create dbconnect.php which stores the connection string. Then it uses the connection string in the format of an include statement and creates a table called 'users'. It also collects four more variables ($username, $password1, $password2, and $email) then it proceeds to index3.php. These variables and index3.php are inconsequential. My mistake/error is somewhere within index.php, index2.php or dbconnect.php. index.php --> [code] <body> <form method="post" action="index2.php"> <p>Server URL: <input type="text" name="serverurl" size="30"></p> <p>Database Name: <input type="text" name="databasename" size="20"></p> <p>Database Username: <input type="text" name="nameofuser" size="20"></p> <p>Database Password: <input type="password" name="passofuser" size="20"></p> <input type="submit" value="Submit"> </form> </body> [/code] index2.php --> [code] <body> <?php //opens a new file and writes the database connection string to it then closes this new file $connectfile = fopen("dbconnect.php","w"); fwrite($connectfile, " <?php \$dbh=mysql_connect (\"$serverurl\", \"$nameofuser\", \"$passofuser\") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db (\"$databasename\");?>"); fclose($connectfile); echo "Got 'er!<br><br>"; include ("dbconnect.php"); $sql = " DROP TABLE users; CREATE TABLE users ( users_id int(6) NOT NULL auto_increment, users_handle varchar(20) default NULL, users_password varchar (20) default NULL, users_email varchar (40) default NULL, users_datejoined timestamp NOT NULL, users_visits int (6) default '0', users_lastvisit timestamp NOT NULL, users_questionsanswered int(6) default '0', users_correctanswers int(6) default '0', users_percentcorrect float default '0', users_totalscore int (6) default '0', users_pagesviewed int(8) default '0', users_visitbonus int(6) default '0', users_activity int(6) default '0', PRIMARY KEY(users_id), UNIQUE(users_handle) ) TYPE=MYISAM; "; ?> <form method="post" action="index3.php"> <p>New Username <input type="text" name="username" size="30"></p> <p>Password: <input type="password" name="password1" size="20"></p> <p>Confirm Password: <input type="password" name="password2" size="20"></p> <p>E-Mail: <input type="text" name="email" size="20"></p> <input type="submit" value="Submit"> </form> </body> [/code] dbconnect.php --> [code] <?php$dbh=mysql_connect ("myhost", "myusername", "mypassword") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("mydatabase");?> [/code] Now, if you look at the [color=red]DROP TABLE users;[/color] near the top of index2.php, that doesn't work. Neither does it work if I replace it with TRUNCATE TABLE users; HELP!!!!!! I'm stuck.
-
Thanks for the quick response guys ... I got 'er. [code]if (($password1 != $password2) || ($password1 == "")) { ...[/code] SWEETNESS!
-
I cannot find anything regarding an 'OR' type operator/statement in PHP. I seem to remember functions like that existing in other programming languages, so I figure there has to be something like that here. Here is the sort of scenario that I am looking at: [code]if ($password1 != $password2) or ($password1 == "") { ...[/code] Thanks in advance. ???
-
Well, if you are worried that the code is not connecting to the MySQL server then rest assured that the connection is fine, but I have not included the connection code in this snippet. I know that the connection is good because if I manually drop the table via phpMySQLadmin and run this code, it does generate a users table. I just can't seem to get the DROP command to work.
-
I have been fighting with this DROP TABLE statement, and I can't get it to remove a table from my database. So after trying everything, maybe I have the wrong idea od 'DROPPING' a table. Should I be 'DROPPING' it or is there a 'DELETE' function that will completely remove the table? I am starting to think that to 'DROP' means to clear the table of any entries, but what I am trying to do is 'DELETE' and remove the table altogether. I'm lost ...
-
Must not be correct, because it did not work ... Any suggestions?
-
When I add the ';' this is the error that I get: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '; CREATE TABLE users ( users_id int(6) NOT NULL auto_incremen You're absolutely right about two queries, however. The problem is, I am unsure of how to do two separate queries. I will try the following: [code] <?php $sql = "DROP TABLE users"; $sql = "CREATE TABLE users ( users_id int(6) NOT NULL auto_increment, users_handle varchar(20) default NULL, users_password varchar (20) default NULL, users_email varchar (40) default NULL, users_datejoined timestamp NOT NULL, users_visits int (6) default '0', users_lastvisit timestamp NOT NULL, users_questionsanswered int(6) default '0', users_correctanswers int(6) default '0', users_percentcorrect float default '0', users_totalscore int (6) default '0', users_pagesviewed int(8) default '0', users_visitbonus int(6) default '0', users_activity int(6) default '0', PRIMARY KEY(users_id), UNIQUE(users_handle) ) TYPE=MYISAM;" ?> [/code] Does that seem correct? Thanks a bunch.
-
I am very new to php/MySQL so I am playing around with the basic functions and I cannot get the DROP TABLE statement to work. My code is as follows: [code] <?php $sql = " DROP TABLE users CREATE TABLE users ( users_id int(6) NOT NULL auto_increment, users_handle varchar(20) default NULL, users_password varchar (20) default NULL, users_email varchar (40) default NULL, users_datejoined timestamp NOT NULL, users_visits int (6) default '0', users_lastvisit timestamp NOT NULL, users_questionsanswered int(6) default '0', users_correctanswers int(6) default '0', users_percentcorrect float default '0', users_totalscore int (6) default '0', users_pagesviewed int(8) default '0', users_visitbonus int(6) default '0', users_activity int(6) default '0', PRIMARY KEY(users_id), UNIQUE(users_handle) ) TYPE=MYISAM;" ?> [/code] What I am trying to do is to drop the previous 'users' table and create a new one in its place. I tried everything I can think of, I believe, including "DROP TABLE users;" I don't know what to do anymore. Some help would be duly appreciated. Thanks guys.
-
I should mention that what I am trying to do is the DROP the previous 'users' table, and create a new one in its place.
-
I am very new to php/MySQL so I am playing around with the basic functions and I cannot get the DROP TABLE statement to work. My code is as follows: [code] <?php $sql = " DROP TABLE users CREATE TABLE users ( users_id int(6) NOT NULL auto_increment, users_handle varchar(20) default NULL, users_password varchar (20) default NULL, users_email varchar (40) default NULL, users_datejoined timestamp NOT NULL, users_visits int (6) default '0', users_lastvisit timestamp NOT NULL, users_questionsanswered int(6) default '0', users_correctanswers int(6) default '0', users_percentcorrect float default '0', users_totalscore int (6) default '0', users_pagesviewed int(8) default '0', users_visitbonus int(6) default '0', users_activity int(6) default '0', PRIMARY KEY(users_id), UNIQUE(users_handle) ) TYPE=MYISAM;" ?> [/code] I tried everything I can think of, I believe, including [font=Verdana]"DROP TABLE users;"[/font] I don't know what to do anymore. Some help would be duly appreciated. Thanks guys.
-
Thanks for the help.
-
The following is a snippet of code where I try to make a DB table. I don't know how to troubleshoot table creation. I am not getting any MySQL errors, but the table is not being created either. Please help! I have stayed up all night trying to figure this out ... [code]<!-- connect to MySQL --> <?php $dbh=mysql_connect ("$serverurl", "$databasename", "$passofuser") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("$databasename"); ?> <!--create MySQL Table --> <?php $sql = " DROP TABLE IF EXISTS 'users'; CREATE TABLE 'users' ( 'users_id' int(6) NOT NULL auto_increment, 'users_handle' varchar(20) default NULL, 'users_password' varchar (20) default NULL, 'users_email' varchar (40) default NULL, 'users_datejoined' timestamp NOT NULL, 'users_visits' int (6) default '0', 'users_lastvisit' timestamp NOT NULL, 'users_questionsanswered' int(6) default '0', 'users_correctanswers' int(6) default '0', 'users_percentcorrect' float (3,2) default '0', 'users_totalscore' default '0', 'users_pagesviewed' int(8) default '0', 'users_visitbonus' int(6) default '0', 'users_activity' int(6) default '0', PRIMARY KEY('users_id'), UNIQUE('users_handle') ) TYPE=MYISAM;" ?> [/code]
-
After trying single and double quotes all over the place, the following seems to have worked: [code] $sql = "CREATE TABLE users ( 'users_id' int(6) NOT NULL auto_increment, 'users_handle' varchar(20) default NULL, 'users_password' varchar (20) default NULL, 'users_email' varchar (40) default NULL, 'users_datejoined' timestamp NOT NULL, 'users_visits' int (6) default '0', 'users_lastvisit' timestamp NOT NULL, 'users_questionsanswered' int(6) default '0', 'users_correctanswers' int(6) default '0', 'users_percentcorrect' float (3,2) default '0', 'users_totalscore' default '0', 'users_pagesviewed' int(8) default '0', 'users_visitbonus' int(6) default '0', 'users_activity' int(6) default '0', PRIMARY KEY('users_id'), UNIQUE('users_handle') ) TYPE=MYISAM;" [/code] Thanks ...
-
I am not sure what you are showing. You have double quotes and periods all over the place. You might very well be right, but I am too confused to know where to add all the quotes and the periods.
-
I know that this is some stupid little mistake that anyone with any knowledge will fix in approximately 3 seconds, but I am a total n00b when it comes to PHP and MySQL. I can't figure this out. I am trying to make a table using the following code: [code] <?php $sql = CREATE TABLE users ( 'users_id' int(6) NOT NULL auto_increment, 'users_handle' varchar(20) default NULL, 'users_password' varchar (20) default NULL, 'users_email' varchar (40) default NULL, 'users_datejoined' timestamp NOT NULL, 'users_visits' int (6) default '0', 'users_lastvisit' timestamp NOT NULL, 'users_questionsanswered' int(6) default '0', 'users_correctanswers' int(6) default '0', 'users_percentcorrect' float (3,2) default '0', 'users_totalscore' default '0', 'users_pagesviewed' int(8) default '0', 'users_visitbonus' int(6) default '0', 'users_activity' int(6) default '0', PRIMARY KEY('users_id'), UNIQUE('users_handle') ) TYPE=MYISAM; ?> [/code] I get the following error: "Parse error: syntax error, unexpected T_STRING in /home/digitalp/public_html/test/mysite/mysqlconnect.php on line 19." That is the line that states $sql = CREATE TABLE users ( Thanks in advance.