Page 1 of 1

The basics to making a php webpage

Posted: Wed May 13, 2009 3:57 pm
by blackheart141
<h3>Login</h3>

Code: Select all

 
        <table>
            <tr>
                    <form name=form1 method="post" action="checklogin.php">
                    <table border=0 cellspacing=0 cellpadding=2>
                    <tr><td>
                    Username: <td><input name="myusername" type="text" id="myusername">
                    <tr><td>
                    Password: <td><input name="mypassword" type="password" id="mypassword">
                    <tr><td><input type="Submit" name="Submit" value="Login !">
                    <table>
                    </form>
            </tr>
        </table>
</div>
 
<div style="position:absolute;top:250px;right:500px;">
<h3>Please feel free to register below.</h3><br>
<h1>Registration</h1>
    <form method="post" action="reg.php">
    <table border=0 cellspacing=0 cellpadding=2>
    <tr><td>
    Username: <td><input type="text" name="username" maxlength="20">
    <tr><td>
    Password: <td><input type="password" name="password">
    <tr><td>
    Email: <td><input type="text" name="email">
    <tr><td>
    <tr><td><input type="submit" value="Register">
    </form>
</div>
 
The above codeing can be used to make a registration page and a login box.

Code: Select all

 
<?php
        $connection=mysql_connect("localhost", "root", "");
        mysql_select_db("bikes",$connection);
 
        $result = mysql_query ("SELECT * FROM products WHERE type LIKE '%$_POST[search]%' OR make LIKE '%$_POST[search]%' OR model LIKE '%$_POST[search]%' OR discription LIKE '%$_POST[search]%'",$connection);
        
        while ($row = mysql_fetch_array($result))
        {
            print '<table border="1">';
                Print '<tr><th>' . $row[1] . '</th></tr>';
                print '<tr><th>' . $row[2] . ' - ' . $row[3] . '</th></tr>'; // Make and Model
                print '<tr><td rowspan="4" scope="col"><img src="images/' . $row[6] . '" width="500" height="300" /></td></tr>'; // picture
                print '<tr><td>' . $row[4] . '</td></tr>'; // decription
                print '<tr><td>Price: £' . $row[5] . '</td></tr>'; // price
                Print '<br>';
            print '</table>';
        }
    ?>
</div>
 
This coding is used to make a products page
 
 
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="bikes"; // Database name
$tbl_name="members"; // Table name
 
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
 
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
 
// To protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
 
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
 
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
 
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
?>
 
This coding is used to connect to the database to check login details.

Re: The basics to making a php webpage

Posted: Wed May 13, 2009 4:04 pm
by crazycoders
What is your question? and please use the [ code ] tags to format your code, it's easier to read your post!

Re: The basics to making a php webpage

Posted: Wed May 13, 2009 5:57 pm
by requinix
I don't think there is a question. Seems to me like blackheart141 was trying to be helpful by offering advice nobody asked for.

Re: The basics to making a php webpage

Posted: Wed May 13, 2009 6:09 pm
by Benjamin
:arrow: Moved to Coding Critique