Jump to content

[PHP] [Help] Can someone look over my PHP and tell me if it will actually work or not?

AustinB

Hello LTT forum!

 

I'm basically creating this thread because I want to get feedback on how well I'm failing / coding in PHP so heres the links

 

HTML: http://pastebin.com/EQjjsS8v

PHP: http://pastebin.com/wfFg0s5k

PHP is incomplete.

 

Thanks. :)

Looking for a Programming Project take a look here!

http://linustechtips.com/main/topic/407332-looking-for-a-project-idea-start-here/

Link to comment
Share on other sites

Link to post
Share on other sites

Are you still working on that code? Because it won't run properly as it is. You also have security vulnerabilities in your SQL queries (it's something normal for beginners).

Want to solve problems? Check this out.

Link to comment
Share on other sites

Link to post
Share on other sites

Are you still working on that code? Because it won't run properly as it is. You also have security vulnerabilities in your SQL queries (it's something normal for beginners).

It isnt complete, yet. If I have the proper conditions in the if statements will it function? - Will edit OP

 

Im in need of a Condition to check if the DB exists

if (IF DBNAME DATABASE EXISTS- == false) { CREATES DB}

Pseudo Code

Looking for a Programming Project take a look here!

http://linustechtips.com/main/topic/407332-looking-for-a-project-idea-start-here/

Link to comment
Share on other sites

Link to post
Share on other sites

You can use the [iF NOT EXISTS] clause when creating the table.

So:

CREATE TABLE IF NOT EXISTS UserData (   PID INT NOT NULL AUTO_INCREMENT,   FirstName VARCHAR(50),   LastName VARCHAR(50),   Email VARCHAR(150) NOT NULL,   PRIMARY KEY(PID),   UNIQUE(Email))

I added a few things too. Your syntax was a little wrong, you should use varchars instead of chars, email should be varchar not text (TEXT is for large text values) and I added a UNIQUE constraint to your email field (this will ensure that you do not add users with replicated emails).

 

It will not work with the conditions alone (although the above query removes the need for some of the conditions), for several reasons:

  • You're not connecting to the database server at the right point in code. Notice that you're running the create query before you've established a connection.
    • Save the connection id by storing the return value of mysqli_connect, and use it on queries later to identify your session:
      $con = mysqli_connect($host, $username, $password, $dbName);
    • You need to set values for $host, $username, $password and $dbName (some usual starter values are 'localhost', 'root' and the password you set when you installed MySQL, respectively).
  • You have some syntax errors. It seems like you do not yet grasp the basic syntax of PHP (or programming), so maybe you should try to practice more basic things first?
  • You need to be careful about security vulnerabilities. But I will not expand on this yet, since you're just starting. But keep this in mind for future reference: SQL injection.

 

Try to work on the code, and I'd recommend you to first do some practice programming in general.

Want to solve problems? Check this out.

Link to comment
Share on other sites

Link to post
Share on other sites

You can use the [iF NOT EXISTS] clause when creating the table.

So:

CREATE TABLE IF NOT EXISTS UserData (   PID INT NOT NULL AUTO_INCREMENT,   FirstName VARCHAR(50),   LastName VARCHAR(50),   Email VARCHAR(150) NOT NULL,   PRIMARY KEY(PID),   UNIQUE(Email))

I added a few things too. Your syntax was a little wrong, you should use varchars instead of chars, email should be varchar not text (TEXT is for large text values) and I added a UNIQUE constraint to your email field (this will ensure that you do not add users with replicated emails).

 

It will not work with the conditions alone (although the above query removes the need for some of the conditions), for several reasons:

  • You're not connecting to the database server at the right point in code. Notice that you're running the create query before you've established a connection.
    • Save the connection id by storing the return value of mysqli_connect, and use it on queries later to identify your session:

      $con = mysqli_connect($host, $username, $password, $dbName);
    • You need to set values for $host, $username, $password and $dbName (some usual starter values are 'localhost', 'root' and the password you set when you installed MySQL, respectively).
  • You have some syntax errors. It seems like you do not yet grasp the basic syntax of PHP (or programming), so maybe you should try to practice more basic things first?
  • You need to be careful about security vulnerabilities. But I will not expand on this yet, since you're just starting. But keep this in mind for future reference: SQL injection.

 

Try to work on the code, and I'd recommend you to first do some practice programming in general.

Yea, I just started this project to get the grasp of PHP, and I'll be needing it for my Photography Site. If you dont mind could you add me on Skype, I'll send you my name.

Looking for a Programming Project take a look here!

http://linustechtips.com/main/topic/407332-looking-for-a-project-idea-start-here/

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×