PHP - Need Help On Returning A Custom Message When Mouse Over
Basically I have a page which returns data from a SQL database. Column results have a mouseover javascript which pops up a message when hovered. I highlighted the code which gives me problem. What i want to do here is that when a the sql query for the field errorMessage has no value, it returns a popup (which functions properly so far), but returns the content of the field errorMessage if it has value in the database.
Here's my code : <?php $conn = mysql_connect("localhost", "root", "123456") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); $sql = mysql_query("SELECT * FROM buccaneer ORDER BY portNumber ASC") or die(mysql_error()); if(mysql_num_rows($sql) == 0) { echo "<center><b>No ORDER/S in Queue</b></center>"; } else { while($result = mysql_fetch_array($sql)) { echo"<tr><td class='tableContent'>".$result['portNumber']."</td>"; echo"<td class='tableContentDate'>".$result['dueDate']."</td>"; echo"<td class='tableContent'><span onmouseover=\"tooltip.show('Click to search ".$result['workObject']." at Shop Floor');\" onmouseout=\"tooltip.hide();\"><a href='http://*******?object=".$result['workObject']."&search=Overview'>".$result['workObject']."</a></span></td>"; echo"<td class='tableContent'><span onmouseover=\"tooltip.show('Click to search ".$result['salesOrder']." at Shop Floor');\" onmouseout=\"tooltip.hide();\"><a href='http://*******?object=".$result['salesOrder']."&search=Overview'>".$result['salesOrder']."</a></span></td>"; echo"<td class='tableContent'>".$result['systemStatus']."</td>"; if ($result['errorMessage'] = "") { echo"<td class='tableContent'><span onmouseover=\"tooltip.show('Click to add Error Message to ".$result['workObject']."');\" onmouseout=\"tooltip.hide();\"><a href='addRemarks.php'>".$result['systemRemarks']."</a></span></td>"; } else { echo"<td class='tableContent'><span onmouseover=\"tooltip.show('".$result['errorMessage']."');\" onmouseout=\"tooltip.hide();\">".$result['systemRemarks']."</a></span></td>"; } echo"<td class='tableContent'>".$result['orderType']."</td>"; echo"<td class='tableContent' id='customerName' name='customerName'>".$result['customerName']."</td>"; echo"</tr>"; }} ?> Please help as this is my project. I'm still a newbie in PHP and I have been coding for a few months only. Thanks! Similar TutorialsHello all, I'm new to PHP and new to this forum (although I have benefitted from your help already -cheers!). However, this time I cannot find the answer I need/recognise/understand.. I have a form and want to conduct tests on each field returning an error message as a session variable if the test fails. The test will be different for some of the fields, and the error message is specific to each field. If there is an error in any one of the fields I want to be redirected to a failure page where all of the error messages are displayed, otherwise I am sent on to another page. I have already written and tested a function to sanitise the incoming form data, so that's not a problem - it's just how to loop through and test. I can guess that there are many ways to do this but I need to understand why one option is better than another, and follow the syntax used (it's all part of my steep learning curve) The approach I have thought to use is to create an array holding the field name, the test and the message, then loop through using foreach, applying the array values into the test and creating the error message....but it's not working for me. The other method is to declare a variable $Stop='No' and if the loop identifies an error, part of the output is to change this to 'yes' and through that redirect to the error page. I'd really welcome your advice and tuition....cheers.. my code so far is... Code: [Select] $Stop='No'; $StaffPassCheck=sanitisealphanum($_POST['PasswordCheck']); $Errors[0]['value']= sanitisealphanum($_POST['FirstName']); $Errors[0]['message']='Please re-enter your name'; $Errors[0]['test']=($StaffFname=""); $Errors[1]['value']= sanitisealphanum($_POST['Surname']); $Errors[1]['message']='Please re-enter your surname'; $Errors[1]['test']=($StaffSname=""); $Errors[2]['value']= sanitisealphanum($_POST['Post']); $Errors[2]['message']='You must select an option'; $Errors[2]['test']=($StaffPost="Select Value"); $Errors[3]['value']= sanitisealphanum($_POST['Username']); $Errors[3]['message']='You must select an option'; $Errors[3]['test']=($StaffUser=""); $Errors[4]['value']= sanitisealphanum($_POST['Password']); $Errors[4]['message']='Please re-enter your password'; $Errors[4]['test']=($StaffPass=""); $Errors[5]['value']= sanitisealphanum($_POST['PasswordCheck']); $Errors[5]['message']='Sorry, your passwords do not match'; $Errors[5]['test']=($StaffPass===$StaffPassCheck); foreach ($Errors as $key => $Value){ if ( $Errors['test']=true ){ $Stop='Yes'; return $_SESSION[$key]=$Value['message']; } } if ($Stop='Yes'){ header('Location.test.php'); die(); }else{ header('Location.indexp.php'); } Hi I am new to php, I am trying to capture the url and place into a variable but I only get the 1st digit to show, I just cant see what I am doing wrong. Sorry to ask such a basic question but I just can't work it out, I have attached a screen shot of all me code, your help would be very very much appreciated. I'm sure it's not much, but I'm not understanding something with custom error handlers: I've created a custom error handler, which I initially set when my page loads : set_error_handler(array ( new ErrorHandler(), 'handleError' ));
It seems to catch all internal PHP errors, such as if I: var_dump($non_existing_var); right after the set_error_handler.... Now, I have an object that throws an exception after: set_error_handler(array ( new ErrorHandler(), 'handleError' )); $locale = new \CorbeauPerdu\i18n\Locale(...); // this should throw an exception ... I thought that with an error handler set, I could 'skip' the try/catch for it, but doing so, PHP spits out in its internal log: PHP Fatal error: Uncaught CorbeauPerdu\i18n\LocaleException: ....
My error handler doesn't catch it at all before, thus my page breaks!! If I want it to go through the error handler, I have to init my Locale with a try/catch and use trigger_error() like so: set_error_handler(array ( new ErrorHandler(), 'handleError' )); try { $locale = new \CorbeauPerdu\i18n\Locale(...); // this should throw an exception } catch(Exception $e) { trigger_error($e->getMessage(), E_USER_ERROR); } ... Is this normal ? I thought one of the goals of the error_handler was to catch anything that wasn't dealt with? Thanks for your answers! Okay, I had a similar problem before.
$users = mysql_query("SELECT * FROM users"); while($users = mysql_fetch_assoc($users)){ echo "<tr><td><p><a href='users.php?id={$users['user_id']}'>{$users['user_name']}</a></p></td><td>{$users['user_clan']}</td><td>{$users['troop_donations']}</td></tr>"; } I'm trying to get this to either show "Final" or "Final Overtime" but it just continues to show "Final" even when the XML key value says Overtime...
What am I missing here?
Thank you!
Hey there, Now I was curious if there was a way I could return an array in my function like the following, I currently get a error though: Code: [Select] Catchable fatal error: Object of class panel_accounts could not be converted to string in C:\wamp\www\X-HostLTD - Panel\PanelFrontend\index.php on line 21 But can you only return strings?. Here is the function that it errors on: function returnAccountInformation($AccountID) { return mysql_fetch_array(mysql_query("SELECT * FROM ****_***** WHERE *****_***** = '".mysql_escape_string($AccountID)."'")); } Could somebody help me on the matter?, Thank you. P.S sorry for staring out the table names but I don't really want people knowing my database structure hehe. My aim is for this what if the table is empty which means no results will be retrieved in the first query then I want it to repeat the $testArray as "TBD" as well. Code: [Select] function getTop5() { $this->db->select('character1_id, character2_id, character3_id, character4_id, character5_id'); $this->db->from('site_top5'); $this->db->where('status_id', '1'); $this->db->order_by('id', 'desc'); $query = $this->db->get(); $row = $query->row(); $ids = array( $row->character1_id, $row->character2_id, $row->character3_id, $row->character4_id, $row->character5_id ); $testArray = array(); foreach ($ids as $id) { if($id !== "0") { $this->db->select('character_name'); $this->db->from('characters'); $this->db->where('id', $id); $query = $this->db->get(); $row = $query->row(); $testArray[] = $row->character_name; } else { $testArray[] = "TBA"; } } return $testArray; } SELECT i.item_id, i.title, i.price, i.p_and_p, SUM(i.price + i.p_and_p) AS `total_price`, i.listing, i.condition, i.start_date_time, i.listing_duration, CONVERT_TZ(DATE_ADD(i.start_date_time, INTERVAL concat(i.listing_duration) DAY), '+00:00', u.time_zone) AS `end_date_time` FROM items i LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id LEFT JOIN categories c ON c.name = 'test' JOIN users u WHERE u.username = 'Destramic' AND i.start_date_time < NOW() AND DATE_ADD(i.start_date_time, INTERVAL concat(i.listing_duration) DAY) >= NOW()I'm having a problem with my query returning more than 1 rows...I've even copied the row which is returning to see if that'll return 2 rows but it doesn't can anyone explain why this is happening please? hello, anybody able to help me with why this is only returning the first staff member's hours? Code: [Select] <?php if(isset($_POST['view'])) { $y3=$_POST['y']; $m3=$_POST['m']; $d3=$_POST['d']; $pdate=$y3."-".$m3. "-".$d3; $pdate1 = date( 'D M j', strtotime($pdate) ); } else { $pdate = date('Y-m-d', strtotime("-1 day") ); $pdate1 = date( 'D M j', strtotime($pdate) ); } echo "<table border='1' style='border-collapse: collapse' bordercolorlight='#000000' bordercolordark='#000000' width='98%' align='center'>"; echo "<tr><td width='100%' colspan='9' align='center'><b>Timesheets For $pdate1</b></td></tr>"; $result = mysql_query("SELECT * FROM staff ORDER BY name"); while($row = mysql_fetch_array($result)) { $eid=$row['eid']; $name=$row['name']; echo "<tr>"; echo "<td align='left' colspan='9'><b>" . $name . "</b></td>"; echo "</tr>"; echo "<tr> <th align='center'>Date</th> <th align='center'>Job Number</th> <th align='center' width='30%'>Service Report</th> <th align='center'>Sign In Time</th> <th align='center'>Sign Out Time</th> <th align='center'>Lunch</th> <th align='center'>Time Billed</th> <th align='center'>Estimated</th> </tr>"; $result3 = mysql_query("SELECT * FROM timesheet WHERE date = '$pdate' AND eid = '$eid'"); $talltime = 0; while($row3 = mysql_fetch_array($result3)) { $tid=$row3['id']; $tdate=$row3['date']; $tjobnumber=$row3['jobnumber']; $teid=$row3['eid']; $tdescription=$row3['description']; $tsignin=$row3['start']; $tfinish=$row3['finish']; $tlunch=$row3['lunch']; $tkms=$row3['kms']; $tschednum=$row3['schednum']; $tdate1 = date( 'M j, Y', strtotime($tdate) ); $tsignin1 = date( 'g:i a', strtotime($tsignin) ); $tfinish1 = date( 'g:i a', strtotime($tfinish) ); if( empty($tfinish) ) { $tfinish2="<i>In Progress"; } else { $tfinish2="$tfinish1"; } $shortid=substr($tjobnumber, 5, -1); //remove the first 5 characters and minus the last character $result = mysql_query("SELECT * FROM jobs WHERE id = '$shortid'"); while($row = mysql_fetch_array($result)) { $jstatus=$row['status']; } $result4 = mysql_query("SELECT * FROM schedule WHERE id = '$tschednum'"); while($row4 = mysql_fetch_array($result4)) { $sid=$row4['id']; $sdate=$row4['date']; $seid=$row4['eid']; $sjobnumber=$row4['jobnumber']; $sstarttime=$row4['starttime']; $sstatus=$row4['status']; $setime=$row4['etime']; } $log_in_time_string = strtotime($tsignin); $log_out_time_string = strtotime($tfinish); $difference_in_seconds = ($log_out_time_string - $log_in_time_string); $tbilled = ($difference_in_seconds / 3600); if($tbilled < 0) { $tbilled1 = $tbilled + 24; } else { $tbilled1=$tbilled; } $tbilled2 = number_format(round($tbilled*4)/4,2); $tbilled3 = $tbilled2 - $tlunch ; $talltime += $tbilled3; echo "<tr>"; echo "<td align='center'>" . $tdate1 . "</td>"; echo "<td align='center'>" . $tjobnumber . "</td>"; echo "<td align='center'>" . $tdescription . "</td>"; echo "<td align='center'>" . $tsignin1 . "</td>"; echo "<td align='center'>" . $tfinish2 . "</td>"; echo "<td align='center'>" . $tlunch . " hour</td>"; echo "<td align='center'>"; if ($tbilled3 > $setime ) { echo "<font color='red'><b>*** " . $tbilled3 . " hours ***</b></font>"; } else { echo "" . $tbilled3 . " hours"; } echo "</td>"; echo "<td align='center'>" . $setime . " hours</td>"; echo "</tr>"; } echo "<tr>"; echo "<td colspan='6' align='right'><b>Totals :</td>"; echo "<td align='center' colspan='2'>"; if ($talltime > "8" ) { echo "<font color='red'><b>*** " . $talltime . " hours ***</b></font>"; } elseif ($talltime < "0" ) { echo "<font color='red'><b>Not Signed Out</b></font>"; } else { echo "" . $talltime . " hours"; } echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='8' bgcolor='#D9FFD9'><hr></td>"; echo "</tr>"; } echo "</table>"; include 'close.php'; ?> Hi All Please take a look at the code below. I am sucessfully accessing a database and pulling the details through into a HTML form with a drop down. However I then want to use a variable (test) in another page. However I cannot get the variable userrow['userid'] to send a value to my getquiz.php. What am I doing wrong? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <?php include_once "db.inc.php"; ?> <body> <form action="getquiz.php" method="GET"> <tr><td class="title">Please Select User</td> <td><select name="test"> <?php $courseid = mysqli_query($link, 'SELECT id FROM mdl_quiz WHERE course = "225"; '); if (!courseid) { $error = ' Error fetching course id: ' . mysqli_error($link); include 'error.html.php'; exit(); } else { while($row = mysqli_fetch_array($courseid)) { $user = mysqli_query($link, 'SELECT userid FROM mdl_quiz_attempts WHERE quiz =' . $row['id']); while ($userrow = mysqli_fetch_array($user)) { $names = mysqli_query($link, 'SELECT firstname,lastname FROM mdl_user WHERE id=' . $userrow['userid']); while ($usernames = mysqli_fetch_array($names)) {?> <option value="<?php $userrow['userid']?>"> <?php echo $usernames ['firstname'] . " " . $usernames['lastname'] . $userrow['userid']; ?> </option> <?php } } } } ?> </select> </td></tr> <center><input type="submit" value="Submit"></center> </table> </form> </body> </html> Browser HTTP client makes a request to a HTTP web server which makes a HTTP cURL request to a HTTP REST API which initiates a ReactPHP socket client to make a request to a socket server, and the socket server script eventually execute the following method: public function executeSpecificRequestCommand(array $data):bool { $status = $this->doSomething($data); return $status; //{success: $status} will be returned to the socket client } All is good until doSomething() takes a lot of time and results in a cURL error between the HTTP web server and HTTP REST API. For this particular case, the task isn't meant to provide immediate feedback to the user, but to do some work and update the database, and as such, my desire is to return true status and then perform the work instead of extending the cURL timeout. One option is to ran some process in the background and return status, but I don't think doing so is really right. Using a queue seems excessive as I am already decoupled via the socket. As such, I will probably just add some logic between the initial $string->on('data') and this executeSpecificRequestCommand() method to determine whether the success message should be returned before or after the method is complete. Before doing so, however, I would like to know if there is a more appropriate approach to this scenario. It appears that maybe a child process or a deferred might be appropriate, but am not sure whether I am going down the wrong path. How would i return the id in the echo of this post: $query = "INSERT INTO jobs SET agent = '".mysql_real_escape_string($agent)."', title = '".mysql_real_escape_string($title)."', location = '".mysql_real_escape_string($location)."', salary_from = '".$salary_from."', salary_to = '".$salary_to."', frequency = '".$frequency."', jobtype='".$jobtype."', description='".$description."', email = '".$email."', created_at = '".$created_at."', closing_date ='".$closing_date."', categories = '".$categories."', sectors = '".$sectors."', ref='".$ref."'"; if(mysql_query($query)) { echo "Job inserted!"; } else { die(mysql_error()); } Thanks for the help guys Ok I have this code retrieving information from mysql: if (isset($memid)) { $query_meminfo = "SELECT * FROM ".MEMBER_PROFILE_TABLE." WHERE `user_id`=".$memid; $query_result = mysql_query($query_meminfo, $db); $MemName = mysql_result($query_result, 0, 'display_name'); $MemGroup = mysql_result($query_result, 0, 'Group'); $LevelQuery = "SELECT group_level FROM ".MEMBER_GROUPS." WHERE group_id='".$MemGroup."'"; $LevelResult = mysql_result(mysql_query($LevelQuery, $db), 0, 'group_level'); $MemLevel = intval($LevelResult); } It is definitely retrieving the correct info as it is correctly checking member levels to display certain information. Part 2 of code: <table width="100%" id="userlinks" cellspacing="6"> <tr> <td>Welcome <?php if (isset($MemName)) { Echo $MemName + " "; ?> (<a href="index.php?act=logout">Logout</a> <?php if ($MemLevel >= 9000) { echo " | <a href='admin.php'>Admin CP</a>"; } ?> ) <?php } Else { ?> Guest (<a href="index.php?act=login">Login</a> | <a href="index.php?act=register">Register</a>) <?php } ?> </td> </tr> </table> For some reason, instead of displaying the person's display name it is just displaying the number 0. Hello, I am trying to implement error proofing to a log in script. But, I cannot get it to work? I have no idea what is going on, or why it doesn't work like I expect it to. I have tried everything, please advise. This is the method I am calling: Code: [Select] public function i_exist($this_username) { //$host_array = null; //$host_array = $this->collection->findOne(array("Username" => $this_username)); //if ($host_array['Username'] = $this_username) //{ return true; //} //return false; } This is where I am calling it: Code: [Select] if (!empty($_POST['Username'])) { $host = new Host(); $event = new Event(); if ($host->i_exist($_POST['Username'])) { header("Location: http://www.drink-social.com/error.php?login=duplicate"); } It is supposed to check the database and see if that username is already in use. But it never directs to the error page? I have even tried commenting everything out and returning true, and returning 1. Nothing? Any advice? Hello. I am trying to pass along a variable in an email auto response ($park), however if the variable is 2 words then it only passes along the first word. Any info would be great. Code: [Select] <?php $to = "$email"; $subject = "Event Signup Confirmation"; $message = "Hello $firstname! Thank you for signing up to work the $park event. Someone will contact you shortly. Event Information Park: $park Date: $orderdate Time: $hour:$min $ampm Description: $description Crew Leader: $leader"; $from = "guy@xxxx.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Thank you for signing up. You will receive an email shortly letting you know event details and who your crew leader is."; ?> Hi all. I'm having a bit of trouble with my script. I can't get "getDirectoryListings()" to return what folders are inside of #SharedObjects Here's my 2 files, 1 is sollib.php, the other is solindex.php. Code: [Select] solindex.php: <?php require('sollib.php'); $shell= new COM('WScript.Shell'); $data=$shell->regRead('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir'); $regval = trim($data, "Program Files"); if(getenv('AppData')!=''){ $filename = getenv('AppData')."\\Macromedia\\FlashPlayer\\#SharedObjects\\".getDirectoryListings(); die($filename); } ?> sollib.php: <?php die(getDirectoryListings()); function getDirectoryListings() { $final = ""; $filename = getenv('AppData')."\\Macromedia\\FlashPlayer\\#SharedObjects\\"; if ($handle = opendir($filename)) { while (false !== ($file = readdir($handle))) { if(($file != '.') && ($file != '..')) { if(!strpos($file,'.')) { if ($handle2 = opendir($filename.$file)) { while (false !== ($file2 = readdir($handle2))) { die($file2); if(($file2 != '.') && ($file2 != '..')) { $final = $filename."$file\\$file2\\".get_files($file2); die($final); if($file2 == 'www.xatech.com'){ die('files: '.get_files($file2)); } } } } }else{ $final = $file; } } } closedir($handle); } return $final; } function get_files($dir){ //path to directory to scan $directory = $dir; //get all sol files with a .sol extension. $file11 = glob("" . $directory . "*.sol"); //print each file name foreach($file11 as $files10){ $final = $files10; die($final); } } ?> i am having issues returning all sent messages. it will only return one for some reason. Code: [Select] //If there are sent messages, display them if ($row = mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result) or die(mysql_error()); //Open table and create headers echo "<table border=\"1\">\n"; echo " <tr>\n"; echo " <th>Recipient</th>\n"; echo " <th>Subject</th>\n"; echo " </tr>\n"; while(mysql_fetch_array($result)) { //Show messages $userIDTo = $row['userIDTo']; // Get the recipient's ID number $recipient = checkRecipient($userIDTo); // Get the sender's Username $messageID = $row['ID']; echo " <tr>\n"; echo " <td>{$recipient}</td>\n"; echo " <td><a href='messageDetails.php?messageID=$messageID' target='_blank'>{$row['subject']}</a></td>\n"; echo " <tr>\n"; } thanks in advance. <?php function time_convert($l_timestamp) { $l_timestamp = $l_timestamp * 86400; $time = date('Y-m-d',$l_timestamp); echo(date('Y-m-d',$l_timestamp)); //This does return (date('Y-m-d',$l_timestamp)); //This does not work return $time; // This does not work echo $time; //This does not work } time_convert(32155.0); ?> Can anyone help me, I am not getting the return parameter as I want I'll try to explain this as easily as possible. I'm working on making a little link shortener site just for fun/practice as a beginner with php. I originally used the source code 'lilurl' as a base to start out, but now I'm adding stuff to it for actual practice. I need some help though. I have two files, my index and my external php file. The external file is called on at the beginning of the index with require_once. The user submits a url into the PHP_SELF form and a url is returned, and it works all great. Now I'm trying to add the option to make a custom url suffix. Code: [Select] <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <fieldset> <label for="longurl">Enter a URL:</label> <input type="text" name="longurl" id="longurl" /> <input type="text" name="suffix" id="suffix" /> <input type="submit" name="submit" id="submit" value="Shrink!" /> </fieldset> </form>[/code] The form looks like this. I added the 'suffix' textbox. So after the user submits the code, it goes back up to the top (phpself). A variable is set for the url the user has inputted as "$longurl", like this. Code: [Select] $longurl = trim(mysql_escape_string($_POST['longurl']));So I added this. Code: [Select] $suffix = ($_POST['suffix']);And to check if it worked, I went down the the bottom of the index and had it echo the suffix variable. When I entered in code into the suffix text box, it would be echoed at the bottom of the page, so the variable did receive the value. So here's where the external file comes in. It is called on by require_once at the very beginning of the index. It is full of functions. One of the functions generates a random string of numbers (that I coded) to be used as the url suffix (uses the $id variable). So my plan was to erase the $id = $rand1 . blah blah stuff and put $id = $suffix. $suffix being the variable from the index that the user inputted. Make sense? Well whenever I try it, it always acts the like the variable is empty, even when I echo it on the index it returns the value of the textbox. Does anyone know what I'm doing wrong? Could it be because since I call on $suffix in the external file, and it's only been declared in the index that it's treating it like a new/empty variable? [spoiler] Someone also explained it to me like this. -I call upon the external file. -I declare the variable is the value of the text box. (Which means it's currently empty because the form has not been submitted.) -Then, the form is submitted as PHP_SELF. -The external file is called upon again. -The variable is then assigned a value. It's hard to explain, but basically that the variable in the external file is not told about the new value of the variable because they are declared after the external file is called upon? :\ So I tried moving the $suffix = ($_POST['suffix']); before the external file is called upon, but the same thing happens. It's hard to explain the situation, but I've tried a lot of things and can't get it to work.[/spoiler] |