The basics to making a php webpage

Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.

Popular code excerpts may be moved to "Code Snippets" by the moderators.

Moderator: General Moderators

Post Reply
blackheart141
Forum Newbie
Posts: 1
Joined: Wed May 13, 2009 3:52 pm

The basics to making a php webpage

Post 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.
Last edited by Benjamin on Wed May 13, 2009 4:06 pm, edited 1 time in total.
Reason: Added [code=php] tags.
crazycoders
Forum Contributor
Posts: 260
Joined: Tue Oct 28, 2008 7:48 am
Location: Montreal, Qc, Canada

Re: The basics to making a php webpage

Post by crazycoders »

What is your question? and please use the [ code ] tags to format your code, it's easier to read your post!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: The basics to making a php webpage

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: The basics to making a php webpage

Post by Benjamin »

:arrow: Moved to Coding Critique
Post Reply