Jump to content

beginPHP

Members
  • Posts

    6
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

beginPHP's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Wow... sorry I misunderstood your post O'mighty genius... No reason to be a douche bag. *Sigh* Maybe you need to rethink how you try to explain things to a noob trying to learn a new language so you don't sound like such a prick. I can see this is getting nowhere, I'll just find a better forum to get an answer... thank you for your input everyone
  2. If it were an issue with my hosting wouldn't all .php files have this issue? All the other files work fine
  3. I think I found the issue but not sure how to solve it... and frankly I think it's best I just start over. lol The greater than sign in this bit of code if ( (isset($_GET['id'])) AND ($_GET['id'] > 0) ) is beign recognized as the closing of <?php. What would cause that? I am using IE9 and Chrome. Chrome displays the entire page as text.
  4. I haven't gotten into SESSIONs yet, I just wanted to get this functional then I planned on reading up and making it more secure later. Sorry for the delayed response, I'm not getting email updates for replies... I must have changed it and forgot. file134.php content <?php $con = mysql_connect("XXXXX","XXXXX","XXXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } if (isset($_GET['id']) AND $_GET['id'] > 0) { mysql_select_db("XXXXX", $con); $mysql_query = "UPDATE news SET Author = '$_POST[author]', title = '$_POST[title]', date = NOW(),body = '$_POST[body]' WHERE id= $row['id'] "; } if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Record updated, click <a href='file130.php'>here</a> to return to the list of records."; mysql_close($con); ?> I'm not sure how I have the code read the previous PHP file...
  5. Noob here learning PHP with a MySQL database. I know that this isn't the best way to connect to a database and I should probably be using variables as well as stored procedures. I just want to make this functional then I will go back and learn how to make it more secure. I've put a database together with 5 fields, id, author, title, date, body. id is the primary key set as autoincrement. Currently I have a page that displays each row in the database and has an option at the bottom to add a new entry. I want to add the option to edit a current entry. I've spent the last 2 hours doing trial/error and reading forums and I don't really feel like I've made any headway. My Main page <?php $con = mysql_connect("XXXXX","XXXXX","XXXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("XXXXX", $con); $result = mysql_query("SELECT * FROM news"); echo "<table border='1'> <tr> <th>ID</th> <th>Author</th> <th>Title</th> <th>Date</th> <th>Body</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['author'] . "</td>"; echo "<td>" . $row['title'] . "</td>"; echo "<td>" . $row['date'] . "</td>"; echo "<td>" . $row['body'] . "</td>"; echo "<td><a href='file133.php?id=" . $row['id'] . "'>edit</a></td>"; echo "</tr>"; } echo "</table>"; echo "<form action='file132.php' method='post'> <table> <tr><td>Author:</td><td> <input type='text' name='author'></td></tr> <tr><td>Title:</td><td> <input type='text' name='title'></td></tr> <tr><td>Body:</td><td> <input type='text' name='body' size='75'></td></tr> <tr><td></td><td><input type='submit' value='Submit'></td></tr> </table> </form>"; mysql_close($con); ?> Clicking Edit takes you to this page where you can enter in the new data <?php $con = mysql_connect("XXXXX","XXXXX","XXXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } if (isset($_GET['id']) AND $_GET['id'] > 0) { mysql_select_db("XXXXX", $con); echo "<form action='file134.php' method='post'> <table> <tr><td>Author:</td><td> <input type='text' name='author'></td></tr> <tr><td>Title:</td><td> <input type='text' name='title'></td></tr> <tr><td>Body:</td><td> <input type='text' name='body' size='75'></td></tr> <tr><td></td><td><input type='submit' value='Submit'></td></tr> </table> </form>"; } mysql_close($con); ?> When you click submit it goes to this page. I know this code below is all wrong because it just displays the actual code from the 0) to the end. I just need some direction on how to make this functional. <?php $con = mysql_connect("XXXXX","XXXXX","XXXXX"); if (!$con) { die('Could not connect: ' . mysql_error()); } if (isset($_GET['id']) AND $_GET['id'] > 0) { mysql_select_db("XXXXX", $con); $mysql_query = "UPDATE news SET Author = '$_POST[author]', title = '$_POST[title]', date = NOW(),body = '$_POST[body]' WHERE id= $row['id'] "; } if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "Record updated, click <a href='file130.php'>here</a> to return to the list of records."; mysql_close($con); ?>
  6. I want to apologize ahead of time for the length of this post... to many questions I'm still new to PHP, infact I've never had a class with anything to do with it. This is more of a hobby I have picked up in the last year or so. I've played around with HTML enough to have built a collaboration site for my friends and I's fantasy football leagues. We don't run the leagues from the site, simply a place where all players within the 4 leagues can talk trash, see how they match up with other players in another league, and there is a tournament between the four. I've made a registration page that works great although it is supposed to verify all info was entered and it doesn't, but I can deal with that for now. The login script I wrote is failing though. It is supposed to verify the username and password and remember the user if the checkbox for it has been checked. When I try to login with the test account I created I get an invalid password error and I know its the correct one. I've verified it in my database a few times. This is the INSERT portion of my registration page: $insert = mysql_query("insert into users values ('" .$_POST['firstname']."', '" .$_POST['lastname']."', '" .$_POST['email']."', '" .$_POST['username']."', '" .$_POST['password']."')"); echo "Your user account has been created!"; echo "Now you can <a href=index.htm>log in</a>" ; LOGIN SCRIPT I've highlighted the area I think the issue is in but I'm not sure. It is using the md5 encryption on the login script but its not on the registration page. I'm not sure how I would go about using this encryption. I have no idea if the issue is somewhere else in the script. If anyone can tell me off the top of your head I've been wanting to add an authentication for the email account within the registration script to. I got the idea from a different site the other day but I don't know how to go about doing it. After the user registers I wanted it to send an email to the account they used to signup with and provide a link to verify the email address. Just a thought if anyone knows how I can do that off the top of their head. I thank everyone in advance that can helpout with this. function confirmUser($username, $password){ global $conn; if(!get_magic_quotes_gpc()) { $username = addslashes($username); } $q = "select password from users where username = '$username'"; $result = mysql_query($q); if(!$result || (mysql_numrows($result) < 1)){ return 1; //Indicates username failure } $dbarray = mysql_fetch_array($result); $dbarray['password'] = stripslashes($dbarray['password']); $password = stripslashes($password); if($password == $_POST['password']){ return 0; //Success! Username and password confirmed } else{ return 2; //Indicates password failure } } function checkLogin(){ if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookpass'])){ $_SESSION['username'] = $_COOKIE['cookname']; $_SESSION['password'] = $_COOKIE['cookpass']; } if(isset($_SESSION['username']) && isset($_SESSION['password'])){ /* Confirm that username and password are valid */ if(confirmUser($_SESSION['username'], $_SESSION['password']) != 0){ unset($_SESSION['username']); unset($_SESSION['password']); return false; } return true; } else{ return false; } } function displayLogin(){ global $logged_in; if($logged_in){ echo "<h1>Logged In!</h1>"; echo "Welcome <b>$_SESSION[username]</b>, you are logged in. <a href=\"members.php\">Members Site</a>"; } else{ ?> <? } } if(isset($_POST['sublogin'])){ /* Check that all fields were typed in */ if(!$_POST['user'] || !$_POST['password']){ die('You didn\'t fill in a required field. Please <a href="index.htm">try again.</a>'); } $md5pass = md5($_POST['pass']); $result = confirmUser($_POST['user'], $md5pass); if($result == 0){ echo ('Welcome <b>$_SESSION[username]</b>, you are logged in. Please continue to the <a href="members.php">Members Site</a>'); } if($result == 1){ die('That username doesn\'t exist in our database, please <a href="index.htm">try again.</a>'); } else if($result == 2){ die('Incorrect password, please <a href="index.htm">try again.</a>'); } $_POST['user'] = stripslashes($_POST['user']); $_SESSION['username'] = $_POST['user']; $_SESSION['password'] = $md5pass; if(isset($_POST['remember'])){ setcookie("cookname", $_SESSION['username'], time()+60*60*24*100, "/"); setcookie("cookpass", $_SESSION['password'], time()+60*60*24*100, "/"); } echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[php_SELF]\">"; return; } $logged_in = checkLogin(); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.