Database Driven Site

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
sneakysockies
Forum Newbie
Posts: 4
Joined: Fri Jun 21, 2002 11:47 pm
Location: hollister, CA
Contact:

Database Driven Site

Post by sneakysockies »

8O

I am a php/mysql newbie. I want that known. I am pretty good with it though, as I have known C++ and HTML for a while. I have always wanted a database-driven website, and I have now allocated time in my life to work on it. I have my server installed with apache, php, mysql, and all that. All of them have been tested are working, to avoid confusion. I would like to write a login page, and a page that shows information depending on the user logged in. All my attempts have crashed and burned, and I am not entirely sure why. I am probably going with the wrong approache, but hey, im new so shoot me :P

It is online, at :arrow: http://www.bluetyme.net/test/

If you want my source just IM me or email. If you have a tip or suggestion, I would greatly appreciate it. Thank you! :)

- Ed Johnson
.::Blue Solutions::.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Well, it looks like you have parse errors. So we really can't help you unless we see some code. :D
sneakysockies
Forum Newbie
Posts: 4
Joined: Fri Jun 21, 2002 11:47 pm
Location: hollister, CA
Contact:

[Code]

Post by sneakysockies »

Ok, heres the pages ive tried, and yeah i want it spanned 3 pages for now. I have read about sessions, should I use them to pass information through pages while logged in rather than calling from a database all the time? (like maybe the persons name, or something) Well, heres my code:

index.php

Code: Select all

<html><head><title>user test system</title></head><body>

<h3>Login Here</h3>
<form method="post" action="mypage.php"> 
Username:<input type="text" name="un" size=10><br>
Password:<input type="password" name="pw" size=10> <br>
<input type="submit" name="submit" value="SUBMIT">
</form> 

<h3>Signup Here</h3>
<form method="post" action="signup.php" name="signup">
username:<input type="text" name="un"><br>
password:<input type="text" name="pw"><br>
<input type="submit" name="submit" value="SUBMIT">
</form>

</body></html>
Logged-in page:
mypage.php

Code: Select all

<html><head><head><body><?php 

$conn = mysql_connect("localhost", "root"); 
mysql_select_db("ed", $conn); 

$sql = "SELECT * FROM user"; 

    $result = mysql_query( $sql ) 
        or die ( 'Unable to execute query.' ); 
$myrow = mysql_fetch_array($result);

if ($un==$myrow&#1111;'name'] && $pw==$myrow&#1111;'password']) &#123;
echo "login successful, hi $un";
&#125;
else &#123;
echo "error!";
&#125;
?>
</body></html>
Sign-up page:
signup.php

Code: Select all

<html><head><title>user test system</title></head><body>
<?php

$connect = mysql_connect("localhost", "root");
mysql_select_db("ed", $connect);

if ($submit=='SUBMIT') &#123; 

$sql = "INSERT INTO user (name, password) VALUES ('$un', '$pw')";

  if (mysql_query($sql)) &#123; 
    echo '<h2>Welcome $un!</h2>You have been added. Click back to log in.'; 
  &#125; else &#123; 
    echo 'Error adding your info'; 
  &#125; 
&#125; 

printf( &un );
printf( &pw );
?></body></html>
Hope that isnt too much! :oops: If you know where I went wrong, again, IM me or email. Thank you

- Ed Johnson
.::Blue Solutions::.[/b]
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post by MattF »

I assume you have register globals on...

try this for your SQL:

$sql = "SELECT * FROM user WHERE name='$un'";

Then later on replace the if with this if:

if ($pw==$myrow['password']) {
echo "login successful, hi $un";
}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

printf( &un );
printf( &pw );
replace & by $ ;)
sneakysockies
Forum Newbie
Posts: 4
Joined: Fri Jun 21, 2002 11:47 pm
Location: hollister, CA
Contact:

Post by sneakysockies »

i thought you cant have " 's in php? 8O
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post by will »

sneakysockies wrote:i thought you cant have " 's in php? 8O
you can, but it's important to know the difference between " and ' ...try this article... http://www.webmasterbase.com/article/686
Post Reply