Several new features have been added to the board, check the Announcements for more details!

Need some help with PHP code...

Discuss all the different aspects of the internet in this forum.
User avatar

Topic Author
AVenger
Board Moderators
Board Moderators
Posts: 546
Joined: 11 Aug 2011, 19:02
Tech Knowledge: Advanced
Location: Maryland
Contact:

Need some help with PHP code...

Postby AVenger » 11 Jan 2012, 06:08

Hey guys...

I have had an account on here for a while now but I never used it before :P Now I am and am going to ask for help when I need it and help out when needed also ^_^

Anyways, to my problem...

I have a website http://beta.project-create.net. As you can see by the URL it is in beta stage. I bought a site from a cheap host and just recently transferred the site to a new host. I edited all the code inside the PHP files and created the right databases and set everything up correctly. But when I go to sign in to my account or create a new one, I fill in the form and press the submit button. But nothing happens after that. You can try to create your own account here and you can see how it just stops.

This wasn't happening before I transferred the site or edited the code. I might just be missing one thing, but I have reviewed the code so many times and tried many different fixes that have yet to work, that I'm starting to get irritated. :frustrated:

I am a computer programmer, not a web designer. But I find it fun to web design, so I am working on this so I can work on the program counterpart. If you need to see the code for the PHP files, I'd like to keep them safe and will only send them to you through PM and will not post on the forum.

Thanks to anyone who is willing to help me out ^_^

User avatar

shovenose
Retired Staff
Retired Staff
Posts: 1040
Joined: 05 Feb 2011, 01:50
Tech Knowledge: Expert
Location: On the computer, of course!
Contact:

Re: Need some help with PHP code...

Postby shovenose » 11 Jan 2012, 09:58

Let's see the following:
-The code for the PHP script that sends the email
-The code for the signup page.

User avatar

Topic Author
AVenger
Board Moderators
Board Moderators
Posts: 546
Joined: 11 Aug 2011, 19:02
Tech Knowledge: Advanced
Location: Maryland
Contact:

Re: Need some help with PHP code...

Postby AVenger » 12 Jan 2012, 02:08

Is it alright if I PM them to you?

User avatar

shovenose
Retired Staff
Retired Staff
Posts: 1040
Joined: 05 Feb 2011, 01:50
Tech Knowledge: Expert
Location: On the computer, of course!
Contact:

Re: Need some help with PHP code...

Postby shovenose » 12 Jan 2012, 09:56

Yup. I guess if you don't want to paste all your code here for security reasons that makes sense :D

User avatar

Topic Author
AVenger
Board Moderators
Board Moderators
Posts: 546
Joined: 11 Aug 2011, 19:02
Tech Knowledge: Advanced
Location: Maryland
Contact:

Re: Need some help with PHP code...

Postby AVenger » 21 Jan 2012, 09:49

Okay well after moving on and then coming back, it works now :P Not sure what happened. But it works now. I'm just trying to finish up the signup, signin, signout code. I'm using a verify page to transfer the user from the temporary database to the actual one. Here is the PHP code for it:

Code: Select all

<?php
session_start();
ob_start();
include('lib/connection.php');
$conn = dbConnect('write');
// Passkey that got from link
$passkey = htmlspecialchars($_GET['passkey']);
// Retrieve data from table where row that match this passkey
$sql = "SELECT * FROM temp_users_tb WHERE confirm_code = '$passkey'";
$result = $conn->query($sql);
$numRows = $result->num_rows;
$link = "";
$print = "";
$user = "";
if($passkey != null) {
   if($numRows == 1) {
      $newUser = $result->fetch_array();
      $name = $newUser['username'];
      $email = $newUser['email'];
      $password = $newUser['password'];
      $linkToPic = "http://project-create.net/profilepics/feeling_blue.jpg";
      $sql = "INSERT INTO users_tb (username, email, password, reg_time, linkToPic) VALUES ('$name', '$email', '$password', CURDATE(), '$linkToPic')";
      $result = $conn->query($sql);
      $print = "";
      // Delete information of this user from table "temp_members_db" that has this passkey
      $sql = "DELETE FROM temp_user_tb WHERE confirm_code = '$passkey'";
      $conn->query($sql);
      $sql = "SELECT * FROM info_tb WHERE id = '1'";
      $result = $conn->query($sql);
      $infoArr = $result->fetch_array();
      $users = $infoArr['numOfUsers'] + 1;
      $sql = "UPDATE info_tb SET numOfUsers = '$users' WHERE id = '1'";
      $conn->query($sql);
      $sql = "SELECT * FROM users_tb WHERE username = '$name'";
      $result = $conn->query($sql);
      $userArr = $result->fetch_array();
      $id = $userArr['user_id'];
      $link = "setup_profile.php?id=$id";
   } else {
      // if not found passkey, display message "Wrong Confirmation code"
      $print = "Wrong confirmation code";
   }
} else {
   $print = "No confirmation code found. Please follow the link in the email that was sent to you.";
}
?>


It will act like it has done all of the commands and it worked. But the only thing it actually does is add another user to the info table. I'm not sure if there is a syntax or spelling error. It is late here and I will review the code again tomorrow. But I thought I would ask you guys if you see anything that is wrong here.

Thanks guys!

User avatar

Topic Author
AVenger
Board Moderators
Board Moderators
Posts: 546
Joined: 11 Aug 2011, 19:02
Tech Knowledge: Advanced
Location: Maryland
Contact:

Re: Need some help with PHP code...

Postby AVenger » 21 Jan 2012, 18:51

I got it working finally. I did have a spelling error that I had missed last night. So the signup, signin, signout of my site is now working. I also setup an account profile. But now I'm going to work on the resetting your password and make sure that is working right.

Here is my final code, by the way, if anyone wanted to see what it looked like.

Code: Select all

<?php
session_start();
ob_start();
// connect to database
include('lib/connection.php');
$conn = dbConnect('write');
// get the passkey from the link
$passkey = htmlspecialchars($_GET['passkey']);
// Retrieve the number of rows from the table that matches the passkey
$sql = "SELECT * FROM temp_users_tb WHERE confirm_code = '$passkey'";
$result = $conn->query($sql);
$numRows = $result->num_rows;
// setup some variables
$link = "";
$print = "";
$user = "";
if($passkey != null) {
   if($numRows == 1) {
      // Retrieve the data from the table that matches the passkey
      $sql = "SELECT * FROM temp_users_tb WHERE confirm_code = '$passkey'";
      $result = $conn->query($sql);
      $newUser = $result->fetch_array();
      // fill variables with data
      $name = $newUser['username'];
      $email = $newUser['email'];
      $password = $newUser['password'];
      $linkToPic = "http://project-create.net/profilepics/feeling_blue.jpg";
      // insert a new row in the users table
      $sql = "INSERT INTO users_tb (username, email, password, reg_time, linkToPic) VALUES ('$name', '$email', '$password', CURDATE(), '$linkToPic')";
      $result = $conn->query($sql);
      $print = "";
      // Delete information of this user from temporary table that has this passkey
      $sql = "DELETE FROM temp_users_tb WHERE confirm_code = '$passkey'";
      $conn->query($sql);
      // add another user to the num of registered users
      $sql = "SELECT * FROM info_tb WHERE id = '1'";
      $result = $conn->query($sql);
      $infoArr = $result->fetch_array();
      $users = $infoArr['numOfUsers'] + 1;
      $sql = "UPDATE info_tb SET numOfUsers = '$users' WHERE id = '1'";
      $conn->query($sql);
      // get the id of the new user
      $sql = "SELECT * FROM users_tb WHERE username = '$name'";
      $result = $conn->query($sql);
      $userArr = $result->fetch_array();
      $id = $userArr['user_id'];
      // send the new user to setup his profile
      $link = "setup_profile.php?id=$id";
   } else {
      // if the passkey was not found, display message "Wrong Confirmation code"
      $print = "Wrong confirmation code";
   }
} else {
   $print = "No confirmation code found. Please follow the link in the email that was sent to you.";
}
?>


** I also re-commented, so you can understand what is what this time ;)


Return to “Internet Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest

cron