Page 1 of 1

Database Driven Site

Posted: Fri Jun 21, 2002 11:47 pm
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::.

Posted: Sat Jun 22, 2002 12:41 am
by jason
Well, it looks like you have parse errors. So we really can't help you unless we see some code. :D

[Code]

Posted: Sat Jun 22, 2002 4:28 pm
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]

Posted: Sat Jun 22, 2002 4:34 pm
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";
}

Posted: Sat Jun 22, 2002 4:38 pm
by volka
printf( &un );
printf( &pw );
replace & by $ ;)

Posted: Mon Jun 24, 2002 9:53 am
by sneakysockies
i thought you cant have " 's in php? 8O

Posted: Mon Jun 24, 2002 10:39 am
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