07-17-2013, 10:16 AM
What made me want to learn PHP was that the language (and others) enabled me to delete, insert, update etc fields within tables within my database using specific SQL queries.
This is small, but may be an effective information thread for your newbie self.
I'm going to start this topic off with some useful links:
Now, hence the order I have placed these links, you should check each website out in order.
Code Academy
You should most definitely complete the 10 or more lessons related to PHP provided. You will cover the basics of arrays, if then else statements, functions and quite a few other aspects.
PHP Academy
This website is more for you to use when you know the basics. Watch their videos, and follow their tutorials closely while observing what code does what. You should know the basics from what you've learned over at Code Academy. I suggest you start with the Login and Register tutorial first.
Basic PHP & SQL Example
Below is a very simple registration page which hopefully some of you may understand.
I'm hosting this website locally. My host is localhost, database name is profile, username is root and I have no password set.
Users simply input their desired username and password and the server will update your MySQL database like so.
There's no input validation really on this form except to see if either input box is empty, otherwise we'll show an error. I suggest you only use this for learning purposes.
Private message me if you would like the database file to go along with this. I'll also include a basic user profile.
I'm still learning so don't give me too much hassle for anything I've done wrong. I thought I'd share this with users as I struggled deeply to get started. :confused:mile:
This is small, but may be an effective information thread for your newbie self.
I'm going to start this topic off with some useful links:
Now, hence the order I have placed these links, you should check each website out in order.
Code Academy
You should most definitely complete the 10 or more lessons related to PHP provided. You will cover the basics of arrays, if then else statements, functions and quite a few other aspects.
PHP Academy
This website is more for you to use when you know the basics. Watch their videos, and follow their tutorials closely while observing what code does what. You should know the basics from what you've learned over at Code Academy. I suggest you start with the Login and Register tutorial first.
Basic PHP & SQL Example
Below is a very simple registration page which hopefully some of you may understand.
PHP Code:
<html>
<head>
<title>Add New Record in MySQL Database</title>
</head>
<body>
<?php
$error = array();
if (isset($_POST['submit'])) {
if (empty($_POST['username']) || empty($_POST['password'])) {
$error[] = 'You must fill in both fields.';
echo '<ul><li>' . implode('</li><li>', $error) . '</li></ul>';
die();
}
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if (! $conn ) {
die('Could not connect: ' . mysql_error());
}
$username = $_POST['username'];
$password = md5($_POST['password']);
$sql = "INSERT INTO users (username, password) VALUES('$username','$password')";
mysql_select_db('profile');
$retval = mysql_query($sql,$conn);
if(! $retval ) {
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
mysql_close($conn);
}
else {
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="600" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="250">Username</td>
<td>
<input name="username" type="text" id="username">
</td>
</tr>
<tr>
<td width="250">Password</td>
<td>
<input name="password" type="password" id="password">
</td>
</tr>
<tr>
<td width="250"> </td>
<td> </td>
</tr>
<tr>
<td width="250"> </td>
<td>
<input name="submit" type="submit" id="submit" value="Register">
</td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
I'm hosting this website locally. My host is localhost, database name is profile, username is root and I have no password set.
Users simply input their desired username and password and the server will update your MySQL database like so.
There's no input validation really on this form except to see if either input box is empty, otherwise we'll show an error. I suggest you only use this for learning purposes.
Private message me if you would like the database file to go along with this. I'll also include a basic user profile.
I'm still learning so don't give me too much hassle for anything I've done wrong. I thought I'd share this with users as I struggled deeply to get started. :confused:mile: