foevah Posted November 10, 2006 Share Posted November 10, 2006 Ive been using a tutorial that lets me make my own blog [url=http://codegrrl.com/!/tutorials/category/Build%20A%20Blog/P10/]click here to see the tutorial site[/url]Ive got up to [url=http://codegrrl.com/!/tutorials/view/part_4_passwording_individual_entries/]part 4[/url] without any problems Im just wondering why it doesnt say how to add more usernames and passwords!This code that allows me to have one username and passwordWhen you enter the correct username and password from the [url=http://www.webdesignhull.lincoln.ac.uk/jecgardner/newblog/]home page[/url] your taken to the entry page for that post. (username and password = TEST)It told me to add [code]$my_username = "TEST";$my_password = "TEST"; [/code]To the single entry's page which can be found [url=http://www.webdesignhull.lincoln.ac.uk/jecgardner/newblog/journal.php]here[/url]This works fine but I want too add more usernames so I tried:[code]$my_username = "TEST";$my_password = "TEST";$my_username = "TEST2";$my_password = "TEST2"; [/code]This didnt work, it only recognized TEST2 and ignored TEST. I also tried[code]$my_username = "TEST";$my_password = "TEST"; $my_username1 = "TEST2";$my_password1 = "TEST2";[/code]Heres the full code for the single entry page:[code]<?php include("header.html"); ?><?php$my_username = "TEST";$my_password = "TEST"; mysql_connect ('localhost', 'username', 'password') ;mysql_select_db ('username');if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { die("Invalid ID specified.");}$id = (int)$_GET['id'];$sql = "SELECT * FROM php_blog WHERE id='$id' LIMIT 1";$result = mysql_query($sql) or print ("Can't select entry from table php_blog.<br />" . $sql . "<br />" . mysql_error());while($row = mysql_fetch_array($result)) { $date = date("l F d Y", $row['timestamp']); $title = stripslashes($row['title']); $entry = stripslashes($row['entry']); $password = $row['password']; if ($password == 1) { if (isset($_POST['username']) && $_POST['username'] == $my_username) { if (isset($_POST['pass']) && $_POST['pass'] == $my_password) { ?> <p><strong><?php echo $title; ?></strong><br /><br /> <?php echo $entry; ?><br /><br /> Posted on <?php echo $date; ?></p> <?php } else { ?> <p>Sorry, wrong password.</p> <?php } } else { echo "<p><strong>" . $title . "</strong></p>"; printf("<p>This is a password protected entry. If you have a password, log in below.</p>"); printf("<form method=\"post\" action=\"journal.php?id=%s\"><p><strong><label for=\"username\">Username:</label></strong><br /><input type=\"text\" name=\"username\" id=\"username\" /></p><p><strong><label for=\"pass\">Password:</label></strong><br /><input type=\"password\" name=\"pass\" id=\"pass\" /></p><p><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"submit\" /></p></form>",$id); print "<hr /><br /><br />"; } } else { ?> <p><strong><?php echo $title; ?></strong><br /><br /> <?php echo $entry; ?><br /><br /> Posted on <?php echo $date; ?></p> <?php }}?>[/code]This code [url=http://www.webdesignhull.lincoln.ac.uk/jecgardner/newblog/php_blog_table.php]inserts the table[/url] for the blog:[code]<?phpmysql_connect ('localhost', 'username', 'password') ;mysql_select_db ('username');$sql = "CREATE TABLE php_blog ( id int(20) NOT NULL auto_increment, timestamp int(20) NOT NULL, title varchar(255) NOT NULL, entry longtext NOT NULL, PRIMARY KEY (id), UNIQUE KEY id (id))";$result = mysql_query($sql) or print ("Can't create the table 'php_blog' in the database.<br />" . $sql . "<br />" . mysql_error());if ($result != false) { echo "Table 'php_blog' was successfully created.";}mysql_close();?>[/code]I then made a page called [url=http://www.webdesignhull.lincoln.ac.uk/jecgardner/newblog/alter.php]alter.php[/url] which adds a password to the table by using the following code:[code]<?phpmysql_connect ('localhost', 'username', 'password') ;mysql_select_db ('username');$sql = "ALTER TABLE `php_blog` ADD `password` TINYINT DEFAULT '0' NOT NULL";$result = mysql_query($sql) or print ("Can't add the column 'password' to the table 'php_blog' in the database.<br />" . $sql . "<br />" . mysql_error());mysql_close();if ($result != false) { echo "The column 'password' was successfully added to your table 'php_blog'";}?>[/code]Why isnt this 'alter' code in the insert table page? Im not sure how to add more usernames and passwords. Please someone help!! Quote Link to comment Share on other sites More sharing options...
Caesar Posted November 10, 2006 Share Posted November 10, 2006 What you're doing by using the same variable names, is overwriting the previous values. I suggest you go read the very nasics of PHP before tackling any pre-written scripts. Quote Link to comment Share on other sites More sharing options...
foevah Posted November 10, 2006 Author Share Posted November 10, 2006 Yeh but im trying to modify this tutorial.. Have you got a more constructive suggestion pleaseI found a different tutorial explaing how to add usernames and passwords and ive succussfully been able to work the script[url=http://www.free2code.net/plugins/articles/read.php?id=99]http://www.free2code.net/plugins/articles/read.php?id=99[/url][url=http://www.webdesignhull.lincoln.ac.uk/jecgardner/user_db/register.php]Click here to see my attempt at this script[/url]You can register successfully and [url=http://www.webdesignhull.lincoln.ac.uk/jecgardner/user_db/login.php]login here[/url] successfully.The register is a form for adding usernames with passwords to the database. Ive connected to the database in dreamweaver using the MySQL Connection. I just need to figure out how this can be used with the blog im doing lol Quote Link to comment Share on other sites More sharing options...
trq Posted November 10, 2006 Share Posted November 10, 2006 [quote]I just need to figure out how this can be used with the blog im doing[/quote]And what part exactly do you need to [i]figure out[/i]? Quote Link to comment Share on other sites More sharing options...
foevah Posted November 10, 2006 Author Share Posted November 10, 2006 well if this is the right idea I need to know how to merge both the tutorials!The tutorial im using to make my blog only tells me how to have one username and password and this other tutorial site explains how to add users when you register... Its not exactly the same as I want but its similar.. ??? Quote Link to comment Share on other sites More sharing options...
trq Posted November 10, 2006 Share Posted November 10, 2006 And what part EXACTLY are you stuck on?This is what happens when you try to run before you can walk. A basic understanding of what is going on and you would figure this out for yourself. We are not in the habbit of re-writting / customising tutorials to make them fit an indivduals needs.Im sorry, but this just isn't how it works. Quote Link to comment Share on other sites More sharing options...
foevah Posted November 10, 2006 Author Share Posted November 10, 2006 Im stuck on trying to add more then one username and password to the blog database!!!!!!!!!!Im asking someone here to help me understand! Quote Link to comment Share on other sites More sharing options...
Caesar Posted November 11, 2006 Share Posted November 11, 2006 Well, the problem, is that you're trying to piece together scripts from tutorials...which will just confuse you more if you don't know what's going on.Try looking into using MySQL with PHP. And read up the very basics....try to grasp at least a little bit how things such as variables or arrays work. It should make things a lot easier for you. Quote Link to comment Share on other sites More sharing options...
foevah Posted November 11, 2006 Author Share Posted November 11, 2006 I have read the basics Quote Link to comment Share on other sites More sharing options...
foevah Posted November 11, 2006 Author Share Posted November 11, 2006 Am I asking something thats real simple that noone wants to help because I should know this?? I thought ive done well not getting any errors with this blog. Now im trying something thats out of the tutorial and im looking for advice noone will help.... I thought people were here to help! Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 11, 2006 Share Posted November 11, 2006 You need stop relying on free tutorials and go pick up a basic PHP programming book.If you don't understand why[code]$user = 'user';$user = 'user1';[/code]only recognizes 'user1', then I'm sorry but you may have read the basics, but you didn't understand them. Quote Link to comment Share on other sites More sharing options...
Petsmacker Posted November 11, 2006 Share Posted November 11, 2006 What you're asking is for people to help you with something that is obviously out of your league for the moment, people are advising you to work with PHP/SQL a little more and familiarise yourself with it so you actually understand what you're doing. Quote Link to comment Share on other sites More sharing options...
foevah Posted November 11, 2006 Author Share Posted November 11, 2006 Well theres one way of inserting usernames with passwords into the database and thats with a register form.. Quote Link to comment Share on other sites More sharing options...
foevah Posted November 11, 2006 Author Share Posted November 11, 2006 I added my_username2 and my_password2 to this part of the code but this doesnt work.[code]if (isset($_POST['username']) && $_POST['username'] == $my_username $my_username2) { if (isset($_POST['pass']) && $_POST['pass'] == $my_password $my_password2) {[/code] Quote Link to comment Share on other sites More sharing options...
foevah Posted November 11, 2006 Author Share Posted November 11, 2006 ok im guessing that was the wrong way of doing it aswel..The page [url=http://www.webdesignhull.lincoln.ac.uk/jecgardner/newblog/alter.php]alter.php[/url] page adds a password to the table by using the following code:[code]<?phpmysql_connect ('localhost', 'username', 'password') ;mysql_select_db ('username');$sql = "ALTER TABLE `php_blog` ADD `password` TINYINT DEFAULT '0' NOT NULL";$result = mysql_query($sql) or print ("Can't add the column 'password' to the table 'php_blog' in the database.<br />" . $sql . "<br />" . mysql_error());mysql_close();if ($result != false) { echo "The column 'password' was successfully added to your table 'php_blog'";}?>[/code]Why isnt this 'alter' code in the insert table page?Should i duplicate this page and change password to username and add username into the the form page.. Heres the form page code[code]<?php$current_month = date("F");$current_date = date("d");$current_year = date("Y");$current_time = date("H:i");if (isset($_POST['submit'])) { $month = htmlspecialchars(strip_tags($_POST['month'])); $date = htmlspecialchars(strip_tags($_POST['date'])); $year = htmlspecialchars(strip_tags($_POST['year'])); $time = htmlspecialchars(strip_tags($_POST['time'])); $title = htmlspecialchars(strip_tags($_POST['title'])); $entry = $_POST['entry']; $password = htmlspecialchars(strip_tags($_POST['password'])); $timestamp = strtotime($month . " " . $date . " " . $year . " " . $time); $entry = nl2br($entry); if (!get_magic_quotes_gpc()) { $title = addslashes($title); $entry = addslashes($entry); } mysql_connect ('localhost', 'username', 'password') ; mysql_select_db ('username'); $sql = "INSERT INTO php_blog (timestamp,title,entry,password) VALUES ('$timestamp','$title','$entry','$password')"; $result = mysql_query($sql) or print("Can't insert into table php_blog.<br />" . $sql . "<br />" . mysql_error()); if ($result != false) { print "Your entry has successfully been entered into the database."; } mysql_close();}?><form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"><p><strong><label for="month">Date (month, day, year):</label></strong> <select name="month" id="month"><option value="<?php echo $current_month; ?>"><?php echo $current_month; ?></option><option value="January">January</option><option value="February">February</option><option value="March">March</option><option value="April">April</option><option value="May">May</option><option value="June">June</option><option value="July">July</option><option value="August">August</option><option value="September">September</option><option value="October">October</option><option value="November">November</option><option value="December">December</option></select><input type="text" name="date" id="date" size="2" value="<?php echo $current_date; ?>" /><select name="year" id="year"><option value="<?php echo $current_year; ?>"><?php echo $current_year; ?></option><option value="2004">2004</option><option value="2005">2005</option><option value="2006">2006</option><option value="2007">2007</option><option value="2008">2008</option><option value="2009">2008</option><option value="2010">2010</option></select><strong><label for="time">Time:</label></strong> <input type="text" name="time" id="time" size="5" value="<?php echo $current_time; ?>" /></p><p><strong><label for="title">Title:</label></strong> <input type="text" name="title" name="title" size="40" /></p><p><strong><label for="password">Password protect?</label></strong> <input type="checkbox" name="password" id="password" value="1" /></p><p><textarea cols="80" rows="20" name="entry" id="entry"></textarea></p><p><input type="submit" name="submit" id="submit" value="Submit"></p></form>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.