Jump to content

trg86

Members
  • Posts

    64
  • Joined

  • Last visited

Posts posted by trg86

  1. Here's another little bit of advice on the SQL front - always name your fields when doing a query (either a SELECT or an INSERT), and don't INSERT anything into an auto_inc field.

     

    So instead of

    SELECT * FROM table1

    USE

    SELECT `field1`, `field2`, `field3`, `field4` FROM table1

     

    and

    INSERT INTO table1 VALUES('', 'value1', 'value2', 'value3')

    Becomes

    INSERT INTO table1 (`field2`, `field3`, `field4`) VALUES ('value1', 'value2', 'value3')

     

    Okay, advice taken.

     

    Quick question though, even though my current setup of the code works, what is the benefit/difference of doing it this way? :)

  2. Christian, thank you for your input. I'm not taking offense to the constructive criticism, but I know HTML and CSS like the back of my hand, I've been doing it for years. During development I tend to get into bad habits of using lengthy old font tags and line-breaks just to see how things will look, before I finalize them (in CSS), you will also notice that I do have some permanent css classes already coded in as well.

     

    As for the validation of data in the form processor, I beg to differ sir, as I have a separate validation class already programmed, I have just not implemented it into this system yet. :)

     

    But, I will take your advice with the PHP and the SQL, those are the areas I am newer in. :)

  3. Lol, yes in answer to your question about the $i, but...

     

    It was a very simple problem that I just fixed....in my database structure. There was a row below the archive row, that I removed since I am not using it at the moment, and that completely solved the problem! :P

  4. Still the same issue, as well as a possible further solution, I believe the problem may be in my processor all of a sudden. Now that I logged into my database via phpMyAdmin, the data is not even being saved to the database anymore, but is still successfully hitting my e-mail. Here is the code for my processor, maybe we can find the culprit there:

     

    <?php
    //
    //GATHERED DATA FROM THE USERS FORM ENTRIES AND DATABASE LOGIN
    //
    $username="REMOVED_FOR_THIS_POST"; //Database username
    $password="REMOVED_FOR_THIS_POST"; //Database password
    $database="REMOVED_FOR_THIS_POST"; //Database name
    
    $name = htmlspecialchars($_POST['name']);
    $email = htmlspecialchars($_POST['email']);
    $age = htmlspecialchars($_POST['age']);
    $gender = htmlspecialchars($_POST['gender']);
    $location = htmlspecialchars($_POST['location']);
    $homephone = htmlspecialchars($_POST['homephone']);
    $referrer = htmlspecialchars($_POST['referrer']);
    
    mysql_connect("REMOVED_FOR_THIS_POST",$username,$password); //Connection to Database
    @mysql_select_db($database) or die( "ALERT! Database not found!"); //Database Selection
    
    $query = "INSERT INTO leads VALUES ('','$name','$email','$age','$gender','$location','$homephone','$referrer', '0')"; //Insert Form Values To Database
    mysql_query($query);
    
    mysql_close();
    ?>
    

     

    Everything below that is just for sending the data to my e-mail, no relevancy. :)

  5. The following is the entire code for the main page that displays the form data, which WAS WORKING BEFORE. Additionally, I know the form is firing still because the same data is also emailed to me, as well as hitting the database.

     

    <?php
    session_start();
    if (!isset($_SESSION['username']))
    {
    exit();
    }
    ?>
    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    
    $db_username="REMOVED_FOR_THIS_POST"; //Database Username
    $password="REMOVED_FOR_THIS_POST"; //Database Password
    $database="REMOVED_FOR_THIS_POST"; //Database Name
    
    mysql_connect("REMOVED_FOR_THIS_POST",$db_username,$password); //Connection to Database
    @mysql_select_db($database) or die("ALERT! Database not found!"); //Selection of Database
    
    $query="SELECT * FROM leads WHERE `archive` = '0' ORDER by id DESC"; //Database Table to Query //Query Sort Settings
    $result=mysql_query($query);
    $num=mysql_numrows($result);
    
    mysql_close();
    ?>
    <html>
    <head>
    <link href="css/db_style.css" rel="stylesheet" type="text/css" media="screen" />
    </head>
    <body>
    <div id="wrap">
    <div id="top_bar">
    <font color="#0092c8"><?php echo "<b>Welcome</b> ".$_SESSION['username'];?></font>, <?php echo('<a href="logout.php">Logout</a>');?>    ||    <b>Current Database:</b> <FONT color="#0092c8" face="verdana" size="2">REMOVED_FOR_THIS_POST</font>    ||    <b>Current Date/Time:</b> <FONT color="#0092c8" face="verdana" size="2"><script type="text/javascript">
    document.write ('<span id="date-time">', new Date().toLocaleString(), '<\/span>')
    if (document.getElementById) onload = function () {
       setInterval ("document.getElementById ('date-time').firstChild.data = new Date().toLocaleString()", 50)
    }
    </script></font>
    </div>
    </div><br>
    <div id="wrap">
    <div id="top_user_toolbar">
    <b>Control Panel</b> |  <a href="leads_archive.php" class="toolbar_link">Archived Leads</a>  |  <a href="#" class="toolbar_link">Active Leads</a>  |  <a href="#" class="toolbar_link">Appointment Calender</a>  |  <a href="pm/message_center.php" class="toolbar_link">Message Center</a></font>
    </div>
    </div><br>
    <div id="wrap">
    <div id="top_notification_box">
    <b>Notification:</b>  <font color="#0992c8">PLEASE REPORT ANY BUGS, THIS IS A WORK IN PROGRESS!</font>
    </div>
    </div>
    <div id="wrap">
    <br><br>
    <table class="leads_table">
    <tr><td><center><font class="small_black"><b>New Leads</font></center></b></td></tr>
    <tr>
    <th bgcolor="#9e0219"><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">Name</font></th>
    <th bgcolor="#9e0219"><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">E-Mail</font></th>
    <th bgcolor="#9e0219"><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">Age</font></th>
    <th bgcolor="#9e0219"><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">Gender</font></th>
    <th bgcolor="#9e0219"><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">Location</font></th>
    <th bgcolor="#9e0219"><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">Phone Number</font></th>
    <th bgcolor="#9e0219"><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF">Referrer</font></th>
    <th bgcolor="#9e0219"><font face="Arial, Helvetica, sans-serif" size="2" color="#FFFFFF"><b>- - - Options - - -</b></font></th>
    </tr>
    </div>
    <?php
    $i=0;
    while ($i < $num) {
    $id=mysql_result($result,$i,"id"); //Unique ID Field
    $name=mysql_result($result,$i,"name"); //Name
    $email=mysql_result($result,$i,"email"); //EMail Address
    $age=mysql_result($result,$i,"age"); //Age
    $gender=mysql_result($result,$i,"gender"); //Gender
    $location=mysql_result($result,$i,"location"); //City of Residence
    $homephone=mysql_result($result,$i,"homephone"); //Home Phone Number
    $referrer=mysql_result($result,$i,"referrer"); //Referrer
    ?>
    <tr>
    <td align="center" bgcolor="#FFFFFF"><font class="lead_txt"><? echo $name; ?></font></td>
    <td align="center" bgcolor="#FFFFFF"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $email; ?></font></td>
    <td align="center" bgcolor="#FFFFFF"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $age; ?></font></td>
    <td align="center" bgcolor="#FFFFFF"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $gender; ?></font></td>
    <td align="center" bgcolor="#FFFFFF"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $location; ?></font></td>
    <td align="center" bgcolor="#FFFFFF"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $homephone; ?></font></td>
    <td align="center" bgcolor="#FFFFFF"><font face="Arial, Helvetica, sans-serif" size="2" class="lead_txt"><? echo $referrer; ?></font></td>
    <td align="center" bgcolor="#fdfdfd"><a href="db_edit.php?id=<?php echo $id; ?>"><img src="images/edit.png" border="0" width="32" height="32" alt="Edit" title="Edit Lead Credentials"></a>   <a href="#"><img src="images/active.png" border="0" width="32" height="32" alt="Active" title="Move To Active Leads">   <a href="add_to_archive.php?id=<?php echo $id; ?>"><img src="images/archive.png" border="0" width="32" height="32" alt="Delete" title="Archive Lead">   <a href="db_remove.php?id=<?php echo $id; ?>"><img src="images/delete.png" border="0" width="32" height="32" alt="Delete" title="Delete Lead From Database"></a></td>
    </tr>
    </center>
    </font>
    </body>
    </html>
    <?php
    $i++;
    }
    echo "</table>";
    ?>
    

  6. Hmm I hope this was just a typing mistake. Your code at the top of the page I overlooked

     

    $query="SELECT * FROM leads WHERE `archive` = '0' ORDER by id DESC;

     

    You're missing the end quote

     

    That was my typing mistake :) The end quote is there in the actual file.

  7. Hey guys, me again. This is all based off of the same couple of items you have helped me with the past couple of days. For those of you that know already, I have been working on a database that stores and displays information via a submitted form from the clients end. By default, all entries show up on a main page, where they can be edited, archived(which moves it to an archive page) or deleted. Now, I have the archive page working, that properly displays only archived entries, using the code below:

     

    $query="SELECT * FROM leads WHERE `archive` = '1' ORDER by id DESC;
    

     

    The problem that I am having now is that the main page, using this code:

     

    $query="SELECT * FROM leads WHERE `archive` = '0' ORDER by id DESC;
    

     

    is no longer displaying the entries once they are submitted through the form, even though it was working before, without the extra WHERE statement, which is also how it still works, but will displayed the archived leads as well, which I DO NOT want, any advice on what I may be doing wrong?

     

    I added a new statement to the form processor as well to try and set the archive to 0 when it is inserted into the database, but still no luck, that code is as follows:

     

    $query = "INSERT INTO leads VALUES ('','$name','$email','$age','$gender','$location','$homephone','$referrer') SET `archive` = '0' ";
    

     

    Thanks guys!!

  8. Submit the form with an id of what you're archiving in the url such as archive.php?id=id

     

    Just call it by using

    $id = mysql_real_escape_string($_GET['id']);

     

    Then use sql to update the information

    $sql = "UPDATE `table` SET `archive` = '1' WHERE `id` = '$id'";

     

    To call all of them that aren't archived just use a while loop and a where clause as followed:

     

    $sql = "SELECT * FROM `table` WHERE `archive` = '0'";
    
    $result = mysql_query($sql,$connection) or die("Error connecting to the database");
    
    while($row = mysql_fetch_array($result)) {
    // How you want to display it here. Examples shown below
    $title = $row['title'];
    $info = $row['info'];
    $id = $row['id'];
    
    // Using so many echos to keep it easy to read
    echo "$title<br>";
    echo "$info<br>";
    echo "<form action='archive.php?id=$id' method='post'>";
    echo "<input type='submit' value='Archive This'>";
    echo "</form>";
    
    }
    

     

    Thank you for the example, although I did not need the whole code, just needed to add this option to my current structure. I also took previous advice that I needed to set it up just like my already complete 'edit' function, which I have done. I have this successfully working now, just need to make the archive page to display just the archived leads...

  9. Add a field to the table called "archived." Set that field to 0. Add a button called "archive this" that will flip the "archived" field on a post to 1. Have your main page only show items where archived = 0. Have an archive page if you wish, which only shows archived = 1.

     

    Additionally, what would be the best way to do this? :)

     

    I already have the button created and in place

  10. Just add an archive COLUMN, not a separate table. You would modify this with an update, just as you are with your 'edit' buttons.

     

    Oh okay, I understand better now, sounds simple enough. :P Thanks!

     

    I will let you know if I need any further assistance.

×
×
  • 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.