PHP - Php / Mysql Has Something Throwing It All Off - 05.17.11
Hello,
There is something I may have over looked in my php that is causing these problems... I am almost there. Currently, my html form once processed by my "process_myform.php" placed the users info into the database, sends me an e-mail, and displayed my thank you page. This is what its doing and I am indeed happy about this part. HOWEVER, my "process_myform.php" that I created, has a BIG PROBLEM. Once processed, it is CURRENTLY giving me multiple blank replies to both my e-mail box and database in addition to that placing the correct 1 user info that I filled out with my html form. Also I would like to have the date and time do be displayed within the database for the my "$registration_date" variable.... how do i accomplish this? Right now in the database it just shows a bunch of zeros. Could someone look at my code and tell me what I am doing wrong? Here is my html & php form processing code below. I KNOW is did or did not do something wrong to throw this all off... not sure what it is. Thank you for your help. mrjap1 Code: [Select] ======================= MY HTML FORM CODE ============================== <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Untitled Document</title> </head> <body> <form action="process_myform.php" method="post"> <p> <!-- FIRST NAME --> <label>First Name:</label> <input name="first_name" type="text" size="15" maxlength="50" tabindex="10" id="first_name"> <!-- LAST NAME --> <label>Last Name:</label> <input name="last_name" type="text" size="15" maxlength="50" tabindex="20" id="last_name"> </p> <!-- ADDRESS--> <label>Address:</label> <input name="address" type="text" size="15" maxlength="50" tabindex="30" id="address"> </p> <p> <!-- EMAIL --> <label>E-mail:</label> <input name="email" type="text" size="15" maxlength="50" tabindex="40"> <!-- ZIP CODE --> <label>Zip Code:</label> <input name="zip_code" type="text" size="15" maxlength="50" tabindex="50"> </p> <br /> <input name="submit" type="image" value="SUBMIT FORM" src="submit_btn.png" alt="submit button" align="middle"> </form> </body> </html> =================== MY PHP FORM PROCESSING CODE ======================= <?php // 1. Create a database connection $con = mysql_connect("localhost","forms","itismyway"); if (!$con) { die('Database connection failed could not connect: ' . mysql_error()); } // 2. Select a database to use $db_select = mysql_select_db("mydatainsert",$con); if (!$db_select) { die('Database selection failed could not connect: ' . mysql_error()); } mysql_select_db("mydatainsert", $con); $sql="INSERT INTO `mydatainsert`.`gangland` ( `id` , `first_name` , `last_name` , `address` , `zip` , `email` , `registration_date` ) VALUES ('NULL','$_POST[first_name]','$_POST[last_name]','$_POST[address]', '$_POST[zip_code]','$_POST[email]','$_POST[registration_date]', "; // I WOULD LIKE THE DATE AND TIME TO BE IN THE DATABASE FOR THE "REGISTRATION_DATE". if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } //echo "1 record added"; // some code // 3. Close Connection mysql_close($con); ?> <?php // ALL THE SUBJECT and EMAIL VARIABLES $emailSubject = 'MY TEST EMAIL SCRIPTING!!! '; $webMaster = 'myemail@gmail.com'; // GATHERING the FORM DATA VARIABLES $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $address = $_POST['address']; $email = $_POST['email']; $zip_code = $_POST['zip_code']; $date = date ("l, F jS, Y"); $time = date ("h:i A"); $body = <<<EOD <br /><hr><br /> <strong>First Name:</strong> $first_name <br /> <strong>Last Name: </strong>$last_name <br /> <strong>Email:</strong> $email <br /> <strong>Zip Code:</strong> $zip_code <br /> <strong>Registration Date:</strong> $date at $time <br /> EOD; // THIS SHOW ALL E-MAILED DATA, ONCE IN THE E-MAILBOX AS READABLE HTML $headers = "From: $email\r\n"; $headers .= "Content-type: text/html\r\n"; $success = mail($webMaster, $emailSubject, $body, $headers); // THE RESULTS OF THE FORM RENDERED AS PURE HTML $theResults = <<<EOD <!DOCTYPE HTML> <html lang="en"> <head> <style type="text/css"> body { font-family:Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; } #thankyou_block { width: 400px; height: 250px; text-align:center; border: 1px solid #666; padding: 5px; background-color: #0CF; border-radius:8px; -webkit-border-radius:8px; -moz-border-radius:8px; -opera-border-radius:8px; -khtml-border-radius:8px; box-shadow:0px 0px 10px #000; -webkit-box-shadow: 0px 0px 10px #000; -moz-box-shadow: 0px 0px 10px #000; -o-box-shadow: 0px 0px 10px #000; margin: 25px auto; } p { font-family: Arial, Helvetica, sans-serif; font-size: 14px; line-height: 18px; letter-spacing:1px; color: #333; } </style> <meta charset="UTF-8"> <title>THANK YOU!!!</title> </head> <body> <div id="thankyou_block"> <br><br><br> <h1>CONGRATULATIONS!!</h1> <h2>YOUR FORM HAS BEEN PROCESSED!!!</h2> <p>You are now registered in our Database...<br> we will get back to you very shortly.<br> Please have a very wondeful day.</p> </div> </body> </html> EOD; echo "$theResults"; ?> Similar TutorialsMy site has been working fine for years but, all of a sudden, is throwing server errors on the pages that call for PHP includes. My provider isn't saying whether there's been an update but the fact that the site has always worked fine and now isn't, well...
So, here's some sample code from a .html page that calls for the TPL file:
<?php include('/home/MyPath/public_html/MySite.com/tpl/footer.tpl'); ?>
A long time ago, I was told to put this in my htaccess file:
AddType application/x-httpd-php5 .html
AddHandler application/x-httpd-php5 .html
If I delete both of these lines from the htaccess file, the site will load without the internal server error but my includes don't work at all. There's just an empty space where the content from the tpl file is supposed to be. I know they installed php 5.4 but my site was automatically put on 5.2 as a default.
I submitted a ticket with my provider and this was the response.
This is the error message as it is being recorded from the server itself when the domain returns a 500 error: [root@provider /home1/MyPath/public_html/mysite.com]# grep mysite.com /usr/local/apache/logs/error_log |tail -6 [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] Cannot load the ionCube PHP Loader - it was built with configuration 2.2.0, whereas running engine is API220100525,NTS, referer: http://www.mysite.com/ [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] Zend Optimizer requires Zend Engine API version 220060519., referer: http://www.mysite.com/ [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] The Zend Engine API version 220100525 which is installed, is newer., referer: http://www.mysite.com/ [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] Contact Zend Technologies at http://www.zend.com/ for a later version of Zend Optimizer., referer: http://www.mysite.com/ [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] , referer: http://www.mysite.com/ [Sat Sep 20 15:42:16 2014] [error] [client 192.190.1.20] malformed header from script. Bad header=<br />: index.html, referer: http://www.mysite.com/ This will be because there is a mismatch between the php version being called and the php.ini that is being loaded for the domain. Reviewing the mod_rewrite statements that call the various php versions within the direct file path to your domain shows the following: [root@provider /home1/MyPath/public_html/mysite.com]# grep -H -A 3 -B 1 'AddHand' /home1/MyPath/.htaccess /home1/MyPath/public_html/.htaccess /home1/MyPath/public_html/mysite.com/.htaccess /home1/MyPath/.htaccess-# Use PHP52 as default /home1/MyPath/.htaccess:AddHandler application/x-httpd-php52 .php /home1/MyPath/.htaccess-<IfModule mod_suphp.c> /home1/MyPath/.htaccess- suPHP_ConfigPath /opt/php52/lib /home1/MyPath/.htaccess-</IfModule> -- /home1/MyPath/public_html/mysite.com/.htaccess-#AddType application/x-httpd-php5 .html /home1/MyPath/public_html/mysite.com/.htaccess:#AddHandler application/x-httpd-php5 .html /home1/MyPath/public_html/mysite.com/.htaccess- /home1/MyPath/public_html/mysite.com/.htaccess- /home1/MyPath/public_html/mysite.com/.htaccess-## You would need to also declare the suphp for the php.ini to be used and upload a version matching php.ini to that location.I am completely lost as to what this means. I don't even know where to begin. Can someone please help me so I can get my site back to normal? Thank you in advance! I have never had to use this function before, but it was recommended to improve the security of my script. I have tried implementing mysql_real_escape_string() in every way I thought possible, but I keep getting random php errors. I am simply trying to sanitize the data from my query (as shown below)... Where would you recommend I call the function and what variable should I store in it? $posts_by_city_sql = "SELECT id, city_id, title FROM postings WHERE city_id='$_GET[id]'"; $posts_by_city_results = (mysqli_query($cxn, $posts_by_city_sql)) or die("Was not able to grab the Postings!"); //$title = $_GET['title']; // mysql_real_escape_string($title); while($posts_by_city_row = mysqli_fetch_array($posts_by_city_results)) { echo "<li><a href='posting_details.php?id=$posts_by_city_row[id]'>$posts_by_city_row[title]</a></li>"; } Hello It's about exception handling... I have two if statements, one inside the other. And I want to throw an exception from each, if one of them is FALSE. What "technique" should I use? I think throwing same exception with the same message within two if's is a bit messy. like: if $x is true //go to 2nd if: if $y is true return value if $y is false: throw exception "Invalid number" if $x is false: throw exception "Invalid number" Thanks, I have this code that has Code: [Select] $this->BeginTransaction();all over it. These are in classes where no such function is defined, and they don't have parents either. It's driving my crazy trying to figure out why they are there, why there's not so much as a warning being given and what, if anything, is being called. Now I do have a Code: [Select] set_error_handler("amfErrorHandler");and in amfErrorHandler I have Code: [Select] if( error_reporting() != 0 && ($amfphpErrorLevel | $level) == $amfphpErrorLevel ) { throw new VerboseException($string, $level, $file, $line); } I don't remember what $amfphpErrorLevel is, except that it should only be ignoring things like E_STRICT. Also, no exception is being thrown. So what do I do w/this code? I've been hacking at this for about 4 hours now.. Throwing the towel in! Any feedback or suggestions please: I'm calling a function like so: <!--START :: Run report and update records --> <p> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <!--<input type="hidden" name="post_var">--> <input type="submit" name="runUpdate" value="Run Update"> </form> </p> <?php if (isset($_POST['runUpdate'])) { updateRecords(); }; ?> <!--END :: Run report and update records --> Here are the function details: <?php function updateRecords() { // START :: Query to replace matches mysql_query("UPDATE orig_codes_1a AS a JOIN old_and_new_codes_1a AS b ON concat(a.orig_code_1, a.orig_code_2) = concat(b.old_code_1, b.old_code_2) SET a.orig_code_1 = b.new_code_1, a.orig_code_2 = b.new_code_2") or die(mysql_error()); // END :: Query to replace matches echo "<p><table border='1' cellpadding='3' width='100%'>"; echo "<tr> <th>Updated Code 1</th> <th>Updated Code 2</th> </tr>"; // START :: While loop - keeps getting the next row until there are no more to get while($row = mysql_fetch_array($result)) { //START :: If to find matching criteria class it w/ bg color if ($row['orig_code_1'] < '10000') { $changedClass = "changedClassCSS"; } else { $changedClass = ""; }; //END :: If to find matching criteria class it w/ bg color //START :: Print out the contents of each row into a table echo "<tr><td class=\"$changedClass\">"; echo $row['orig_code_1']; echo "</td><td class=\"$changedClass\">"; echo $row['orig_code_2']; echo "</td>"; } echo "</table></p>"; //END :: Print out the contents of each row into a table // START // //echo "$tableOutput"; // END // }; ?> I'm getting this error: Notice: Undefined variable: result in C:\wamp\www\php_practice\apps\records_updater_2\functions.php on line 27 Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\wamp\www\php_practice\apps\records_updater_2\functions.php on line 27 Now what I don't understand is 1) This script works fine (even though the $result is not defined) when all of the code is in one file not being called as a function. And 2) Why the hell would it work as in number 1?? Please please please tell me what I am doing wrong here! create table mimi (mimiId int(11) not null, mimiBody varchar(255) ); <?php //connecting to database include_once ('conn.php'); $sql ="SELECT mimiId, mimiBody FROM mimi"; $result = mysqli_query($conn, $sql ); $mimi = mysqli_fetch_assoc($result); $mimiId ='<span>No: '.$mimi['mimiId'].'</span>'; $mimiBody ='<p class="leading text-justify">'.$mimi['mimiBody'].'</p>'; ?> //what is next? i want to download pdf or text document after clicking button or link how to do that Hello everyone, Sorry if this has been answered but if it has I can't find it anywhere. So, from the begining then. Lets say I had a member table and in it I wanted to store what their top 3 interests are. Their$ row has all the usual things to identify them userID and password etc.. and I had a further 3 columns which were labled top3_1 top3_2 & top3_3 to put each of their interests in from a post form. If instead I wanted to store this data as a PHP Array instead (using 1 column instead of 3) is there a way to store it as readable data when you open the PHPmyadmin? At the moment all it says is array and when I call it back to the browser (say on a page where they could review and update their interests) it displays 'a' as top3_01 'r' as top3_02 and 'r' as top3_03 (in each putting what would be 'array' as it appears in the table if there were 5 results. Does anyone know what I mean? For example - If we had a form which collected the top 3 interests to put in a table called users, Code: [Select] <form action="back_to_same_page_for_processing.php" method="post" enctype="multipart/form-data"> <input name="top3_01" type="text" value="enter interest number 1 here" /> <input name="top3_02" type="text" value="enter interest number 2 here" /> <input name="top3_03" type="text" value="enter interest number 3 here" /> <input type="submit" name="update_button" value=" Save and Update! " /> </form> // If my quick code example for this form is not correct dont worry its not the point im getting at :) And they put 'bowling' in top3_01, 'running' in top3_02 and 'diving' in top3_03 and we catch that on the same page with some PHP at the top --> Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' With me so far? If I had a table which had 3 columns (1 for each interest) I could put something like - Code: [Select] include('connect_msql.php'); mysql_query("Select * FROM users WHERE id='$id' AND blah blah blah"); mysql_query("UPDATE users SET top3_01='$top3_01', top3_02='$top3_02', top3_03='$top3_03' WHERE id='$id'"); And hopefully if ive got it right, it will put them each in their own little column. Easy enough huh? But heres the thing, I want to put all these into an array to be stored in the 1 column (say called 'top3') and whats more have them clearly readable in PHPmyadmin and editable from there yet still be able to be called back an rendered on page when requested. Continuing the example then, assuming ive changed the table for the 'top3' column instead of individual colums, I could put something like this - Code: [Select] if (isset($_POST)['update_button']) { $top3_01 = $_POST['top3_01']; // i.e, 'bowling' changing POST vars to local vars $top3_02 = $_POST['top3_02']; // i.e, 'running' $top3_03 = $_POST['top3_03']; // i.e, 'diving' $top3_array = array($top3_01,$top3_02,$top3_03); include('connect_msql.php'); mysql_query("UPDATE members SET top3='$top3_array' WHERE id='$id' AND blah blah blah"); But it will appear in the column as 'Array' and when its called for using a query it will render the literal string. a r r in each field instead. Now I know you can use the 'serialize()' & 'unserialize()' funtcions but it makes the entry in the database practically unreadable. Is there a way to make it readable and editable without having to create a content management system? If so please let me know and I'll be your friend forever, lol, ok maybe not but I'd really appreciate the help anyways. The other thing is, If you can do this or something like it, how am I to add entries to that array to go back into the data base? I hope ive explained myself enough here, but if not say so and I'll have another go. Thanks very much people, L-PLate (P.s if I sort this out on my own ill post it all here) I have following piece of code below, and I would like to be able to express it pure SQL, something that could go into a .sql file :
$request_string='SELECT topic_forum_id FROM topic_table WHERE topic_id= 2014'; $query=database->prepare($request_string); $query->execute(); $data=$query->fetch(); $query->closeCursor(); $forum=$data['topic_forum_id']; $request_string='INSERT INTO post_table (post_topic,post_forum) VALUES (2014,:forum)'; $query=database->prepare($request_string); $query->bindValue(':forum',$forum,PDO::PARAM_INT); $query->execute(); $data=$query->fetch(); $query->closeCursor();Is it possible ? So i have this php as shown below. It should make a list of comments with comment replies below their comment respectively. The problem is that it only goes through and shows 1 comment and all the comment replies for that one comment. It should be showing all comments i have in the db for that article. If i remove the second while then it shows all the comments correctly but no comment replies then... How do i get this script to loop through the db for every comment but also loop through every comment reply for that $row[id]? If anyone has a better / more efficient way of what I am trying to do, please explain or show example (i am open to anything)... Code: [Select] // what article are we showing? $article_to_show_id = $_GET['article_id']; $active_is_set_text = "1"; // Active Column text that makes it okay to show // Finding the article $search_for_article = mysql_query("SELECT * FROM articles WHERE id = '$article_to_show_id' AND active = '$active_is_set_text'"); while($row = mysql_fetch_array($search_for_article)) { // format the last updated date right $update_date_edit = $row[update_date]; $update_date_edit = date('F j, Y \a\t h:ia', $update_date_edit); $row[update_date] = $update_date_edit; // format the submit updat date right $submit_date_edit = $row[submit_date]; $submit_date_edit = date('F j, Y \a\t h:ia', $submit_date_edit); $row[submit_date] = $submit_date_edit; echo ' <div> ', $row[title] ,' </div> <div> by: ', $row[author] ,' on ', $row[submit_date] ,' </div> <div> ', $row[content] ,' </div> <div> Last Updated: ', $row[update_date] ,' </div> <form action="article_reply.php" method="post"> <input type="hidden" name="article_id" value="', $row[id] ,'" /> <button name="article_reply" type="submit" value="submit">Reply</button> </form> '; } $comment_count = 0; $comment_reply_count = 0; // Finding all of the comments $search_for_article = mysql_query("SELECT * FROM article_comments WHERE article_id = '$article_to_show_id' AND reply_id = '0'"); while($row_comment = mysql_fetch_array($search_for_article)) { // format the submit updat date right $comment_date_edit = $row_comment[comment_date]; $comment_date_edit = date('F j, Y \a\t h:ia', $comment_date_edit); $row_comment[comment_date] = $comment_date_edit; echo ' <br> <br> COMMENT:<br> <div> By: ', $row_comment[username] ,' on ', $row_comment[comment_date] ,' </div> <div> ', $row_comment[comment] ,' </div> '; $comment_count++; // Finding all of the comment replies if any $search_for_article = mysql_query("SELECT * FROM article_comments WHERE article_id = '$article_to_show_id' AND reply_id = '$row_comment[id]'"); while($row_two = mysql_fetch_array($search_for_article)) { // format the submit updat date right $comment_date_edit = $row_two[comment_date]; $comment_date_edit = date('F j, Y \a\t h:ia', $comment_date_edit); $row_two[comment_date] = $comment_date_edit; echo ' <br> <br> COMMENT REPLY:<br> <div> By: ', $row_two[username] ,' on ', $row_two[comment_date] ,' </div> <div> ', $row_two[comment] ,' </div> '; $comment_reply_count++; } } Need some help I have 2 tables in a database and I need to search the first table and use the results from that search, to search another table, can this be done? and if it can how would you recommend that I go about it? Thanks For Your Help Guys! Hi everyone! I am stuck! SELECT config FROM inettuts WHERE user_id='5' This config pulls out this data: Code: [Select] PostInfo,color-grey,User Info,not-collapsed|Twitter,color-grey,Twitter,not-collapsed;AboutMe,color-grey,AboutMe,not-collapsed|Signature,color-grey,Signature,not-collapsed From a Text field in the mysql db, it then it is translated from jquery to show a portable iGoogle like page. But the problem is, I need to make the query select everything but the "Twitter,color-grey,Twitter,not-collapsed" (TWITTER PART) how is this possible? Hi Chaps, I've got something of a mixed bag, in which I need some help with a MySQL query and PHP to display the results correctly. I'm basically after the following: Query to produce results of; invoice_item_price of all jobs that include a Typesetting task and all of those that don't. The problem I'm having is that I can't figure out how to get the correct SUMtotal of the invoice_item_price, when searching through the tbl_task_item, to see if a Typesetting task has been completed. In trying to do this, it multiplies the invoice_item_price by the amount of tasks within a job. Database: Code: [Select] -- MySQL dump 10.11 -- -- Host: localhost Database: dbtemp -- ------------------------------------------------------ -- Server version 5.0.83-community-nt /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; -- -- Table structure for table `tbl_analysis` -- DROP TABLE IF EXISTS `tbl_analysis`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tbl_analysis` ( `analysis_id` int(20) unsigned NOT NULL auto_increment, `FK_job_id` int(20) unsigned default NULL, `analysis_gross` int(10) default NULL, `analysis_net` int(10) default NULL, PRIMARY KEY (`analysis_id`), KEY `FK_job_id` (`FK_job_id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `tbl_analysis` -- LOCK TABLES `tbl_analysis` WRITE; /*!40000 ALTER TABLE `tbl_analysis` DISABLE KEYS */; INSERT INTO `tbl_analysis` VALUES (1,1,100,50),(2,2,500,250); /*!40000 ALTER TABLE `tbl_analysis` ENABLE KEYS */; UNLOCK TABLES; -- -- Table structure for table `tbl_customer` -- DROP TABLE IF EXISTS `tbl_customer`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tbl_customer` ( `cust_id` int(20) unsigned NOT NULL auto_increment, `cust_name` varchar(255) default NULL, PRIMARY KEY (`cust_id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `tbl_customer` -- LOCK TABLES `tbl_customer` WRITE; /*!40000 ALTER TABLE `tbl_customer` DISABLE KEYS */; INSERT INTO `tbl_customer` VALUES (1,'Customer A'); /*!40000 ALTER TABLE `tbl_customer` ENABLE KEYS */; UNLOCK TABLES; -- -- Table structure for table `tbl_invoice` -- DROP TABLE IF EXISTS `tbl_invoice`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tbl_invoice` ( `invoice_id` int(20) unsigned NOT NULL auto_increment, `FK_cust_id` int(20) unsigned default NULL, `FK_proj_id` int(20) unsigned default NULL, `invoice_date` date default NULL, `invoice_total` varchar(30) default NULL, `invoice_status` enum('Pending','Sent') default NULL, PRIMARY KEY (`invoice_id`), KEY `FK_cust_id` (`FK_cust_id`), KEY `FK_proj_id` (`FK_proj_id`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `tbl_invoice` -- LOCK TABLES `tbl_invoice` WRITE; /*!40000 ALTER TABLE `tbl_invoice` DISABLE KEYS */; INSERT INTO `tbl_invoice` VALUES (1,1,1,'2010-01-30','500','Sent'); /*!40000 ALTER TABLE `tbl_invoice` ENABLE KEYS */; UNLOCK TABLES; -- -- Table structure for table `tbl_invoice_item` -- DROP TABLE IF EXISTS `tbl_invoice_item`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tbl_invoice_item` ( `invoice_item_id` int(20) unsigned NOT NULL auto_increment, `FK_job_id` int(20) unsigned default NULL, `FK_invoice_id` int(20) unsigned default NULL, `invoice_item_price` varchar(30) default NULL, `invoice_status` enum('Pending','Sent') default 'Pending', PRIMARY KEY (`invoice_item_id`), KEY `FK_job_id` (`FK_job_id`), KEY `FK_invoice_id` (`FK_invoice_id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `tbl_invoice_item` -- LOCK TABLES `tbl_invoice_item` WRITE; /*!40000 ALTER TABLE `tbl_invoice_item` DISABLE KEYS */; INSERT INTO `tbl_invoice_item` VALUES (1,1,1,'250','Sent'),(2,2,1,'250','Sent'); /*!40000 ALTER TABLE `tbl_invoice_item` ENABLE KEYS */; UNLOCK TABLES; -- -- Table structure for table `tbl_job` -- DROP TABLE IF EXISTS `tbl_job`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tbl_job` ( `job_id` int(20) unsigned NOT NULL auto_increment, `FK_proj_id` int(20) unsigned default NULL, `FK_langt_id` int(20) unsigned default NULL, `job_title` varchar(255) default NULL, `job_pages` int(10) default '1', `job_complete` enum('Yes','No') default 'No', `job_complete_date` timestamp NULL default NULL, PRIMARY KEY (`job_id`), KEY `FK_proj_id` (`FK_proj_id`), KEY `FK_langt_id` (`FK_langt_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `tbl_job` -- LOCK TABLES `tbl_job` WRITE; /*!40000 ALTER TABLE `tbl_job` DISABLE KEYS */; INSERT INTO `tbl_job` VALUES (1,1,1,'Job 1',1,'Yes','2012-30-01 17:30:00'), (2,1,3,'Job 2',2,'Yes','2012-30-01 17:30:00'); /*!40000 ALTER TABLE `tbl_job` ENABLE KEYS */; UNLOCK TABLES; -- -- Table structure for table `tbl_language` -- DROP TABLE IF EXISTS `tbl_language`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tbl_language` ( `lang_id` int(20) unsigned NOT NULL auto_increment, `langname` varchar(255) default NULL, PRIMARY KEY (`lang_id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `tbl_language` -- LOCK TABLES `tbl_language` WRITE; /*!40000 ALTER TABLE `tbl_language` DISABLE KEYS */; INSERT INTO `tbl_language` VALUES (1,'EN'),(2,'DE'),(3,'FR'); /*!40000 ALTER TABLE `tbl_language` ENABLE KEYS */; UNLOCK TABLES; -- -- Table structure for table `tbl_project` -- DROP TABLE IF EXISTS `tbl_project`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tbl_project` ( `proj_id` int(20) unsigned NOT NULL auto_increment, `proj_title` varchar(255) default NULL, `FK_cust_id` int(20) unsigned default NULL, `FK_langsid` int(20) unsigned default NULL, `proj_start_date` timestamp NULL default NULL, `proj_end_date` timestamp NULL default NULL, `proj_status` enum('Open','Hold','Enquiry','Redundant','Complete') default NULL, PRIMARY KEY (`proj_id`), KEY `FK_cust_id` (`FK_cust_id`), KEY `FK_langsid` (`FK_langsid`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `tbl_project` -- LOCK TABLES `tbl_project` WRITE; /*!40000 ALTER TABLE `tbl_project` DISABLE KEYS */; INSERT INTO `tbl_project` VALUES (1,'Project A', 1,2,'2012-01-30 09:00:00','2012-01-30 17:30:00','Complete'); /*!40000 ALTER TABLE `tbl_project` ENABLE KEYS */; UNLOCK TABLES; -- -- Table structure for table `tbl_task` -- DROP TABLE IF EXISTS `tbl_task`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tbl_task` ( `task_id` int(20) unsigned NOT NULL auto_increment, `task_title` varchar(50) default NULL, PRIMARY KEY (`task_id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `tbl_task` -- LOCK TABLES `tbl_task` WRITE; /*!40000 ALTER TABLE `tbl_task` DISABLE KEYS */; INSERT INTO `tbl_task` VALUES (1,'Preparation'),(2,'Typesetting'),(3,'Correction'),(4,'Evaluate'); /*!40000 ALTER TABLE `tbl_task` ENABLE KEYS */; UNLOCK TABLES; -- -- Table structure for table `tbl_task_item` -- DROP TABLE IF EXISTS `tbl_task_item`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `tbl_task_item` ( `task_item_id` int(20) unsigned NOT NULL auto_increment, `FK_job_id` int(20) unsigned default NULL, `FK_task_id` int(20) unsigned default NULL, `status` enum('Pending','Ready','Sent','Active','Complete') default 'Pending', `task_complete_date` timestamp NULL default NULL, `task_order` int(20) unsigned default NULL, PRIMARY KEY (`task_item_id`), KEY `FK_task_id` (`FK_task_id`), KEY `FK_job_id` (`FK_job_id`) ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; -- -- Dumping data for table `tbl_task_item` -- LOCK TABLES `tbl_task_item` WRITE; /*!40000 ALTER TABLE `tbl_task_item` DISABLE KEYS */; INSERT INTO `tbl_task_item` VALUES (1,1,1,'Complete','2012-01-30 10:00:00',1),(2,1,2,'Complete','2012-01-30 11:00:00',2),(3,1,3,'Complete','2012-01-30 12:00:00',3),(4,1,4,'Complete','2012-01-30 17:30:00',4),(5,2,1,'Complete','2012-01-30 10:00:00',1),(6,2,3,'Complete','2012-01-30 12:00:00',3),(7,2,4,'Complete','2012-01-30 17:30:00',4); /*!40000 ALTER TABLE `tbl_task_item` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; -- Dump completed on 2012-01-30 18:59:47 QUERY: Code: [Select] SELECT DATE_FORMAT(proj_end_date, '%m') as month_number, MONTHNAME(proj_end_date) AS the_month, YEAR(proj_end_date) AS the_year, SUM(analysis_net) as analysis_net, SUM(analysis_gross) as analysis_gross, SUM(job_pages) as job_pages, SUM(invoice_item_price) as total, CASE WHEN task_title='Typesetting' AND ti1.status='Complete' THEN 'Typeset' ELSE 'Non-Typeset' END AS 'JobType', langname FROM tbl_job as j INNER JOIN tbl_task_item as ti1 ON ti1.FK_job_id = j.job_id INNER JOIN tbl_task as t ON t.task_id = ti1.FK_task_id INNER JOIN tbl_invoice_item as ii ON ii.FK_job_id = j.job_id INNER JOIN tbl_invoice as i ON i.invoice_id=ii.FK_invoice_id INNER JOIN tbl_analysis as a ON a.FK_job_id = j.job_id INNER JOIN tbl_language as l ON l.lang_id = j.FK_langt_id INNER JOIN tbl_project as p ON p.proj_id = j.FK_proj_id WHERE p.FK_cust_id = 1 AND proj_status='Complete' GROUP BY the_year, month_number, JobType, langname ORDER BY the_year DESC, month_number DESC, JobType DESC, langname ASC The second problem I'm having is in presenting the results in the correct way. From my example below, you can see what I'm trying to achieve. The 'commented-out' PHP code, should 'GROUP' the JobType results, just like how the 'the_month' is working. But again, becoming a bit stuck in getting this to work too. <table border="3" cellpadding="3" cellspacing="3"> <tr> <td>Month</td> <td>Year</td> <td>JobType</td> <td>Analysis Net</td> <td>Analysis Gross</td> <td>Pages</td> <td>Invoice Total</td> <td>Language</td> </tr> <?php $previousMonth = ''; $previousType = ''; do { if ($previousMonth != $row_rsProjType['the_month']) { //if ($previousType != $row_rsProjType['JobType']) {?> <tr> <td><?php echo $row_rsProjType['the_month']; ?></td> <td><?php echo $row_rsProjType['the_year']; ?></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <?php $previousMonth = $row_rsProjType['the_month'];} ?> <tr> <td></td> <td></td> <td><?php echo $row_rsProjType['JobType']; ?></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> <?php //$previousType = $row_rsProjType['JobType'];} ?> <tr> <td></td> <td></td> <td></td> <td><?php echo $row_rsProjType['analysis_net']; ?></td> <td><?php echo $row_rsProjType['analysis_gross']; ?></td> <td><?php echo $row_rsProjType['job_pages']; ?></td> <td><?php echo $row_rsProjType['total']; ?></td> <td><?php echo $row_rsProjType['langname']; ?></td> </tr> <?php } while ($row_rsProjType = mysql_fetch_assoc($rsProjType)); ?> </table> If anyone can help me out in getting this to display correctly, it'll be highly appreciated. Hello, I am new to this site and hope I am posting this in the right section...
The thing is.....
I would like some help with php and mysql..
What I want to create is a page where users can create an account by entering their name, email and password, and if the username is taken they will have to try again otherwise their details will be registered to the mysql table and have an account to login.
Also I would like a redirect so if the user is a standard user it goes to say “home”, but if the user is an admin it will go to another page ie “home2”, and how would I create the admin in the same table on mysql or seperate?
Right the last thing is once the user can register and login, so can the admin, for instance if there are 10 users, when logged in I want each of those users to see different information can this be done and how could I do this ? I thought maybe have the table and the id would be from 1-10 so if user is 1 being dan show his column, and if user logged 2 being steve show column id 2.
Can somebody help me implement this please ?
I am currently learning php and mysql, im in university I managed to learn how to create the table, connect login, search, add to the database when logged in and edit etc.. but for what I want to achieve now I cannot find any tutorials or help, could somebody please help me with the coding for this and what pages are what and how to create the table in mysql being either 1 table for both user and admin, or 2 tables for separate users and admin.
Thanks for your help in advance guys
Hello i want to create a comment function to my website, but im not sure which way to do it. The thing is that i have post.php script that insert a new row in my table "content" and i want 1 separate comment function for each row (that symbols a link on my website). I was thinking that i could add a new table each time a new row(link) is created on my website just by modifying post.php to create new table. But will this be the most officiant way of making a comment function or will it burden my server and slow'en it? Not sure if this is the correct place to ask this question but here we go. I just wanted to know if I could insert into a MySQL database table a PHP conditional statement. I mean I am able to add this data to the table but when I grab that info from the table and echo it out to the browser it does not get displayed correctly. What I am trying to do is add a small login form into the table and render it out but I see the acutal code instead of the form. If I removed all PHP code the form will render correctly. So I was thinking either I cant add PHP or I am doing it wrong. I have a table that has a field called rating which can be from 0-100. I want to create a mysql query that will count the number of ratings between 0-20 then 21-40 then 41-60 etc. However I'm not really sure how to do this so any help would be great. Need help with php/sql. When I add a drink to the cart, only the quantity increases, but the item does not go to the cart. Check it out on my website http://fhcs.be/cart-demo2/ This is a part of my index.php <h1>Drinks</h1> <? $Link = mysql_connect("xxxx","xxxx","xxxx"); $Query = "SELECT * FROM products"; $DBName = "xxxx"; $results = mysql_db_query($DBName, $Query, $Link); ?> <select name = "drop1" size="1" id="drop1"> <Option Value=" ">Select Drink:</option> <? //Begins PHP for($u=0;$u<mysql_num_rows($results); $u++) { $id=mysql_result($results,$u,'name'); ?> <option value="<? echo($id); ?>"><? echo($id); ?></option><? //Begins PHP //Begins PHP } ?> </select> <? //Begins PHP if (mysql_db_query ($DBName, $Query, $Link)) { } else { print ("FAILURE<BR>\n"); } mysql_close ($Link); ?> <a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a> //button to add to chart And this is a part of my cart.php <?php // Include MySQL class require_once('inc/mysql.class.php'); // Include database connection require_once('inc/global.inc.php'); // Include functions require_once('inc/functions.inc.php'); // Start the session session_start(); // Process actions $cart = $_SESSION['cart']; $action = $_GET['action']; switch ($action) { case 'add': if ($cart) { $cart .= ','.$_GET['id']; } else { $cart = $_GET['id']; } break; case 'delete': if ($cart) { $items = explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($_GET['id'] != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } $cart = $newcart; } break; case 'update': if ($cart) { $newcart = ''; foreach ($_POST as $key=>$value) { if (stristr($key,'qty')) { $id = str_replace('qty','',$key); $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); $newcart = ''; foreach ($items as $item) { if ($id != $item) { if ($newcart != '') { $newcart .= ','.$item; } else { $newcart = $item; } } } for ($i=1;$i<=$value;$i++) { if ($newcart != '') { $newcart .= ','.$id; } else { $newcart = $id; } } } } } $cart = $newcart; break; } $_SESSION['cart'] = $cart; I have this code I want to check to see if the id from table1 is in table2. Can anyone help me with that if($checkProfile) { $sql_chk_tbl_username = "SELECT id FROM members_profile WHERE id = '"$_SESSION['face']"'"; $rs_user_list = mysql_query($sql_chk_tbl_username); if(mysql_num_rows($rs_user_list) <= 0) } ?> Umm.. Yeah, this MySQL line needs some reviewing list($total_banned_servers) = mysql_fetch_row(mysql_query("SELECT COUNT(id) FROM `toplist` WHERE banned='1' && serverowner=". $_SESSION['user'] ."")); |