Jump to content

Search the Community

Showing results for tags 'mysql'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

  1. hello, Maby you can help me make somthing I have done things myself but i am a litle stuck it has somthing to do with my admin of product list like you can see in the picture i have done alot but now i want to ad a percentage i know that it has somthing to do with taking the result out of the column named (winstverlies) and devide that trough the purchese price and multiply this by 100 but i can not implement this in my code. the code is PHP so who can help me? so i want it to look like on the picture. is this posible? picture is in the file named percentage.jpg So i would be verry pleasd if you could help me?
  2. I am creating a table using phpMyAdmin. I would appreciate if someone would explain: In the collation, I am selecting utf8_general_ci. Is this OK? For indexing, when should I use ''unique and when would I use 'index'?
  3. Hi, I am considering to have two tables related to investments: 1) investors 2)invested money, with a link between the two. For the second table, besides own id and id linking to the first table, there are: investment received, paid money (e.g. profits, paid capital etc.), and dates associated with investment and paid money. There is also some money deductible which is relevant to tax, exchange rate, expenses, etc. I have two options: having those deductions as part of the second table with proper formulas, or keep the table simple and have deductions not in the table but rather as part of the accounting work in accountants' books. I would appreciate if someone knows what could be the best/advisable professional practice.
  4. What is the best way of capturing data sent via a contact-us form (I am using form and PHP)--in DB only, in a dedicated email only, or in both? Pros and cons of each method please, if possible.
  5. Hi everybody, I am trying to import a db in myphpadmin which works fine on another server and I get the error below. Can you tell me what's wrong here? Thank you. Roughly translated it s: Static analysis: 1 error was found during analysis. Keyword not recognized. (near "ON" at position 25) SQL Query: SET FOREIGN_KEY_CHECKS = ON; MySQL message: #2006 - MySQL server has gone away
  6. I dropped a column (linknum) in a table (wine) with mysql in the console After that I wanted to make it again ALTER TABLE wine ADD linknum INT DEFAULT '1' NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST; but now I recieve an error message like this: ERROR 1067 (42000): Invalid default value for 'linknum' How can I solve it, and create a column called linknum again, starting with 1 and incrementing 1 ?
  7. This is my situation If variable $conn has all variables (with a value) $conn = new mysqli($servername, $username, $password, $dbname); and then you use var_dump($conn); and the output would be null of all the values of $conn. What would it mean? Am I right the connection then needs to be re-established? I'm doing 2 queries on a database. First query is SHOW TABLES then make the user choose a table value. From this value a new query is done. So first connection is done. But can I use this connection or should I make a new one?
  8. I have a question about security and MYSQL. I installed MYSQL and PHPMYADMIN. I changed the root password. But when in PHPMYADMIN I see a list of users and priviliges. Usernames sound like: All, root or pma. I understand I need pma or root, but what is the use of All ? User name Host Password Global privileges User group Grant Action Any % -- USAGE Any localhost No USAGE pma localhost Yes USAGE root 127.0.0.1 Yes ALL PRIVILEGES root ::1 Yes ALL PRIVILEGES root localhost Yes ALL PRIVILEGES Furthermore which priviliges and global rights should a user have when developing localhost?
  9. //Determine who receives bracelets and update bracelet recipients table //This is only applicable to recipients of CHARMS $sql = "SELECT DISTINCT ACCOUNT_NUM FROM sc_master WHERE REFERENCE = '$reference' AND AWARD NOT LIKE 'Scentsational Start Award%' AND GIFT_GROUP = 'Charm' AND PROCESSED <> 'X' LIMIT 1000"; $qry = mysql_query($sql) or die(mysql_error()); while($r = mysql_fetch_array($qry)) { $acct = $r['ACCOUNT_NUM']; $fname = $r['FNAME']; //no data due to DISTINCT clause $lname = $r['LNAME']; //no data due to DISTINCT clause $bsql = "SELECT ID FROM sc_bracelet_recipients WHERE CONSULTANT_ID = '$acct'"; $bqry = mysql_query($bsql) or die(mysql_query()); $count = mysql_num_rows($bqry); if($count < 1) { //get count of how many bracelet records were marked $bracelets = $bracelets + 1; //update sc_master with an "X" for each bracelet needed mysql_query("UPDATE sc_master SET BRACELET = 'X' WHERE ACCOUNT_NUM = '$acct' AND REFERENCE = '$reference' AND AWARD NOT LIKE 'Scentsational Start Award%' AND GIFT_GROUP = 'Charm' LIMIT 1") or die(mysql_error()); //update sc_bracelet_recipients to track these records mysql_query("INSERT INTO sc_bracelet_recipients (CONSULTANT_ID, FIRST_NAME, LAST_NAME, BATCH_MONTH) VALUES('$acct', '$fname', '$lname', '$reference')"); } //mark the record as processed to avoid reprocessing it on the next pass mysql_query("UPDATE sc_master SET PROCESSED = 'X'") or die(mysql_error()); } I have a script that we run once a month on a large 'awards' list provided by a customer. A recipient can be on the list more than once for different achievements, and for certain awards they may receive a charm for a bracelet. If they are receiving a charm for the first time we must send them a charm bracelet, however if they have already received a bracelet all we send is the charm. Here's a summary of steps: Is the recipient award associated with a charm?Yes - check the 'bracelets' table to see if they have received a bracelet already If they haven't received a bracelet: update the bracelets table indicate that the record receives a bracelet if this recipient receives multiple awards, only mark 1 record for a bracelet [*]Mark all records that have been processed as processed The 'batch' of data that we process is anywhere from 5,000 to 15,000 records per month. The logic noted above runs (loops) for each record in the 'batch' and the bracelet table contains a couple hundred thousand records. This just kills the server... so, you'll see that I limit the primary query to 1,000 records, this is due to how slow this script is (the tables contain hundreds of thousands of records). I'm guessing there's someone far smarter than I that can probably handle all of this in one beautiful and much faster query, preferably fast enough to process the entire list in one run vs. breaking it into groups of 1,000 per run. Thanks in advance for your help! Rumble
  10. So my goal is now to have a table list read from the database. The content of the table is supposed to be put in an <SELECT> <OPTION VALUE> form for a dropdown menu having the user select only 1 value. $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SHOW TABLES"; if (!$result = $conn->query($sql)){ die('There was an error running the query[' .$conn->error. ']'); } foreach($row = $result->fetch_assoc()){ echo "<center>"; $reeks = implode(" " , $row); // echo $reeks; // echo "<br>"; echo "</center>"; ?> <center> <form name = "inpform" method="post" action="Add-succ7.php"> <SELECT > <option value = "<?php echo $reeks; ?>" > </option> </SELECT> </center> <?php } mysqli_close($conn); ?> Do I have to do this with foreach or while? (or something else?) In the checkbox version I use while but when doing that I get a list of 8 checkboxes without any value. I see the dropdown menu is placed in the loop of while so another condition (like foreach) seems to be the first thing to think about. But what kinda solutions would you have for the script above?
  11. id | mid | pid | owgh | nwgh |1 3 12 1.5 0.62 3 12 1.5 0.33 3 14 0.6 0.44 3 15 1.2 1.15 4 16 1.5 1.06 4 17 2.4 1.27 3 19 3.0 1.4 Select mid , COUNT(distinct pid) as cpid , SUM(nwgh) as totalnwgh from test GROUP BY mid sqlfiddle : link of below result with above query mid cpid totalnwgh3 4 3.84 2 2.2 But above i need one more column that's as below : **totowgh** mid cpid totalnwgh totowgh3 4 3.8 6.3 (DISTINCT value as per pid column)4 2 2.2 3.9 where totowgh = 6.3 come by DISTINCT value as per pid columnthat's mid = 3 has count 5 but distinct pid = 4 for mid=3 same way "distinct" owgh = 6.3 for mid=3 and distinct pid.As pid=12 is count 1 time hence,1.5 + 0.6 + 1.2 + 3 = 6.3 ( please not this is as per DISTINCT value of pid )Please note : i need owgh value as per distinct pid or group by pid .. because if i replace value of owgh 0.6 with 1.5 then it will be 5.7 instead of 7.2 but value of owgh 0.6 belong to pid = 14 and not pid = 12 hence totalcount of owgh change ...but i need is 7.2SEE WHAT I MEANS : sqlfiddle.com/#!9/2a53c/6
  12. tech991

    Bookmark system

    Hi to all. I'm new in php development. I'm trying to do a bookmark system. I have an intern search engine that extract data from a database table build in MYSQL that show as link and the user can click on and appear es text html. I want to give the possibility to add a star button near these link and when the user click on to bookmark. I found 2 ways to do this, but I'm sure that exist more solution that can do better or not: 1- Give the possibility to the user that when click on button near the link that extract data from the database to add this on a bookmark table. 2- When the user click on button add data to a the bookmark browser with a javascript as this (http://stackoverflow.com/questions/10033215/how-do-i-add-an-add-to-favorites-button-or-link-on-my-website). I think is the easiest solution but I'm not sure what can do the correct way to this. Any advice is welcome:)
  13. Hello. I'm currently developing an app in the Intel XDK for my local high school. One of the features I would like to add is something where school administrators (such as the athletic director) can login and then submit data into an HTML5 form, which is then submitted to a server and stored in a database. Then, after it is stored, I would like the information to be able to be viewed by regular users of the app, in something such as an HTML page. THe purpose of this would be for the school admins to submit scores from the games such as football, etc. My question is, how do I setup the server (im assuming would run PHP) to be able to store the submitted data, and then would edit an HTML page to include the new text? Any help is appreciated! Thanks!
  14. Hi Sir, I creating a form with checkbox for example I checked the Add Employee and Upload Employee, after I click the Submit button the output is 2 and 3 which is correct but only the Upload Employee was checked. How can it be that the Add Employee and Upload Employee was checked. Also how can save checkbox check in the database. if(isset($_POST['submit'])){ if(!empty($_POST['access'])) { $access = $_POST['access']; echo "You chose the following color(s): <br>"; foreach ($access as $access_id){ echo $access_id."<br />"; }} // end brace for if(isset else { echo "You did not choose a color."; }}<input type="checkbox" name="access[]" id="access" value="1" <?php if($access_id==1) echo 'checked="checked"'; ?>>Search/View Employee Information<br><input type="checkbox" name="access[]" id="access" value="2" <?php if($access_id==2) echo 'checked="checked"'; ?>>Add Employee<br><input type="checkbox" name="access[]" id="access" value="3" <?php if($access_id==3) echo 'checked="checked"'; ?>>Upload Employee<br><input type="checkbox" name="access[]" id="access" value="4" <?php if($access_id==4) echo 'checked="checked"'; ?>>Permission<br><input type="checkbox" name="access[]" id="access" value="5" <?php if($access_id==5) echo 'checked="checked"'; ?>>Vacation<br><input type="checkbox" name="access[]" id="access" value="6" <?php if($access_id==6) echo 'checked="checked"'; ?>>Calendar Event<br> <input type="submit" name="submit" id="submit" value="Submit"> Thank youHi Sir,I creating a form with checkboxfor example I checked the Add Employee and Upload Employee, after I click the Submit button the output is 2 and 3 which is correct but only the Upload Employee was checked.How can it be that the Add Employee and Upload Employee was checked.Also how can save checkbox check in the database. if(isset($_POST['submit'])){ if(!empty($_POST['access'])) { $access = $_POST['access']; echo "You chose the following color(s): <br>"; foreach ($access as $access_id){ echo $access_id."<br />"; }} // end brace for if(isset else { echo "You did not choose a color."; }}<input type="checkbox" name="access[]" id="access" value="1" <?php if($access_id==1) echo 'checked="checked"'; ?>>Search/View Employee Information<br><input type="checkbox" name="access[]" id="access" value="2" <?php if($access_id==2) echo 'checked="checked"'; ?>>Add Employee<br><input type="checkbox" name="access[]" id="access" value="3" <?php if($access_id==3) echo 'checked="checked"'; ?>>Upload Employee<br><input type="checkbox" name="access[]" id="access" value="4" <?php if($access_id==4) echo 'checked="checked"'; ?>>Permission<br><input type="checkbox" name="access[]" id="access" value="5" <?php if($access_id==5) echo 'checked="checked"'; ?>>Vacation<br><input type="checkbox" name="access[]" id="access" value="6" <?php if($access_id==6) echo 'checked="checked"'; ?>>Calendar Event<br> <input type="submit" name="submit" id="submit" value="Submit"> Thank you
  15. Hello every one anyone can solve my prob my database not save my html data in mysql i want to save my hrml data in mysql but its work only for 755 characters after 755 755 no data save in database so plz tell me how i save my html 8000 characters data how to save in my db Thanks
  16. Hi, Can anyone recommend anywhere that I can learn code part time in the United Kingdom? I have been teaching myself html, css, etc on a basic level & now venturing into php, mysql, js, etc & think that having a tutor or guidance would really help speed up my learning process. Any companies or colleges offering part time courses in these area's will hopefully fill in the holes in my knowledge & help me progress. I'm not really concerned about qualification certificates, the knowledge is more important to me. Thanks for any advice. Old Guy.
  17. Hi, need some advice to do logic in my table casue i never face this before, hope you guys help me out this issue i need to show data from database and the image upload here cause cannot upload here to big system respond but let me tell here what i stuck it I need show the row with max id ( Done ) I need show data limit 1 where id != row with max id (Done) I need show all data without max id (point 1) and point 2 Thanks, and think that it can handle by css by hidden or by selector asecending but still figure out how. edit : i use codeiigniter
  18. Hi,Good day!I found a tutorial on creating a calendar that can add Event.Now, I want to enhance it to add Delete and Edit button but I have no idea on how to do that here is my code:calendar.php <?php$hostname = 'localhost';$username = 'root';$password = 'root';$dbname = 'calendar';$conn = new mysqli($hostname, $username, $password, $dbname);// Check connectionif ($conn->connect_error) { die("Connection failed: " . $conn->connect_error);}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script> function goLastMonth(month,year) { if(month == 1) { --year; month = 13; } --month var monthstring = ""+month+""; var monthlength = monthstring.length; if(monthlength <= 1) { monthstring = "0"+monthstring; } document.location.href = "<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year; } function goNextMonth(month,year) { if(month == 12) { ++year; month = 0; } ++month var monthstring = ""+month+""; var monthlength = monthstring.length; if(monthlength <= 1) { monthstring = "0"+monthstring; } document.location.href = "<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year; }</script><style> .today { background-color: #d3c6bd; } .event { background-color: #8d735a; }</style></head><body><?phpif(isset($_GET['day'])){ $day = $_GET['day'];}else{ $day = date("j");}if(isset($_GET['month'])){ $month = $_GET['month'];}else{ $month = date("n");}if(isset($_GET['year'])){ $year = $_GET['year'];}else{ $year = date("Y");}$maxDay = cal_days_in_month(CAL_GREGORIAN, $month, $year);if( $day > $maxDay ) { $day = $maxDay;}$currentTimeStamp = strtotime("$year-$month-$day");$monthName = date("F", $currentTimeStamp);$numDays = date("t", $currentTimeStamp);$counter = 0;if(isset($_GET['add'])){ $title = $_POST['txttitle']; $detail = $_POST['txtdetail']; $eventdate = $month."/".$day."/".$year; $sqlinsert = "INSERT INTO tbl_calendar (Title, Detail, eventDate, dateAdded) VALUES ('".$title."','".$detail."','".$eventdate."', now())"; if ($conn->query($sqlinsert) === TRUE) { // echo "Event was successfully Added..."; } else { // echo "Event Failed to be Added..."; } }?><table border="1"> <tr> <td><input style='width:60px; height:40px;' type='button' value='<' name='previousbutton' onClick="goLastMonth(<?php echo $month.",".$year; ?>);"></td> <td colspan="5" style='text-align:center;font-weight:bold;background-color:#8d735a; color:#FFF;'><?php echo $monthName. ", ".$year; ?></td> <td><input style='width:60px; height:40px;' type='button' value='>' name='nextbutton' onClick="goNextMonth(<?php echo $month.",".$year; ?>);"></td> </tr> <tr style='background-color:#af9c8e; color:white;'> <td width='60px' height='40px' align='center'>Sun</td> <td width='60px' height='40px' align='center'>Mon</td> <td width='60px' height='40px' align='center'>Tue</td> <td width='60px' height='40px' align='center'>Wed</td> <td width='60px' height='40px' align='center'>Thu</td> <td width='60px' height='40px' align='center'>Fri</td> <td width='60px' height='40px' align='center'>Sat</td> </tr> <?php echo "<tr>"; for($i = 1; $i < $numDays+1; $i++, $counter++){ $timeStamp = strtotime("$year-$month-$i"); if($i == 1) { $firstDay = date("w", $timeStamp); for($j = 0; $j < $firstDay; $j++, $counter++) { echo "<td> </td>"; } } if($counter % 7 == 0) { echo "</tr><tr>"; } $monthstring = $month; $monthlength = strlen($monthstring); $daystring = $i; $daylength = strlen($daystring); if($monthlength <=1) { $monthstring = "0".$monthstring; } if($daylength <=1) { $daystring = "0".$daystring; } $todaysDate = date("m/d/Y"); $dateToCompare = $monthstring.'/'.$daystring.'/'.$year; echo "<td align='center' width='60px' height='40px'"; if($todaysDate == $dateToCompare) { echo "class='today'"; } else { $sqlCount = "SELECT * from tbl_calendar where eventDate='".$dateToCompare."'"; $resCount = $conn->query($sqlCount); $noOfEvent = $resCount->num_rows; if($noOfEvent >= 1){ echo "class='event'"; } } echo "><a href='".$_SERVER['PHP_SELF']."?month=".$monthstring."&day=".$daystring."&year=".$year."&v=true' style='text-decoration:none; color:#000;'>".$i."</a></td>"; } echo "</tr>"; ?></table><br/> <?php if(isset($_GET['v'])) { echo "<a href='".$_SERVER['PHP_SELF']."?month=".$month."&day=".$day."&year=".$year."&v=true&f=true' style='float:left; margin:-390px auto auto 500px; background-color:#83694d; padding:5px; border-color:#fece99; border-radius:4px; color:white; cursor:pointer; width:58px; text-decoration:none; font-weight:bold;'>Add Event</a>"; if(isset($_GET['f'])) { include("eventform.php"); } $sqlEvent = "SELECT * FROM tbl_calendar WHERE eventDate = '".$month."/".$day."/".$year."'"; $resEvent = $conn->query($sqlEvent); $cntEvent = $resEvent->num_rows; echo "<br/>"; if(isset($_GET['f'])) { echo "<div style='float:left; margin:-150px auto auto 500px;'>"; } else { echo "<div style='float:left; margin:-370px auto auto 500px;'>"; } while($row= $resEvent->fetch_array()) { echo "<b>Title: </b>". $row['Title']."<br/>"; echo "<b>Detail: </b>". $row['Detail']."<br/>"; } echo "</div>"; } ?></body></html>eventform.php<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title></head><body><form name='eventform' method='POST' action="<?php $_SERVER['PHP_SELF']; ?>?month=<?php echo $month;?>&day=<?php echo $day; ?>&year=<?php echo $year; ?>&v=true&add=true"> <div style="float:left; margin:-360px auto auto 500px;"> <table width='400px'> <tr> <td width='50px' style='font-weight:bold;'>Title: </td> <td width='250px'><input type='text' name='txttitle' size='40'></td> </tr> <tr> <td width='50px' style='font-weight:bold;'>Detail: </td> <td width='250px'><textarea name='txtdetail' style='width: 300px; height: 150px;'> </textarea></td> </tr> <tr> <td colspan='2' align='center'><input type='submit' name='btnadd' value='Submit' style='width:80px; height:25px; background-image:url(images/Search-Button.jpg); border-radius:5px; border: 1px solid #616f7c; color:#fff; margin: auto;cursor:pointer;'></td> </tr> </table> </div></form></body></html>Thank you
  19. Hi, i am playing a game and there is a user in chat that bothers me and other players a lot but he does not break any game rule... i was wondering if there is a way i could block or mute his text with a JavaScript if so, does anyone have a tutorial on how to code something like this? the chat have no ID but every chat message is put out like this. <table border="0" padding="0" cellspacing="0" width="100%"> <tbody> <tr> <td width="90" class="chat"> <div id="202525"></div> 2015-08-24 06:06:00 </td> <td style=""> <a href="javascript:newmsg('The Martyr','')" style="">The Martyr:</a> " so I starting to give up" </td> </tr> </tbody></table> and it looks like this in chat: 2015-08-24 06:06:00 The Martyr: so I starting to give up i was thinking i could use the user name 'The Martyr' in some way to block that user i would love to code something that would just remove the lines from the chat box. and any other line the user typed and will type. i just have no idea where to start. any kind of help would be appreciated thanks
  20. I get an error code You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near I found this is error 1149 ? is that right? I'm looking for the meaning of this error. What is the reason I'm having this? Does it mean the mysq code in my php script is wrong? Is a solution changing the MYSQL line or can the error also be made in the php part of the script?
  21. Bootstrap sounds a bit like a finished optional program to use? also It seemed like when I first started seeing this page I have been learning from, that it is trying to "sell me" on the HTML5 as a good new and easier way to think of html code I wonder if this stuff has any merit? is it true? Is there any particular Web and computer code language *(scripting etc,) that are universal, or more functional for a different similar type? like for example I have read that someone wrote "there personal favorite scripting is" and similar quoted. Is there any that are not liked or favored by many, but are more sort of fundamentally necessary to and work very well, and will be around to stay? It seems like to me HTML, is the way things are done, also interactions with internet and computers happens with javascript. As I have researched more about how it all works, It seems there are database languages that are used as well, and of course web page layout - CSS, it seems like some of these must be more of a basic foundation? I would like to focus on the types of web coding that have stood the test of time? types of code that aren't going anywhere due to the nature of how they function is not likely to be outdated soon? some of the questions and comments are referring to, jSON, mySql, appML, PHP, jquery, CSS, bootsrap, html5, (html5 vs. HTML or XHTML), xml, are any of the things listed Proprietarily limited more-so than others? or do any of them duplicate function of another? all generally speaking, I am sure there are reasons for everything. but to cut down the cluster of things to learn? which is important, and if multitudes of things are important enough to learn. which order is best?
  22. I'm receiving this error 'Call to a member function prepare() on null' if I were to put this search code into the page. It works fine if i were to put at other pages(for inserting to database).Here's my search code that I've put before the html tags: <?php//echo '<pre>';//echo $_POST;//echo '</pre>';//declare the form name//$searchForm = htmlentities($_SERVER['PHP_SELF']);try { //inserts database connections require('Connections/database.php'); if (($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['search'])) { // array to hold errors $errorsSearch = array(); //create a bad word array $badwords = array('######','damn','mother######er','###### you'); //Declare variables $search = $_POST['search']; //Validations for the $_POST //check if it's blank if (trim($search) == "" || !isset($search)) { $errorsSearch[] = ("Search is blank!"); } //Check if the text to search is too long if (isset($search) && strlen(trim($search)) > 50) { $errorsSearch[] = ("The text to search is too long!"); } //Check for any vulgarities if (isset($search) && in_array($search,$badwords)) { $errorsSearch[] = ("No vulgarities!"); } if (empty($errorsSearch)) { //Declare the sql query $query = "SELECT * FROM portfolio WHERE nameOfPortfolio LIKE '%$search%'"; //var_dump($query); $stmt = $database->query($query); $number_of_rows = $stmt->fetchColumn(); if ($number_of_rows == 0) { $errorsSearch[]= ("No results! Sorry, please try again!"); } if ($number_of_rows > 0) { //$errors[] = "There is an existing record. You cannot insert another profile! Either update the old one, or delete to insert again."; header("Location:searchResults.php"); exit; }} if (isset($errorsSearch) == true) //foreach($errors as $error){ echo "<div id=search_errors>" .implode("<br>", $errorsSearch) . "</div>"; //printf("%s",$error);}} //end of form processing} //end of try methodcatch(PDOException $e){ // end of database dependent code, handle any errors $status = empty($query) ? 'Connection failed':" Query failed: $query"; // application message trigger_error("$status, Error: {$e->getMessage()}, File: {$e->getFile()}, Line: {$e->getLine()}"); // user message $errorsSearch[] = 'Sorry, this page is not working at this time.';}// done with the database, destroy any pdostatment resource and close connection$stmt = null;$database = null; //the html document that uses any data from the above code starts here -?> This is my code for getting the data: <table width="379" border="0" cellspacing="0" cellpadding="0" style=" border-style: solid" > <?php try { //connect to database require_once('Connections/database.php'); //Selecting a single row! $sql = "SELECT * FROM userProfile WHERE user_id in ( select id from users where id = ".($_SESSION['user_id']).")"; //Prepare our SELECT statement. $statement = $database->prepare($sql); //Execute our SELECT statement. $statement->execute(); if (!$row = $statement->fetch(PDO::FETCH_ASSOC)) { print_r ("No Data to show. Please add in your profile. Navigate your way through the left side of the page where the navigations are."); } if (isset($errors) == true) { echo "<div id=add_port_errors>" .implode("<br>", $errors) . "</div>"; }// get method/display code (if any) - get/produce data that's needed to display the page// to edit existing data, if the $data array is empty at this point, retrieve any existing data from the database table?> <tr> <th width="auto" scope="row"><div align="left">Profile Picture:</div></th> <td width="auto"><img src="<?php print htmlspecialchars($row['picPath']); ?>" width="82" height="72"> </td> <td width="auto"><form name="editProfile" method="post" action="editProfile.php"> <input type="submit" name="edit" id="edit" value="Edit"> </form></td> </tr> <tr> <th scope="row"><div align="left">Username:</div></th> <td><label><?php print htmlspecialchars($row['username']); ?></label></td> <td><form name="editProfile" method="post" action="editProfile.php"> <input type="submit" name="edit" id="edit" value="Edit"> </form></td> </tr> <tr> <th scope="row"><div align="left">Name:</div></th> <td><label><?php print htmlspecialchars($row['Name']); ?></label></td> <td><form name="editProfile" method="post" action="editProfile.php"> <input type="submit" name="edit" id="edit" value="Edit"> </form></td> </tr> <tr> <th scope="row"><div align="left">Email:</div></th> <td><label><?php print htmlspecialchars($row['Email']); ?></label></td> <td><form name="editProfile" method="post" action="editProfile.php"> <input type="submit" name="edit" id="edit" value="Edit"> </form></td> </tr> <tr> <th scope="row"><div align="left">ContactNo:</div></th> <td><label><?php print htmlspecialchars($row['ContactNo']); ?></label></td> <td><form name="editProfile" method="post" action="editProfile.php"> <input type="submit" name="edit" id="edit" value="Edit"> </form></td> </tr> <tr> <th scope="row"><div align="left">Skillset:</div></th> <td><label><?php print htmlspecialchars($row['skillset']); ?></label></td> <td><form name="editProfile" method="post" action="editProfile.php"> <input type="submit" name="edit" id="edit" value="Edit"> </form></td> </tr> <tr> <th scope="row"><div align="left">Specialization:</div></th> <td><label><?php print htmlspecialchars($row['Specialization']); ?></label></td> <td><form name="editProfile" method="post" action="editProfile.php"> <input type="submit" name="edit" id="edit" value="Edit"> </form></td> </tr> <tr> <th scope="row"><div align="left">Introduction:</div></th> <td><label><?php print htmlspecialchars($row['introduction']); ?></label></td> <td><form name="editProfile" method="post" action="editProfile.php"> <input type="submit" name="edit" id="edit" value="Edit"> </form></td><?php } //catch(PDOException $e){ // end of database dependent code, handle any errors$status = empty($query) ? 'Connection failed':" Query failed: $query";// application messagetrigger_error("$status, Error: {$e->getMessage()}, File: {$e->getFile()}, Line: {$e->getLine()}");// user message$errors[] = 'Sorry, this page is not working at this time.';}// done with the database, destroy any pdostatment resource and close connection$stmt = null;$database = null; ?> </tr> </table> My database is correct though, I'm using $database for all the connections, i didn't change the variable name. I'm not sure why it wouldn't initialized. Is my select query wrong? ;-;
  23. Hi,Good day!I created a search box and my problem is when I type Employee ID the auto list displayed is Employee Name, I need to display on the list is based on what I type. I don't know if it is possible that in one search box I can search Employee name then the list of names will display, when I type Employee ID, employee id list will display. same with Passport no and res id.Now, when I type Employee Id or Passport No or res id and employee name. the displayed list is employee name.this is my code: <script type="text/javascript" src="js/jquery.js"></script> <script type='text/javascript' src='js/jquery.autocomplete.js'></script> <link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" /><script type="text/javascript">//----auto complete emp no--//$().ready(function() { $("#search_data").autocomplete("get_emp_info.php", { width: 237, minLength: 3,//search after three characters matchContains: true, mustMatch: true, selectFirst: false }); });</script> <table> <tr> <td style="border: none;color:#80600a;font-weight:bold;">Search:</td> <td><input type="text" name="search_data" id="search_data" value="" size="35" autofocus></td> </tr> </table> <?phpob_start();include('includes/connection.php');$q = strtolower($_GET["q"]);if ($q == '') { header("HTTP/1.0 404 Not Found", true, 404);}//else (!$q) return;else{$sql = "SELECT pe.employee_no, pe.employee_name, pe.passport_no, gov.res_id FROM tbl_personal_info AS pe JOIN tbl_public_info AS pu ON (pe.employee_no = pu.employee_no) JOIN tbl_e_government_info AS gov ON (pu.employee_no = gov.employee_no) WHERE pe.employee_no LIKE '%".$q."%' OR pe.employee_name LIKE '%".$q."%' OR pe.passport_no LIKE '%".$q."%' OR gov.res_id LIKE '%".$q."%'";$result = $conn->query($sql);if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { $pid = $row["employee_no"]; $employee_name = $row["employee_name"]; $passport_no = $row["passport_no"]; $res_id = $row["res_id"]; echo "$employee_name|$pid|$passport_no|$res_idn"; }} else { echo "0 results";}$conn->close(); }?>
  24. I'm trying to restrict users from accessing a page if their rank isn't manager or admin. I made a variable called $rank which is the rank that is fetched from the user's table in my database. When I echo the rank on the page, the rank does equal to manager or admin but it redirects me to the index page because it somehow doesn't equal manager or admin. When I try using this code: if(!isset($_SESSION['userID'])) { header("Location: index.php");} else if ($rank == "manager" OR $rank == "admin") { } else { header("Location: index.php");} it does work but I feel like that's the wrong way of doing it. This is the code that I'm using now and isn't working: $tUsers_Select = "SELECT users.rank, ranks.rank_name FROM users LEFT JOIN ranks ON users.rank = ranks.rank_name WHERE user_id = ".$_SESSION['userID'];$tUsers_Select_Query = mysqli_query($dbConnect, $tUsers_Select);$fetch = mysqli_fetch_array($tUsers_Select_Query);$rank = $fetch['rank'];if(!isset($_SESSION['userID'])) {header("Location: index.php");} else if ($rank !== "manager" OR $rank !== "admin") {header("Location: index.php");} Hopefully you understood. Please comment if you have any questions.
  25. I have a hard time trying to make my radio buttons work. I know that radio buttons are a special case whereby if the user did not click on them, the value will not be taken in. Thus, i have made all my radio buttons to be set per group. However, i can't seem to get the validating right. This is my current validating code as of now: if ((isset($data['specialization']) && $data['specialization'] = "specialization_1")) { $data['specialization'] = "IS"; $skillset =($data['ISgrp1'].",".$data['ISgrp2'].",".$data['ISgrp3'].",".$data['ISgrp4'].",".$data['ISgrp5']); } if ((isset($data['specialization']) && $data['specialization'] = "specialization_2")) { $data['specialization'] = "IM"; $skillset = ($data['IMgrp1'].",".$data['IMgrp2'].",".$data['IMgrp3'].",".$data['IMgrp4'].",".$data['IMgrp5']); } if ((isset($data['specialization']) && $data['specialization'] = "specialization_3")) { $data['specialization']= "CNET"; $skillset = ($data['CNETgrp1'].",".$data['CNETgrp2'].",".$data['CNETgrp3'].",".$data['CNETgrp4'].",".$data['CNETgrp5']); } if ((isset($data['specialization']) && $data['specialization'] = "specialization_4")) { $data['specialization'] = "ITSM"; $skillset = ($data['ITSMgrp1'].",".$data['ITSMgrp2'].",".$data['ITSMgrp3'].",".$data['ITSMgrp4'].",".$data['ITSMgrp5']); } I have set my specialization radio group to correspond together with my $skillset. However, my $specialization is somehow always set to "ITSM" although I click on IS" and $skillset is showing only ",,,," in the database. (it used to be nothing as i have to declare $skillset = "" for they can't read my $skillset inside the {} , I'm not sure what i have done to the piece of code o.o). I've heard about imploding (since it's in an array), and this is what I came up with: //assign skillsets based on the specialization if (!$data['specialization'] = "" && isset($data['specialization'])) { if ($data['specialization']= "specialization_1") { $data['specialization'] = "IS"; $skillset = (implode(",",($data['ISgrp1']).",".($data['ISgrp2']).",".($data['ISgrp3']).",".($data['ISgrp4']).",".($data['ISgrp5']))); } if ($data['specialization']= "specialization_2") { $data['specialization'] = "IM"; $skillset = (implode(",",($data['IMgrp1']).",".($data['IMgrp2']).",".($data['IMgrp3']).",".($data['IMgrp4']).",".($data['IMgrp5']))); } if ($data['specialization']= "specialization_3") { $data['specialization']= "CNET"; $skillset = (implode(",",($data['CNETgrp1']).",".($data['CNETgrp2']).",".($data['CNETgrp3']).",".($data['CNETgrp4']).",".($data['CNETgrp5']))); } if ($data['specialization']= "specialization_4") { $data['specialization'] = "ITSM"; $skillset = (implode(",",($data['ITSMgrp1']).",".($data['ITSMgrp2']).",".($data['ITSMgrp3']).",".($data['ITSMgrp4']).",".($data['ITSMgrp5']))); } } However, they are showing undefined $skillset and the $data[''] inside the $skillset. Please tell me where i've gone wrong, I have been searching for some examples but the examples are only those with male/female gender type of option (simple type). Why is it that they can't get the $skillset defined in that validation? Also, can someone give me a link to a good image uploading tutorial? I can't seem to get it right as it always goes to a blank page when i hit the submit>< This is my page(my html form and my php codes ): addProfile.php
×
×
  • Create New...