PHP/Mysql
So as some of you know, I am learning the both of them and, well, I am having a little trouble with it. I have no idea why this is harder to understand than a strict programming language. But well, I was going to see if anyone had any good sources to learn both from.
And by the way I will use this thread in the future if i have questions about the two of them.
yours31f wrote: I have no idea why this is harder to understand than a strict programming language.
By "strict programming language", I'm assuming you are referring to the typeless variables in PHP. Everything else is similar to a "typed" language like C++. PHP is a scripting language, and should be thought of as such… there is the capability to use OOP structures in PHP, but the majority of its use falls under procedural style programming. Thus, use PHP in the same layout as you would HTML, almost as a replacement or optimization for HTML content. That's all it does, anyways… it creates HTML content using functionality that HTML does not have (since HTML is not a programming language but, rather, a language construct).
MySQL is not hard… you can break it down into function, table argument, search criteria, order criteria, and sort criteria. Take a couple of example MySQL queries:
markup"SHOW TABLES"
SHOW is the function, TABLES is the argument. This will list tables. "SHOW DATABASES" will list databases.
markup"SELECT id,name FROM categories ORDER BY id DESC"
SELECT and FROM are the functions, "id,name" and "categories" are the table arguments (table columns) for each (respectively), ORDER BY is the order function, "id" is the order criteria, and DESC is the sort criteria (there is no function for sort criteria as they are added to the order function).
markup"INSERT INTO categories VALUES(NULL,'test name')"
INSERT INTO and VALUES are the functions (VALUES functions as a language-defined array construct), categories is the table argument for INSERT INTO, and NULL,'test name' are the table arguments (array elements, for sake of making it simpler) for VALUES.
That's it for simple MySQL query structure. Learn in this order:
- SELECT, INSERT, UPDATE, and DELETE functions and table arguments
- Search criteria, order criteria, and sort criteria
- CREATE, ALTER, DROP, and SHOW functions
- MySQL Joins in a Query
You're just waiting for someone to feed you, and no one either wants to or has the time to… not when we have our own learning to do.
yours31f wrote: So as some of you know, I am learning the both of them and, well, I am having a little trouble with it. I have no idea why this is harder to understand than a strict programming language. But well, I was going to see if anyone had any good sources to learn both from.
There's really no good reason to try and learn both at the same time. Any time you start with something it's a little tough, but PHP probably wouldn't be hard if you were dealing with it standalone. These just happen to be the two languages I have gotten into, the reason I'm posting.
In summer of 2005 I started to learn C++. Stumbling around with a new compiler, even the hello world was daunting. I continued to read and experiment though, something a lot of people just don't do around here. Please, look around the whole internet, no one says you have to learn from a single site. There are sites out there that give prototypes of library functions, along with examples how to use them. Yea, the type system will seem extreme, but you it will grow on you.
Ok the past post (except spyware's, but he's always welcome to post in my threads) were helpful. I understand that both don't have to be learned at the same time but i tend to procrastinate or just never get around to finish learning things, But this site has helped me with that so much since i have joined.
Ok so I get an error but I cant fond whats wrong with this code…
here is the error #1064 - 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 '<?php $con = mysql_connect("mysql","name","password")' at line 1 obviously its line one but whats wrong with it?
<?php $con = mysql_connect("mysql","Name","Password"); if (!$con) { die('Could not connect: ' . mysql_error()); }
if (mysql_query("CREATE DATABASE Table",$con)) { echo "Database created"; } else { echo "Error creating database: " . mysql_error(); }
// Create table in login database mysql_select_db("table", $con); $sql = "CREATE TABLE ***** ( username varchar(15), password varchar(15) )";
mysql_query("INSERT INTO user (username, password) VALUES ('', '*')"); mysql_query($sql,$con); mysql_close($con);
?>
hellboundhackersok wrote: Fuck man… google has everything you'll need.
Wow… it's been about 2 years, and you're still a noob. You should probably work on that if you expect anyone to take you seriously.
yours31f wrote: I rather enjoy talking to people, google just isnt social enough,
Well, people aren't going to keep catering to your questions. So, either you start trying to learn on your own, or people are just going to shit on your threads. Either way, you need to use other resources than the threads on this site.
Ok Now I have a serious question. I made a login form, then made it post to login.php, so my question is (yes i have searched and cannot find a way to make it work.) How do I make the script do this?
test to see
if ($post["username"] == * from column username) { &&
if ($post["password']== * from column password) { setcookie(user,$post["username"],3600,mysite.com); } } else { echo "incorrect login info"; } ?>
yours31f wrote: How do I make the script do this?
test to see
if ($post["username"] == * from column username) && if ($post["password']== * from column password)
Do you even attempt to learn anything on your own? What is the point of a MySQL SELECT statement? For the form bit, just Google "php post form". I'm tired of answering your crap when you don't even try on your own.
Then the best way to do it is
$data = $_POST['data'];
$data = mysql_real_escape_string($data);
$data = htmlentities($data);
$query = mysql_query("SELECT * FROM table WHERE username = '".$data."' ");
$nums = mysql_num_rows($query);
if($nums == 0)
{
//no username exists
}
else
{
// the username is in the database
}```
That would be to check for username , if it exists
or, you can do
```markup$data = $_POST['data'];
$query = mysql_query("SELECT * FROM table ");
$row = mysql_fetch_assoc($query);
if($row['row_u_want_to_compare_against'] == $data)
{
//
}```