trg86 Posted October 29, 2012 Share Posted October 29, 2012 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!! Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 29, 2012 Share Posted October 29, 2012 (edited) Dont use set in an insert query...it won't work just insert normally and where you would be inserting into archive just put a 0 Edited October 29, 2012 by ExtremeGaming Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 29, 2012 Author Share Posted October 29, 2012 Dont use set in an insert query...it won't work just insert normally and where you would be inserting into archive just put a 0 Thanks for your reply EG, although I am slightly confused with your response... Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 29, 2012 Share Posted October 29, 2012 Ok so say your archive column is right after where you are inserting '$referrer' Then you would put '0' Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 29, 2012 Author Share Posted October 29, 2012 Oh okay, more like this then?: $query = "INSERT INTO leads VALUES ('','$name','$email','$age','$gender','$location','$homephone','$referrer', '0'); Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 29, 2012 Share Posted October 29, 2012 Exactly Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 29, 2012 Author Share Posted October 29, 2012 Exactly Cool deal, I just tried it before you responded, but it is still not wanting to work...hmmm... Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 29, 2012 Share Posted October 29, 2012 So it is still not being set as 0 when inserting into the database? Are there any errors? Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 29, 2012 Author Share Posted October 29, 2012 So it is still not being set as 0 when inserting into the database? Are there any errors? Nope, no errors on the page, for error reporting, I am using: error_reporting(E_ALL); ini_set('display_errors', '1'); Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 29, 2012 Share Posted October 29, 2012 Can you please post your code? Your sql seems legit Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 29, 2012 Author Share Posted October 29, 2012 Can you please post your code? Your sql seems legit What do you need to see? Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 29, 2012 Share Posted October 29, 2012 You said it's not displaying correctly? Anything that you're using to display it, queries, loops, etc. Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 29, 2012 Share Posted October 29, 2012 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 Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 29, 2012 Author Share Posted October 29, 2012 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. Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 29, 2012 Author Share Posted October 29, 2012 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>"; ?> Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 29, 2012 Share Posted October 29, 2012 You see where you're using mysql_close(); ? Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 29, 2012 Author Share Posted October 29, 2012 You see where you're using mysql_close(); ? Yup, 'tis that the problem? Should I move that statement to the bottom of the document? Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 29, 2012 Share Posted October 29, 2012 (edited) That might be it, I don't remember whether it requires an argument or not Try it and see as there are connection properties happening below it Edited October 29, 2012 by ExtremeGaming Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 29, 2012 Author Share Posted October 29, 2012 (edited) 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. Edited October 29, 2012 by trg86 Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 29, 2012 Share Posted October 29, 2012 You are not issuing any errors if your query is incorrect, which is what I suspect. Without knowing your database structure it would be impossible add echo mysql_error(); before your mysql_close(); Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 29, 2012 Author Share Posted October 29, 2012 You are not issuing any errors if your query is incorrect, which is what I suspect. Without knowing your database structure it would be impossible add echo mysql_error(); before your mysql_close(); Done...still no errors. Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 29, 2012 Share Posted October 29, 2012 Ok I officially fail at helping this topic...and it's probably the smallest thing ever :/ One last try. In your while loop you are incrementing $i by 1 every time. Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 29, 2012 Author Share Posted October 29, 2012 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! Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 29, 2012 Share Posted October 29, 2012 Mwahaha I win...I guess. Go me! Quote Link to comment Share on other sites More sharing options...
trg86 Posted October 29, 2012 Author Share Posted October 29, 2012 Lol, it seems like the simplest problems are always the hardest to find...hehe 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.