Jump to content

A simple script help


pratkal

Recommended Posts

hello guys i need help in a script here is the script first

<?phpinclude '../config.php';$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con)  {  die('Could not connect: ' . mysql_error());  }// fetch data$username=$_POST['username'];$password=$_POST['password'];$First_Name=$_POST['First_Name'];$Last_Name=$_POST['Last_Name'];$Email=$_POST['Email'];// Create tablemysql_select_db("goaddworld_test", $con);$sql = "CREATE TABLE admin$sql=INSERT INTO admin($username, $password, $First_Name, $Last_Name, $Email)VALUES('$topic',;(id INT NOT NULL AUTO_INCREMENT, $username NOT NULL,$password NOT NULL,$First_Name NOT NULL,$Last_Name NOT NULL,$Email NOT NULL,echo Success in creating table please delete the install folder)";$result=mysql_query($insert);if($result){echo "Successful<BR>";}else {echo "ERROR in updating mysql";}// Execute querymysql_query($sql,$con);mysql_close($con);?>

now issue is everything is going fine but everything just work fine no error come in creating the table script part but when i look in database there is no table created what is the issue with the code

Link to comment
Share on other sites

your main problem is that you have SQL for creating a table and inserting data, along with a echo code mixed together, also you are using posted values as referencing field names in table.You should also set the auto increment, as a primary key.your create table and insert data sql should be similar to this

<?phpinclude '../config.php';$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con)  {  die('Could not connect: ' . mysql_error());  }// fetch data$username=$_POST['username'];$password=$_POST['password'];$First_Name=$_POST['First_Name'];$Last_Name=$_POST['Last_Name'];$Email=$_POST['Email'];// Create tablemysql_select_db("goaddworld_test", $con);$sql = "CREATE TABLE admin(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),username varchar(100) NOT NULL,password varchar(100)NOT NULL,fname  varchar(100) NOT NULL,lname  varchar(100) NOT NULL,email  varchar(100) NOT NULL)";mysql_query($sql,$con);//echo 'Success in creating table please delete the install folder';$insert="INSERT INTO admin(username, password, fname, lname, email) VALUES('$username', '$password', '$First_Name', '$Last_Name', '$Email')";// Execute query$result=mysql_query($insert,$con );if($result){echo "Successful<BR>";}else {echo "ERROR in updating mysql";}mysql_close($con);?>

you can use phpmyadmin SQL tab, to run your SQL to see if it works and is valid as in, and usually give you a indication where the problem is located within the SQL statment if error is occursCREATE TABLE admin(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),username varchar(100) NOT NULL,password varchar(100)NOT NULL,fname varchar(100) NOT NULL,lname varchar(100) NOT NULL,email varchar(100) NOT NULL)

Link to comment
Share on other sites

hi i also tried to use ur code but it still end up with same error i am bypassing to error when code is trying to put data into the table but the code fails to create the table it self please mind it i am new to php and only know html and css this is infect my first script i am trying to make an admin login installer so that i can post news on all website and install on website wherever i need to feed news

Link to comment
Share on other sites

Lets start from beginning an make sure below worksCREATE TABLE admin(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),username varchar(100) NOT NULL,password varchar(100)NOT NULL,fname varchar(100) NOT NULL,lname varchar(100) NOT NULL,email varchar(100) NOT NULL)I assume you know how to access phpmyadmin?, localhost/phpmyadmin, this should bring up a list of databases and 'goaddworld_test(0)' should be shown showing that you have no tables in 'goaddworld_test' database. Now click this database name, and at the top you should see a SQL tab, click this and enter the above code into textarea box, and press go. You should now see that the table admin has been created, and listed under the database name, which now shows 'goaddworld_test(1)'.

Link to comment
Share on other sites

I just wanted to make sure the database accepts the sql code, I now suggest you comment out the code related to $_POST, and insert, and run it again, make sure you are connected to the correct database, and not been inserting to some other database instead. you should find that again! the table is created.

Link to comment
Share on other sites

ok let me try changing the codei will remove everything other then just creating the tablethis time i use the code

<?phpinclude '../config.php';$con = mysql_connect("$dbhost","$dbuser","$dbpass");if (!$con)  {  die('Could not connect: ' . mysql_error());  }else  {  echo "Table in database created please click continue to go to next step ";  }// Create tablemysql_select_db("goaddwor_mydb", $con);$sql = "CREATE TABLE adminCREATE TABLE admin(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),username varchar(100) NOT NULL,password varchar(100)NOT NULL,fname varchar(100) NOT NULL,lname varchar(100) NOT NULL,email varchar(100) NOT NULL,)";// Execute querymysql_query($sql,$con);mysql_close($con);?>

but still the same issue i am so ######ing angry @ momment that i cant even run a simple code @ :)also checked config file and database name its correct

Link to comment
Share on other sites

$sql = "CREATE TABLE admin(CREATE TABLE admin(

Some unnecessary redundancy there.

removed still nothing D: i am learning php and having this issue till last day... can it be an issue with php version difference ???
Link to comment
Share on other sites

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 admin ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), username v' at line 2

Link to comment
Share on other sites

ok found something via php my admin when i run this code

CREATE TABLE admin(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),username varchar(100) NOT NULL,password varchar(100)NOT NULL,fname varchar(100) NOT NULL,lname varchar(100) NOT NULL,email varchar(100) NOT NULL)";

code does not work while this code work in phpmyadmin

CREATE TABLE admin(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),username varchar(100) NOT NULL,password varchar(100)NOT NULL,fname varchar(100) NOT NULL,lname varchar(100) NOT NULL,email varchar(100) NOT NULL)

this code work fine with phpmyadmin but give error while running with the scriptParse error: syntax error, unexpected $end in /home/goaddwor/public_html/test/install/install.php on line 28line 28 code

?>

WTF

Link to comment
Share on other sites

did you forget to end one of your statement's with a semi-colon? (it is typical to also look a line or two before the actual line number suggested by the error message).

Link to comment
Share on other sites

in phpmyadmin you only insert the code between quotesCREATE TABLE admin(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),username varchar(100) NOT NULL,password varchar(100)NOT NULL,fname varchar(100) NOT NULL,lname varchar(100) NOT NULL,email varchar(100) NOT NULL)to run the script in php you assign the code as text string to $sql.$sql = "CREATE TABLE admin(id INT NOT NULL AUTO_INCREMENT,PRIMARY KEY(id),username varchar(100) NOT NULL,password varchar(100)NOT NULL,fname varchar(100) NOT NULL,lname varchar(100) NOT NULL,email varchar(100) NOT NULL)";

Link to comment
Share on other sites

back to the earlier 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 admin ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), username v' at line 2btw thanks for info dsonesuk

Link to comment
Share on other sites

ye i changed the db dw i was using test earlier now using mydb for test it is correctbtw posting config.php code here too if i am doing something wrong

<<?php// please enter your mysql details$dbhost = 'localhost';$dbuser = 'goaddwor_kal';$dbpass = 'coughcoughmypass';$dbname = 'goaddwor_mydb';?>

Link to comment
Share on other sites

Are you sure the user you're connecting with even has permission to create a new table? The front page of phpMyAdmin should have a Privileges tab which lists the users and which privileges they have on which databases.

Link to comment
Share on other sites

is it you running on your localserver or remote server? if you are using remote server in a remote host then you can not access the database in root. in your cpanel you can find for managing database user privilages though.

Link to comment
Share on other sites

check your cpanel and make sure as jsg said that the current user which accessing the datbase has permission for creating tables. if you still having problem you may want to show the final edited code which you come up with.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...