473,378 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

admin login

Hello All,

I'm new to the world of php. I've just had a site designed for me by a company, and I'm now trying to manage and grow it, so it will suit my needs.

The site was built in a folder called mysite.com/test. I coppied this folder a number of times, so I now have mysite.com/test2, mysite.com/test3 etc. Each folder acts as its own landing page.

they setup an interface where we can control the upsells presented to the customer; basically a template. To access, I go to mysite.com/test/admin.php to login. I'd like to be able to be able to have a separate login for each landing page, so I'm trying to setup access at mysite.com/test2/login.php.

I've copied my database, so that there are 2. I've pointed my dbconnect.php to the new database I created.

Originally, the code looked like this;

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. mysql_connect("localhost", "energym2_wp01", "***");
  3. mysql_select_db("energym2_wp01");
  4. ?>
In my test2 folder, I changed the code to this;

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. mysql_connect("localhost", "energym2_wp01", "***");
  3. mysql_select_db("energym2_wp02");
  4. ?>
energym2_wp02 being the new database I created.

When I try to login, I get the following error;

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/energym2/public_html/test3/login.php on line 15
Below is the relevant (I think) code from the login page in /test2

Expand|Select|Wrap|Line Numbers
  1. if($_POST["btnLogin"] == "Login")
  2. {
  3.     $sqlAuthentication = "SELECT id FROM tbl_admin_info WHERE UserID ='".$_POST["txtUserID"]."' AND Password ='".$_POST["txtPassword"]."'";
  4.     $resAuthentication = mysql_query($sqlAuthentication);
  5.     $arrAuthentication = mysql_fetch_array($resAuthentication);
  6.     $UsersID           = $arrAuthentication['id'];
  7.     $Role              = "Admin";
  8.  
  9.     if($UsersID > 0)
  10.     {
  11.  
  12.         $_SESSION['id']   = $UsersID;
  13.         $_SESSION['Role'] = $Role;
  14.  
  15.         header("location:productAdmin.php");
  16.  
  17.     }
  18.     else
  19.     {
  20.         $error = "<font style='color:#FF0000; width:170px;'>Invalid Login. Please Try Again!!!</font>";
  21.     }
  22. }
  23.  
  24. mysql_close();

Any thoughts, ideas, suggestions would be greatly appreciated.

Please let me know if there is any additional info required to answer this question.

Andrew
Oct 18 '09 #1
9 7491
TheServant
1,168 Expert 1GB
Welcome to Bytes.
Use [code] tags around your code to make it easier to read.

A few things could be improved, but starting with the basics: The MySQL error you ahve is because mysql_fetch_array has been given an input that it wasn't expecting, like a NULL value or an error. Try replace relavent code with this and tell us the output:
Expand|Select|Wrap|Line Numbers
  1. /* Instead of: */
  2. $resAuthentication = mysql_query($sqlAuthentication);
  3. /* Use this: */
  4. $resAuthentication = mysql_query($sqlAuthentication) or die(mysql_error());
There is something wrong with your query, and adding a die() will stop if tehre is any error. Putting something in the die("There was an error") will display "There was an error" if there is any error. Finally, the function mysql_error() shows any error that happened. This is one of the best debugging techniques especially while you are still developing.
Oct 18 '09 #2
Thanks for the reply TS.

I'd like to expand a little to make sure we're both on the same page.

The template that was built works. When I go to mysite.com/test/login.php I can login and make changes to the upsells that are presented to our customers when they check out (pictures, discriptions, prices, etc.)

When I created mysite.com/test2, I went to mysite.com/test2/login.php and I was able to login using the same username and password that I use to login at /test/login.php.

What I noticed was that I was controlling the same interface. It didn't matter if I was logging in at test, test2, test3; I was always accessing the same template (ie. every landing page would have the same upsells presented to our customer).

When I inquired into this, it was brought to my attention that I need to point the dbconnect.php in each folder to a separate database, in order for each folder/landing-page to own its own template. This led me to copy the exiting database 'wp01' and create an identical database (identical for now anyways) which I named 'wp02'.

Initially I changed both instances of 'energym2_wp01' to 'energym2_wp02' in the dbconnect.php code located in /test2. When I went to see if it worked, by logging in at /test2/login.php the page had the following warnings at the top.



Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'energym2_wp02'@'localhost' (using password: YES) in /home/energym2/public_html/test3/includes/dbConnect.php on line 2
Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'energym2'@'localhost' (using password: NO) in /home/energym2/public_html/test3/includes/dbConnect.php on line 3
Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/energym2/public_html/test3/includes/dbConnect.php on line 3
Warning: mysql_close(): no MySQL-Link resource supplied in /home/energym2/public_html/test3/login.php on line 34



When I try to login using the username and password I use for test/login.php, I get the following;


Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'energym2_wp02'@'localhost' (using password: YES) in /home/energym2/public_html/test3/includes/dbConnect.php on line 2
Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'energym2'@'localhost' (using password: NO) in /home/energym2/public_html/test3/includes/dbConnect.php on line 3
Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/energym2/public_html/test3/includes/dbConnect.php on line 3
Warning: mysql_query() [function.mysql-query]: Access denied for user 'energym2'@'localhost' (using password: NO) in /home/energym2/public_html/test3/login.php on line 14
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/energym2/public_html/test3/login.php on line 14
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/energym2/public_html/test3/login.php on line 15
Warning: mysql_close(): no MySQL-Link resource supplied in /home/energym2/public_html/test3/login.php on line 34
In addition, I get the message 'Invalid Login. Please Try Again!!!'



I'm assuming that the username and password we use to sucessfully login at test/login.php is somewhere within the database that I copied, which is why I'm using the same username and password at test2/login.php. Maybe this isn't the case?



Anyway, I looked at the code in dbConnect.php and decided I would try again, this time leaving "energym2_wp01" in the mysql_connect and using "energym2_wp02" in the mysql_select_db (initially I had changed both to wp02).

This led to the content that I originally provided in my first post.

Either way, I can still login to /test/login.php which is why I'm thinking it's not a problem with the code since it worked/works. I think the problem lies i the fact that I don't understand what I'm doing and have likely neglected to change something somewhere along the line.



Thanks again, and please excuse any bad form on my part. I appreciate the help and any additional guidance that helps me present this to you in a fashion that best suits this forum. I'm trying to learn as I go here and any suggestions in the way of online tutorials or other learning tools are also appreciated.
Oct 19 '09 #3
TheServant
1,168 Expert 1GB
I am not sure if I understand correctly, but with regards to templates you do not need a duplicated database?? Your database code, and PHP are together, and then your html and css are together. I don't know what you mean by template, because if it is just the display of data then you simply need to select a different stylesheet.

Your error messages are not about what's in the database, as they say, and I am sure you know, it is that you cannot connect to the database because your username and password are not correct. The username and password to access a database is not stored in that same database, but rather in a special MySQL one to log which users have access to which database. When you create a databse youneed to assign users (along with privilages) to each database. I think that you have forgotten to do this with your new (copied) database. Checkup on that and let me know what software you are using for databases?

**ALSO** I am not a moderator, so I can't hide it for you, but if that's your real password for your MySQL connection, I suggest you change it, as it has now been shown to the world through this post (your first post).
Oct 19 '09 #4
Cool. That's definitely it. I never setup access to the new db.

I did a search through those posts for my username and pw and it didn't come up, so I don't think I divulged that info, but it's due to be changed soon anyway.

I'll setup access to the new db and play around a bit to see if I can get it working. I'll report back sometime tomorrow.

Thanks again.

Andrew
Oct 19 '09 #5
TheServant
1,168 Expert 1GB
No worries, let us know how you go.

And thanks Dorm for the code tags and **** ;)
Oct 19 '09 #6
Dormilich
8,658 Expert Mod 8TB
@TheServant
isn’t that what Mods are for? ;)
Oct 19 '09 #7
supun24
11
Hi.. You can create one login page for every page you visiting. If someone loged in to database. It will create new session. every page is searching for session and if can't find, it will redirect to login page..

This is login page index.php

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4.  
  5. <script type="text/javascript">
  6. function setFocus()
  7. {
  8. document.getElementById("username").focus();
  9. }
  10. </script>
  11.  
  12. <script language="JavaScript" type="text/javascript">
  13. <!--
  14. if (top==self)
  15. self.location.href="blank.php";
  16. -->
  17. </script>
  18.  
  19.  
  20. <title>Member Login</title>
  21. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  22. </head>
  23. <body onload="setFocus()">
  24. <form name="login-form" id="login-form" method="post" action="manage-check.php">
  25.   <table width="207" height="108" border="1">
  26.     <tr>
  27.         <td width="197" height="102"><input name="submit" type="submit" style="position:absolute; left: 84px; top: 84px; width: 53px;" tabindex="3" value="Login" />
  28.       <input name="button" type="button" id="button" style="position:absolute; left: 144px; top: 84px; width: 55px;" tabindex="4" onClick="window.location.href='blank.php'" value="Cancel"/>
  29.      </td>
  30.     </tr>
  31.   </table>
  32.  
  33.   <label title="Username"><br />
  34.  
  35.     <input name="username" type="text" id="username" style="position:absolute; left: 102px; top: 28px; width: 100px;" tabindex="1" maxlength="100" />
  36.   </label>
  37.   <br />
  38. <br />
  39.   <label title="Password">
  40.     <input name="password" type="password" id="password" style="position:absolute; left: 102px; top: 55px; width: 100px;" tabindex="2" maxlength="14" />
  41.   <input name="" type='text' style='border-style:none; position:absolute; left: 20px; top: 29px; width: 75px;' value='User Name' onClick="setFocus();">
  42.       <input name="" type='text' style='border-style:none; position:absolute; left: 20px; top: 55px; width: 75px;' value='Password'>
  43.   </label>
  44. <dl>
  45.   <dt>&nbsp;</dt>
  46. </dl>
  47. </form>
  48. </body>
  49. </html>
  50.  

This is Second page manage-check.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. include('db.php');
  4. if(isset($_POST['submit'])) :
  5. // Username and password sent from signup form
  6. // First we remove all HTML-tags and PHP-tags, then we create a sha1-hash
  7. $username = strip_tags($_POST['username']);
  8. $password = sha1(strip_tags($_POST['password']));
  9. // Make the query a wee-bit safer
  10. $query = sprintf("SELECT ID FROM members WHERE username = '%s' AND user_password = '%s' LIMIT 1;", mysql_real_escape_string($username), mysql_real_escape_string($password));
  11. $result = mysql_query($query);
  12. if(1 != mysql_num_rows($result)) :
  13. // MySQL returned zero rows (or there's something wrong with the query)
  14. header('Location: member.php');
  15. else :
  16. // We found the row that we were looking for
  17. $row = mysql_fetch_assoc($result);
  18. // Register the user ID for further use
  19. $_SESSION['member_ID'] = $row['ID'];
  20. header('Location: member.php');
  21. endif;
  22. endif;
  23. ?>
This is Database Connection db.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. if(!session_is_registered('member_ID')) :
  4. header('Location: index.php');
  5. endif;
  6. define('SQL_USER', '***');
  7. define('SQL_PASS', '***');
  8. define('SQL_DB', 'home');
  9. // Create a link to the database server
  10. $link = mysql_connect('localhost', SQL_USER, SQL_PASS);
  11. if(!$link) :
  12. die('Could not connect: ' . mysql_error());
  13. endif;
  14. // Select a database where our member tables are stored
  15. $db = mysql_select_db(SQL_DB, $link);
  16. if(!$db) :
  17. die ('Can\'t connect to database : ' . mysql_error());
  18. endif;
  19. ?>
This is function file functions.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. function user_info($field='') {
  3. // If $field is empty
  4. if(empty($field))
  5. return false;
  6. // Check to see if we're allowed to query the requested field.
  7. // If we add other fields, such as name, e-mail etc, this array
  8. // will have to be extended to include those fields.
  9. $accepted = array('username', 'user_password');
  10. if(!in_array($field, $accepted))
  11. return false;
  12. // Poll the database
  13. $result = mysql_query("SELECT ". $field ." FROM members WHERE ID = ". $_SESSION['member_ID'] .";");
  14. // If we don't find any rows
  15. if(1 != mysql_num_rows($result)) :
  16. return false;
  17. else :
  18. // We found the row that we were looking for
  19. $row = mysql_fetch_assoc($result);
  20. // Return the field
  21. return $row[$field];
  22. endif;
  23. } // end user_info
  24. ?>
Login Complete page member.php

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Start a session
  3. session_start();
  4. // Sends the user to the login-page if not logged in
  5. if(!session_is_registered('member_ID')) :
  6. echo "<a href='index.php' target='homeif'>Member Login</a> <br>";
  7. echo "<a href='register.php'>Register</a>";
  8. else:
  9. include 'db.php';
  10. include 'functions.php';
  11. echo "<Strong> Welcome ";
  12. print user_info('username');
  13. echo "</strong>";
  14. echo "<br><a href='logout.php'>Logout</a>";
  15. endif;
  16. ?>
  17. <head>
  18. </head>
  19. <body>
  20. </body>
Oct 19 '09 #8
Thanks Supun24. Unfortunately, that's a little over my head.

Part of my problem here is that I'm trying to keep our /test folder intact and not mess around too much with the code I've been given. The thought being that this firm has committed to getting this site up and operational for us, so I don't really mess with what's in /test; that's all theirs. I've just created my own folder /test2 which is where I'm doing all my messing around.

Firstly, TS, I've granted the user that was setup with rights to db 'wp_01' access to the second db I created, 'wp_02'. That worked. I'm now able to login at test2/login.php and the changes I make to the orderpage (our upsells) stay intact. This means that customers that are directed to test/orderpage.php are given different upsell options than customers that are directed to test2/orderpage.php.

orderpage.php is our template. The code for the template (productAdmin.php) looks as follows.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. include_once("includes/dbConnect.php");
  4. include_once("includes/pagerForAll.php");
  5.  
  6. if($_SESSION['Role'] != 'Admin') header("location:login.php");
  7.  
  8. if($_GET[edit]) $_POST['hdnProductID'] = $_GET['edit'];
  9.  
  10. if($_SERVER['REQUEST_METHOD'] == "POST")
  11. {
  12.     $extension = "";
  13.     if($_FILES['browseFile']['name'] != "")
  14.     {
  15.         $fileName      = "Product".date("Ymdhmi").$_FILES['browseFile']['name'];
  16.         $tmpPath       = $_FILES['browseFile']['tmp_name']; 
  17.         $sizeOfFile    = $_FILES['browseFile']['size'];
  18.         $target        = "files/";
  19.         $file           = $target.$fileName;
  20.  
  21.         $arrFileName   =  explode(".", $fileName);             
  22.  
  23.         $extension     =  $arrFileName[count($arrFileName)-1]; 
  24.         $extension     =  strtolower($extension); 
  25.     }
  26.  
  27.     if($extension == "jpg" || $extension == "jpeg" || $extension == "png" || $extension == "gif" || $extension == "tif")
  28.     {
  29.         if(move_uploaded_file($tmpPath, $file))
  30.         {            
  31.             if($_POST['hdnProductID'] < 1)
  32.             {
  33.                 if(trim($_POST['txtOrder']) == "") $_POST['txtOrder'] = 0;
  34.                 $sqlOrder   = "SELECT order_position FROM product WHERE order_position=".$_POST['txtOrder']; 
  35.                 $resOrder   = mysql_query($sqlOrder);
  36.                 $rowCount   = mysql_num_rows($resOrder);
  37.  
  38.                 if($rowCount > 0)
  39.                 {
  40.                     $sqlMaxOrder       = "SELECT (max(order_position) + 1) As MaxOrder FROM product";
  41.                     $resMaxOrder       = mysql_query($sqlMaxOrder);
  42.                     $arrMaxOrder       = mysql_fetch_array($resMaxOrder);
  43.                     $intMaxOrder       = $arrMaxOrder['MaxOrder'];
  44.                     $_POST['txtOrder'] = $intMaxOrder;
  45.                 }
  46.  
  47.                 $sqlInsert  = "INSERT INTO product(product_name, description, price, order_position, filename) VALUES ('".$_POST['txtProduct']."', '".addslashes(str_replace('"',"\'",trim($_POST['txtDescription'])))."',".$_POST['txtPrice'].",".$_POST['txtOrder'].",'".$fileName."')";
  48.                 $resInsert  = mysql_query($sqlInsert);
  49.                 $insertID   = mysql_insert_id();
  50.  
  51.                 if($insertID > 0) $strError .= "<font style='color:#006633'>Inserted Successfully</font>";
  52.             }
  53.             else
  54.             {
  55.                 $sqlUpdate  = "  UPDATE product SET ";
  56.                 $sqlUpdate .= "  product_name        = '".$_POST['txtProduct']."'";
  57.                 $sqlUpdate .= ", description         = '".addslashes(str_replace('"',"\'",trim($_POST['txtDescription'])))."'";
  58.                 $sqlUpdate .= ", price               = '".$_POST['txtPrice']."'";
  59.                 $sqlUpdate .= ", order_position      = '".$_POST['txtOrder']."'";
  60.                 $sqlUpdate .= ", filename            = '".$fileName."'";
  61.                 $sqlUpdate .= "  WHERE id            = ".$_POST['hdnProductID'];
  62.  
  63.                 $resUpdate  = mysql_query($sqlUpdate);
  64.                 $rowUpdate  = mysql_affected_rows();
  65.  
  66.                 if($rowUpdate > 0) $strError .= "<font style='color:#006633'>Updated Successfully</font>";    
  67.             }
  68.  
  69.             $_POST['txtProduct']      = "";
  70.             $_POST['txtDescription'] = "";
  71.             $_POST['txtOrder']         = "";
  72.             $_POST['hdnProductID']    = "";
  73.             $_POST['hdnOrder']         = "";
  74.         }
  75.         else
  76.         {
  77.             $strError .= "<font style='color:#FF0000'>Max Upload File Size is 3.5 MB</font>";
  78.         }
  79.     }
  80.     else if($extension == "" && $_POST['hdnProductID'] > 0)
  81.     {
  82.         if($_POST['hdnOrder'] > 0)
  83.         {
  84.               $sqlUpd = "UPDATE product SET order_position=".$_POST['hdnOrder']." WHERE order_position = ".$_POST['txtOrder'];
  85.               $resUpd = mysql_query($sqlUpd);
  86.         }
  87.  
  88.         $sqlUpdate  = "  UPDATE product SET ";
  89.         $sqlUpdate .= "  product_name        = '".$_POST['txtProduct']."'";
  90.         $sqlUpdate .= ", description         = '".addslashes($_POST['txtDescription'])."'";
  91.         $sqlUpdate .= ", price               = '".$_POST['txtPrice']."'";
  92.         $sqlUpdate .= ", order_position = '".$_POST['txtOrder']."'";
  93.         $sqlUpdate .= "  WHERE id       = ".$_POST['hdnProductID'];
  94.  
  95.         $resUpdate  = mysql_query($sqlUpdate);
  96.         $rowUpdate  = mysql_affected_rows();
  97.  
  98.         if($rowUpdate > 0) $strError .= "<font style='color:#006633'>Updated Successfully</font>";    
  99.  
  100.         $_POST['txtProduct']      = "";
  101.         $_POST['txtDescription'] = "";
  102.         $_POST['txtOrder']         = "";
  103.         $_POST['hdnProductID']   = "";
  104.         $_POST['hdnOrder']         = "";
  105.         $_POST['txtPrice']       = "";
  106.     }
  107.     else if($extension == "" && $_POST['hdnProductID'] < 1)
  108.     {
  109.             $sqlOrder   = "SELECT order_position FROM product WHERE order_position=".$_POST['txtOrder']; 
  110.             $resOrder   = mysql_query($sqlOrder);
  111.             $rowCount   = mysql_num_rows($resOrder);
  112.  
  113.             if($rowCount > 0)
  114.             {
  115.                 $sqlMaxOrder       = "SELECT (max(order_position) + 1) As MaxOrder FROM product";
  116.                 $resMaxOrder       = mysql_query($sqlMaxOrder);
  117.                 $arrMaxOrder       = mysql_fetch_array($resMaxOrder);
  118.                 $intMaxOrder       = $arrMaxOrder['MaxOrder'];
  119.                 $_POST['txtOrder'] = $intMaxOrder;
  120.             }
  121.  
  122.             $fileName = "noimage.jpg";
  123.  
  124.             $sqlInsert  = "INSERT INTO product(product_name, description, order_position, filename) VALUES ('".$_POST['txtProduct']."', '".addslashes($_POST['txtDescription'])."',".$_POST['txtOrder'].",'".$fileName."')";
  125.             $resInsert  = mysql_query($sqlInsert);
  126.             $insertID   = mysql_insert_id();
  127.  
  128.             if($insertID > 0) $strError .= "<font style='color:#006633'>Inserted Successfully</font>";
  129.             $_POST['txtProduct']      = "";
  130.             $_POST['txtDescription'] = "";
  131.             $_POST['txtOrder']         = "";
  132.             $_POST['hdnProductID']   = "";
  133.             $_POST['hdnOrder']         = "";
  134.             $_POST['txtPrice']       = "";
  135.     }
  136.     else
  137.     {
  138.         $strError .="<font style='color:#FF0000'>Improper File</font>";
  139.     }
  140. }
  141. else if($_GET['edit']!="")
  142. {
  143.      $sqlSelectById             = "SELECT * FROM product where id=".$_GET['edit'];
  144.      $resSelectById             = mysql_query($sqlSelectById);
  145.  
  146.      $_POST['txtProduct']       = mysql_result($resSelectById, 0, "product_name");
  147.      $_POST['txtDescription']   = mysql_result($resSelectById, 0, "description");
  148.      $_POST['txtOrder']          = mysql_result($resSelectById, 0, "order_position");
  149.      $_POST['txtPrice']         = mysql_result($resSelectById, 0, "price");
  150.      $_POST['hdnProductID']     = mysql_result($resSelectById, 0, "id"); 
  151.      $_POST['hdnFileName']      = mysql_result($resSelectById, 0, "filename");
  152.      $_POST['hdnOrder']            = mysql_result($resSelectById, 0, "order_position");
  153.      $image                        = mysql_result($resSelectById, 0, "filename");  
  154. }
  155. else if($_GET['delete'] != "")
  156. {
  157.     @unlink($_GET['fileName']);
  158.  
  159.     $sqlSelect = "SELECT order_position FROM product WHERE id=".$_GET['delete'];
  160.     $resSelect = mysql_query($sqlSelect);
  161.     $cntSelect = mysql_num_rows($resSelect) > 0 ? mysql_result($resSelect, 0, "order_position") : "0";
  162.  
  163.     if($cntSelect > 0)
  164.     {
  165.         $sqlUpdOrder = "UPDATE product SET order_position = order_position - 1 WHERE order_position > ".$cntSelect;
  166.         $resUpdOrder = mysql_query($sqlUpdOrder);
  167.  
  168.         $sqlDelete = "DELETE FROM product WHERE id=".$_GET['delete'];
  169.         $resDelete = mysql_query($sqlDelete);
  170.         $rowDelete = mysql_affected_rows();
  171.  
  172.         if($rowDelete > 0)  $strError .= "<font style='color:#006633'>Deleted Successfully</font>";
  173.     }
  174. }
  175.  
  176. $pageRows          = 5;
  177. $intFromRecord      = 0;
  178. $pagenum          = 1;
  179.  
  180. $sqlCount      = "SELECT count(id) As Count FROM product";
  181.  
  182. $resCount           = mysql_query($sqlCount);
  183. $numRowsDb        = mysql_result($resCount, 0, "Count"); 
  184.  
  185. $numOfPages          = ceil($numRowsDb/$pageRows);
  186.  
  187. if($_GET['pageNum'])
  188.     $pagenum   = $_GET['pageNum'];
  189.  
  190. if(!(isset($pagenum))) 
  191.     $pagenum   = 1; 
  192.  
  193. $last          = ceil($numRowsDb/$pageRows); 
  194.  
  195. if ($pagenum < 1) 
  196.     $pagenum   = 1; 
  197.  
  198. else if($last<1)
  199.     $pagenum   = 1; 
  200.  
  201. else if($pagenum > $last) 
  202.     $pagenum   = $last; 
  203.  
  204. $intFromRecord    = ($pagenum - 1) * $pageRows;
  205. $max               = "LIMIT " .$intFromRecord."," .$pageRows;
  206.  
  207. $sqlProduct  = "SELECT * FROM product ORDER BY order_position ".$max;;
  208. $resProduct  = mysql_query($sqlProduct);
  209. $rowCount    = mysql_num_rows($resProduct);
  210. ?>
  211.  
  212. <?php
  213. session_start();
  214. include_once("includes/dbConnect.php");
  215.  
  216. if($_GET['loginFailed'] == 1)  $error = "<font style='color:#FF0000;'>Please login as Administrator</font>";
  217.  
  218. if($_GET['logout'] == 1) session_destroy();
  219.  
  220. if($_SESSION['Role'] == 'A') header("location:productAdmin.php");
  221.  
  222. if($_POST["btnLogin"] == "Login")
  223. {
  224.     $sqlAuthentication = "SELECT id FROM tbl_admin_info WHERE UserID ='".$_POST["txtUserID"]."' AND Password ='".$_POST["txtPassword"]."'";
  225.     $resAuthentication = mysql_query($sqlAuthentication);
  226.     $arrAuthentication = mysql_fetch_array($resAuthentication);
  227.     $UsersID           = $arrAuthentication['id'];
  228.     $Role              = "Admin";
  229.  
  230.     if($UsersID > 0)
  231.     {
  232.  
  233.         $_SESSION['id']   = $UsersID;
  234.         $_SESSION['Role'] = $Role;
  235.  
  236.         header("location:productAdmin.php");
  237.  
  238.     }
  239.     else
  240.     {
  241.         $error = "<font style='color:#FF0000;'>Invalid Login. Please Try Again!!!</font>";
  242.     }
  243. }
  244.  
  245. mysql_close();
  246.  
  247. ?>
  248.  
  249.  
  250.  
  251. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  252. <html xmlns="http://www.w3.org/1999/xhtml">
  253. <head>
  254. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  255. <title>Foosh</title>
  256. <link rel="stylesheet" href="css/style.css" type="text/css" />
  257. <link href="css/pagination.css" rel="stylesheet" type="text/css" />
  258. <script type="text/javascript">
  259. <!--
  260. function MM_swapImgRestore() { //v3.0
  261.   var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
  262. }
  263. function MM_preloadImages() { //v3.0
  264.   var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  265.     var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  266.     if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  267. }
  268.  
  269. function MM_findObj(n, d) { //v4.01
  270.   var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  271.     d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  272.   if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  273.   for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  274.   if(!x && d.getElementById) x=d.getElementById(n); return x;
  275. }
  276.  
  277. function MM_swapImage() { //v3.0
  278.   var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  279.    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
  280. }
  281.  
  282. function fnValidate()
  283. {
  284.     if(document.getElementById("txtUserID").value == "")
  285.     {
  286.         alert("Please enter the User ID");
  287.         return false;
  288.     }
  289.     else if(document.getElementById("txtPassword").value == "")
  290.     {
  291.         alert("Please enter the Password");
  292.         return false;
  293.     }
  294.  
  295.     return true;
  296.  
  297. }
  298.  
  299. //-->
  300.  
  301. function fnValidate()
  302. {
  303.     var regExNumeric =/^[0-9]+$/;
  304.     var str = trim(document.getElementById("browseFile").value);
  305.     document.getElementById("txtDescription").value = trim(document.getElementById("txtDescription").value)
  306.     document.getElementById("txtProduct").value     = trim(document.getElementById("txtProduct").value)
  307.  
  308.     if(document.getElementById("txtProduct").value == "")
  309.     {
  310.         alert("Please enter the Product Name");
  311.         document.getElementById("txtProduct").focus();
  312.         return false;
  313.     }
  314.     else if(document.getElementById("txtDescription").value == "")
  315.     {
  316.         alert("Please enter the description");
  317.         document.getElementById("txtDescription").focus();
  318.         return false;
  319.     }
  320.     else if(str != "")
  321.     {
  322.         var extension = str.substring(str.length-4,str.length).toLowerCase();
  323.         if(extension != ".jpg" && extension != "jpeg" && extension != ".png" && extension != ".gif" && $extension != ".tif")
  324.         {
  325.             alert("Please select Image, Document or Zip file");
  326.             document.getElementById("browseFile").focus();
  327.             return false;
  328.         }
  329.         return true;
  330.     }
  331.     else if(trim(document.getElementById("txtPrice").value) == "")
  332.     {
  333.         alert("Please enter the Price");
  334.         return false;
  335.     }
  336.     else if(regExNumeric.test(document.getElementById("txtPrice").value) == false)
  337.     {
  338.         alert("Invalid Price");
  339.         return false;
  340.     }
  341.     else if(trim(document.getElementById("txtOrder").value) == "")
  342.     {
  343.         alert("Please enter the Ordering No");
  344.         return false;
  345.     }
  346.     else if(regExNumeric.test(document.getElementById("txtOrder").value) == false)
  347.     {
  348.         alert("Invalid Ordering Number");
  349.         return false;
  350.     }
  351.  
  352.     return true;
  353. }
  354.  
  355. function ltrim(argvalue) {
  356.  
  357.   while (1) {
  358.     if (argvalue.substring(0, 1) != " ")
  359.       break;
  360.     argvalue = argvalue.substring(1, argvalue.length);
  361.   }
  362.  
  363.   return argvalue;
  364. }
  365.  
  366. function rtrim(argvalue) {
  367.  
  368.   while (1) {
  369.     if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
  370.       break;
  371.     argvalue = argvalue.substring(0, argvalue.length - 1);
  372.   }
  373.  
  374.   return argvalue;
  375. }
  376.  
  377. function trim(argvalue) {
  378.   var tmpstr = ltrim(argvalue);
  379.  
  380.   return rtrim(tmpstr);
  381.  
  382. }
  383.  
  384. function fnDisplayImage()
  385. {
  386.     document.getElementById("image").style.display = "";
  387.     document.getElementById("image").onclick =  function() {fnHideImage()};
  388.     document.getElementById("link").onclick =  function() {fnHideImage()};
  389. }
  390.  
  391. function fnHideImage()
  392. {
  393.     document.getElementById("image").style.display = "none";
  394.     document.getElementById("image").onclick =  function() {fnDisplayImage()};
  395.     document.getElementById("link").onclick  =  function() {fnDisplayImage()};
  396. }
  397.  
  398. </script>
  399.  
  400. <style type="text/css">
  401. <!--
  402. body {
  403.     margin-left: 5px;
  404.     margin-top: 10px;
  405.     margin-right: 5px;
  406.     margin-bottom: 5px;
  407.     background-color: #EBFAFF;
  408.     font-family:Arial, Helvetica, sans-serif;
  409.     font-size:12px;
  410. }
  411.  
  412. -->
  413. </style>
  414. </head><body onload="MM_preloadImages('images/ordrbttn2.gif')">
  415. <table><td><table align="center" width="972" cellspacing="0" cellpadding="0"><tr><td scope="row"><table  align="center" width="972" cellspacing="0" cellpadding="0">
  416.   <tr>
  417.     <td scope="row"><img src="images/innerpageLefthdr.gif" /></td>
  418.     <td><img src="images/innerpageRghthdr.gif" /></td>
  419.   </tr>
  420. </table></td>
  421.     </tr>
  422. </table>
  423. <table class="midcontent3" width="929" border="0" cellspacing="0" cellpadding="0">
  424.   <tr><td>
  425.     <table align="center" width="870" border="0" cellspacing="0" cellpadding="0">
  426.  
  427.       <tr>
  428.         <td colspan="2" scope="row">&nbsp;</td>
  429.         <td>&nbsp;</td>
  430.         <td>&nbsp;</td>
  431.         <td>&nbsp;</td>
  432.       </tr>
  433.       <tr>
  434.         <td height="24" colspan="5"  class="graynav"scope="row" style="padding-left:5px;">
  435.  
  436. <table width="562" border="0" cellspacing="0" cellpadding="0">
  437.  
  438.  
  439.       <tr align="left" valign="top">
  440.         <th scope="row">&nbsp;</th>
  441.         <td align="center" valign="middle">
  442.  
  443. <br /><br />
  444. <form name="frmProductAdmin" action="productAdmin.php" method="post" enctype="multipart/form-data" onsubmit="return fnValidate();">
  445.  
  446. <div align="center">
  447. <a href="login.php?logout=1">Logout</a> <!--| <a href="manage_admin.php">Manage Admin</a>-->
  448. <table width="520" border="0" cellspacing="0" cellpadding="5"  style=" border:1px solid #666666;">
  449.   <?php if($strError != "") { ?>
  450.   <tr>
  451.     <td colspan="2" align="left" style="border:0px;"><?php echo $strError; ?></td>
  452.   </tr>
  453.   <?php } ?>
  454.     <tr>
  455.         <th align="left" colspan="2" valign="top" bgcolor="#CCCCCC" scope="row"><strong>Product  Admin </strong></th>
  456.     </tr>
  457.   <tr>
  458.     <td scope="col" colspan="2" align="left">Add / Edit Product </td>
  459.   </tr>
  460.   <tr>
  461.     <td width="151" valign="top">Product</td>
  462.     <td width="243" align="left" valign="top">
  463.         <input type="text" name="txtProduct" id="txtProduct" value="<?php echo $_POST['txtProduct']; ?>" />
  464.         <input type="hidden" name="hdnProductID" id="hdnProductID" value="<?php echo $_POST['hdnProductID']; ?>" />
  465.         <input type="hidden" name="hdnFileName" id="hdnFileName" value="<?php echo $_POST['hdnFileName']; ?>" />    
  466.     </td>
  467.   </tr>
  468.   <tr>
  469.     <td width="151" valign="top">Description</td>
  470.     <td width="243" align="left" valign="top"><textarea type="text" name="txtDescription" id="txtDescription" style=" border:1px solid #666666; width:200px; height:100px; font-family:Arial, Helvetica, sans-serif; font-size:12px;"> <?php echo trim($_POST['txtDescription']); ?></textarea></td>
  471.   </tr>
  472.   <tr>
  473.     <td width="151" valign="top">Price</td>
  474.     <td width="243" align="left" valign="top">
  475.     <input type="text" name="txtPrice" id="txtPrice" value="<?php echo $_POST['txtPrice']; ?>"  style="width:40px;"/>
  476.     </td>
  477.   </tr>
  478.   <tr>
  479.     <td width="151" valign="top">Ordering</td>
  480.     <td width="243" align="left" valign="top">
  481.     <input type="text" name="txtOrder" id="txtOrder" value="<?php echo $_POST['txtOrder']; ?>"  style="width:40px;"/>
  482.     <input type="hidden" name="hdnOrder" id="hdnOrder" value="<?php echo $_POST['hdnOrder']; ?>" />
  483.     </td>
  484.   </tr>
  485.   <tr>
  486.     <td valign="top">Photo</td>
  487.     <td align="left" valign="top">
  488.      <input type="file" name="browseFile" id="browseFile" />&nbsp; 
  489.      <?php if($image != "") { ?>
  490.      <a name="link" id="link" onclick="javascript:fnDisplayImage();" style="color:#0000FF; cursor:pointer;"><?php echo $image;  ?></a>
  491.      <div id="image" style="display:none">
  492.          <img src="files/<?php echo $image;  ?>" width="60" height="60" />
  493.      </div>
  494.      <?php } ?>
  495.      </td>
  496.   </tr>
  497.   <tr>
  498.       <td>&nbsp;</td>
  499.     <td align="left"><input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" style="width:100px;" />&nbsp;<input type="button" name="btnCancel" id="btnCancel" value="Cancel" onclick="javascript:window.location='productAdmin.php'" style="width:100px;" /></td>
  500.   </tr>
  501.  
  502. </table>
  503. <br />
  504.  
  505. <table width="520" border="0" cellspacing="0" cellpadding="5" style=" border:1px solid #666666;">
  506.   <tr>
  507.     <th scope="col" align="left" colspan="6">View Product </th>
  508.   </tr>
  509.   <tr>
  510.     <th scope="col" style="text-align:left;">Product</th>
  511.     <th scope="col" style="text-align:left;">Description</th>
  512.     <th scope="col" style="text-align:left;">Ordering</th>
  513.     <th scope="col" style="text-align:left;">Image</th>
  514.     <th scope="col" style="text-align:left;">Edit</th>
  515.     <th scope="col" style="text-align:left;">Delete</th>
  516.   </tr>
  517. <?php 
  518.     if($rowCount > 0) {
  519.     while($row = mysql_fetch_array($resProduct)) { 
  520. ?>  
  521.   <tr>
  522.     <td align="left" width="16%"><?php echo $row['product_name']; ?></td>
  523.     <td align="left" width="34%"><?php echo "Price: $".$row['price']." <br />".$row['description']; ?></td>
  524.     <td align="left" width="12%"><?php echo $row['order_position']; ?></td>
  525.     <td align="left" width="18%"><img src="files/<?php echo $row['filename']; ?>" name="ProductImage" width="60" height="60" /></td>
  526.     <td align="left" width="10%">
  527.     <a href="productAdmin.php?edit=<?php echo $row['id']; ?>&fileName=files/<?php echo $row['filename']; ?>">Edit</a>
  528.     </td>
  529.     <td align="left" width="10%">
  530.     <a href="productAdmin.php?delete=<?php echo $row['id']; ?>">Delete</a>
  531.     </td>
  532.   </tr>
  533. <?php } } else { ?>
  534.   <tr>
  535.     <td colspan="6" align="left">No Product Updated</td>
  536.   </tr>
  537. <?php } if($numRowsDb > $pageRows) {  ?>
  538.           <tr>
  539.              <td align="left" colspan="6"><?php echo pager($numRowsDb, "pageNum",$pageRows,3,"", $strParamenter, "productAdmin.php"); ?></td> 
  540.           </tr>
  541.         <?php } ?>
  542. </table>
  543. </div>
  544.  
  545. </form>
  546.  
  547. <br /><br />
  548.  
  549.         </td>
  550.         <td>&nbsp;</td>
  551.       </tr>
  552.     </table>
  553.  
  554.  
  555.         </td>
  556.       </tr>
  557.  
  558.       <tr>
  559.         <td colspan="5"  height="24" scope="row">&nbsp;</td>
  560.       </tr>
  561.       <tr>
  562.         <td colspan="5"  height="24" scope="row">&nbsp;</td>
  563.       </tr>
  564.     </table></td>
  565.   </tr>
  566. </table>
  567. <table align="right" width="949" border="0" cellspacing="0" cellpadding="0">
  568.   <tr>
  569.     <td colspan="2"><table border="0" cellspacing="0" cellpadding="0">
  570.         <tr>
  571.           <td bgcolor="#FFFFFF" height="10">&nbsp;</td>
  572.         </tr>
  573.         <tr>
  574.           <td class="footer"width="929" height="29"><table align="center" width="900" border="0" cellspacing="0" cellpadding="0">
  575.               <tr>
  576.                 <td scope="row"><a href="#">Terms & Conditions</a> | <a href="#">Privacy Policy</a></td>
  577.                 <td align="right">Copyright 2009 fooshenergytrial.com. All rights Reserved.</td>
  578.               </tr>
  579.             </table></td>
  580.         </tr>
  581.       </table></td>
  582.   </tr>
  583.   <tr>
  584.     <td class="disclaimer"width="929"><div align="center">These statements have not been reviewed by the Food and Drug Administration. This product is not intended to diagnose, treat, cure, or prevent any disease. SmokeScreen Chewing 
  585.         Gum is not affiliated in any way with WebMD, Google, and The Washington Times. WebMD, Google, and The Washington Times are registered trademarks of their respective owners.</div></td>
  586.     <td width="18">&nbsp;</td>
  587.   </tr>
  588. </table>
  589.  
  590. </body></html>
  591.  
  592.  
I'm guessing that the proper way of doing this is to not duplicate that wp_01 db; based on my limited knowledge of what I'm doing, it was just the direction I took. I'm kinda reverse engineering the site, based on what they've done and the limited guidance I've received from a number of sources. Searching for keywords and links, and changing them accordingly type thing. I'm starting to think that this will create quite a mess in the long run.

What confuses me the most is that page 2 and page 3 in the checkout process have the same name 'orderpage.php'.

This is the process.

Landing page (index.php) >> fill in your address for us to send the free samples to.

Page 2 (orderpage.php) >> fill in your credit card details

Page 3 (also 'orderpage.php') >> select any upsells that are of interest to you


It's page 3 that we control with the template that was built for changing pricing/pics/descriptions for the upsell options.


I've still managed to break something though. Page 2 in the /test2 folder isn't working properly. When you fill in your CC details and submit, it redirects you to /test/orderpage.php and you have to enter the CC info again. Then it takes you to page 3 in /test. Working properly, it would have just taken you to page 3 in /test2/orderpage.php

I'm getting closer though.

And learning lots along the way :)

Thanks guys. And thanks Dorm; keep letting me know as I screw up formatting on my posts. I think I got the code tags this time :P.

Andrew
Oct 19 '09 #9
TheServant
1,168 Expert 1GB
Glad you're getting there. Even though what you do now may be the long way around, when you make version 2.0, you can map it out and improve. I look at some code I made when I started (beginning of last year) and it was very much the long way around. No doubt by the end of next year I will be yet more efficient.

I had a quick look through the code but nothing jumped out (I was just scanning as there's a lot of code). Check you're URL's, and in all your files and amke sure there aren't any /test/'s that need to be /test2/'s. I suspect that one of the forms that you copied for test2 is still submitting to test.

Post back if you have any more issues, and when you have a more precise bit of code that is broken.
Oct 19 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Perttu Pulkkinen | last post by:
I have this problem: If administrator closes administration window from "right-corner-X", how to reset administration session? Now it happens that after that kind of "illegal" closing operation...
11
by: AnhTai | last post by:
Hi all, I've just installed MySQL 5.0 on my sun box (runing Solaris 10, install from blastwave). This is my first time with MySQL so I don't have any exp with it. I have some troubles as: -...
3
by: Dalibor | last post by:
How to protect administration pages from entering. I put login form on my start page (index.php), and if user put correct data, script redirect him on page admin/admin.php. That works fine! But if...
9
by: lostconnection | last post by:
I need some help with a registration/login and admin panel..PLEASE email me if you can help me out on this.. I like to get this site up and going and see where it goes. If I can get a reliable...
1
by: 2005.ravikumar | last post by:
Hello sir How to create Oscommerce admin login? Please give me sample code.
2
by: gangac | last post by:
I am currently working on an ms access application for a large insurance company which generates reports for the user after the user inputs/select some data.... Unfortunately the application has...
0
by: Big Charles | last post by:
Hello, Programming in VS2003-ASP.NET 1.1, I have this problem: Using DirectoryEntry and without any admin user, how can I check if a domain account, that try to login, has expired? Scenario: User...
4
by: vinpkl | last post by:
hi i am working on admin section which has a login page with login id and pasword form. in my admin section i have many pages say like manage_products.php, description.php, user.php etc. if i...
12
by: tvnaidu | last post by:
I have Two kinds of web pagess, one is for control page for only admin login, another one is to view status for user login. initially both html files can view with 192.168.0.10/control.htm and other...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.