PHP - Pulling Last Updated Record
Hi. I am trying to figure out the best approach to pull THE most recent record for display, and ONLY the most recent one. I am really not sure how to go about doing this. Ive just started into stored procedure programming and php, but havent found anything yet on this one. Thanks.
Similar TutorialsWhat's the best way to display when a page was last edited/modified? this is the script for viewing the data in edit mode <tr> <td width="67" height="24"><select name="qualifi"> <option selected="selected">None</option> <?php $qry=mysql_query("select * from qualification"); while($obj=mysql_fetch_array($qry)) { ?> <option value="<?php echo $obj[0]; ?>"<?php if($obj[0]==$qualifi) echo("selected"); ?>><?php echo $obj[1]; ?></option> <?php } ?> </select> </td> <?php echo"<td width='301'><input name='board' type='text' size='50' value='$board'/></td>"; echo"<td width='60'><input name='start' type='text' size='10' value='$start'/></td>"; echo"<td width='60'><input name='end' type='text' size='10' value='$end'/></td>"; echo"<td width='60'><input name='percentage' type='text' size='10' value='$percentage'/></td> </tr>"; } ?> </table> and the update query is like //qualification if($_SESSION[empcode]!="") { if($_SESSION[qualifi]!="None") { mysql_query("update HRMEMPQUAL set EMPCODE='$_SESSION[empcode]',QUALCODE='$_SESSION[qualifi]',BOARD='$_SESSION[board]',FROMYEAR='$_SESSION[start]',TOYEAR='$_SESSION[end]',MARK_PERCENT='$_SESSION[percentage]' where EMPCODE='$_SESSION[empcode]'"); } } how can i save all the data correctly while any change is take place...their are 3 rows of data.only the last fled data is updated all the 3 rows Is there something wrong with this query? elseif($_POST["titlee"] && $_POST["contente"]) { $titlee = $_POST['titlee']; $contente = $_POST['contente']; $to = $_POST['edit']; mysql_query("UPDATE custom_pages SET title='$titlee' AND content='$contente' WHERE id='$to'"); echo '<div class="post"> <div class="postheader"><h1>Updated</h1></div> <div class="postcontent"> <p>Your custom page has been updated.</p> </div> <div class="postfooter"></div> </div> '; } I have a script to update certain rows that contain certain data in them. Here is the code: if ($_POST['newstype'] == "1") { $query = mysql_query("SELECT * from `news` WHERE type='1'"); if (mysql_num_rows($query) == 1) { mysql_query("UPDATE `news` SET type = '2' WHERE type = '1' ORDER BY `news`.`dtime` ASC LIMIT 1") or die(mysql_error()); } else { echo "did not edit main news"; } } elseif ($_POST['newstype'] == "2") { $query = mysql_query("SELECT * from `news` WHERE type='2'"); if (mysql_num_rows($query) == 3) { mysql_query("UPDATE `news` SET type = '3' WHERE type= '2' ORDER BY `news`.`dtime` ASC LIMIT 1") or die(mysql_error()); } else { echo "did not edit recent news"; } } elseif ($_POST['newstype'] == "3") { $query = mysql_query("SELECT * from `news` WHERE type='3'"); if (mysql_num_rows($query) == 3) { mysql_query("UPDATE `news` SET type = '4' WHERE type= '3' ORDER BY `news`.`dtime` ASC LIMIT 1") or die(mysql_error()); } else { echo "did not edit old news"; } } else { echo "didnt update anything!"; } Here is my database structure. Why is it not updating it and always saying Did not edit main/recent/old news. i am a beginerr in php.. and here is my code..which shows error in the querry line.. erro goes like this Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\restafinal\process_edit_page.php on line 56 and code goes like this.. echo part works well...that query line is the error line..please tell me whats the problem... Code: [Select] <?php //$id=$_GET["id"]; $id= $_GET['id']; $menu_name= $_POST['menu_name']; $position= $_POST['position']; $visible= $_POST['visible']; $note= $_POST['note']; $content= $_POST['content']; //echo part works well.. echo "menu_name"; echo $menu_name; echo "<br/>"; echo "position"; echo $position; echo "<br/>"; echo "visible"; echo $visible; echo "<br/>"; echo "note"; echo $note; echo "<br/>"; echo "id"; echo $id; echo $content; [b]$result = mysql_query(UPDATE page SET note =$note, nevigation = $menu_name WHERE id = $id,$connection)[/b] // test to see if the update occurred if (mysql_affected_rows() == 1) { // Success! } else { $message = "The page could not be updated."; $message .= "<br />" . mysql_error(); } ?> I'm creating a game where 2 people, on separate computers can battle each other. I'm doing it turn-based, like Final Fantasy but I came across a problem, how do I check if the other person has ended their turn? I was thinking that I would have an area in my database that would be true/false if it was their turn. So if the first person ends their turn, their 'turn' becomes false in the database, but how, on the other users computer, do I constantly check if the 'turn' has become false so that they may now play without having to keep updating the browser. Or is their a better way to do something like this? I think I've gotten as far as I can with my troubleshooting so hopefully someone can help me here. I have a constructor for a controller class that receives the $_SESSION array from index.php by reference. An instance variable is then created when references this references so that any changes made to this instance variable update the real $_SESSION variable. This was working until it mysteriously stopped after not touching it for a few hours. The local $this->session variable is working because it completes some tasks using it. I've also hardcoded values into the session from the index.php file and when they are hard coded the session works as you would expect so it seems to just not be connecting this local variable to the $_SESSION array anymore for some reason. index.php snippet: Code: [Select] session_start(); $action = 'login'; $controller = new UserController($_POST,$_SESSION); call_user_func(array($controller,$action)); constructor and login action from UserController (constructor is actually from a base controller but that shouldn't matter). Also the activeSession() function that checks if a session is valid and kicks the user if its not (which is what happens when anything is tried after logging in): Code: [Select] function __construct($post,&$session){ $this->post = $post; $this->session = &$session; $this->view = 'views/login.php'; $this->title = ''; $this->error = ''; } function login(){ try{ $user = $this->validateString($this->post['username'],'Username'); $pass = $this->validateString($this->post['password'],'Password'); $dao = new UserData(); $this->session['userid'] = $dao->login($user, $pass); $this->session['username']=$user; $dao = new PostData(); $this->posts = $dao->getFeedPosts($this->session['userid']); $this->view = 'views/posts.php'; $this->title = 'Post Feed'; } catch(Exception $e){ $this->handleException($e); } } function activeSession(){ if(!empty($this->session['userid'])) return true; else return false; } Any help would be amazing. I really don't know how this stopped working. Thanks in advance. I have been using an inventory application built on PHP/MySQL. Since this morning I could submit the data and they were perfectly reflected on the MySQL Table. However, for a few hours I cannot save the submitted data to the table and it doesn't show any error message. Please note no change have been made since it was successfully running. The developer of this application is not available right now.
PLEASR HELP I AM A NOVICE IN PHP/MYSQL.
Hi guys, I need your help. I am checking on a database as I want to see if the records have been updated or not. Code: [Select] <?php session_start(); define('DB_HOST', 'localhost'); define('DB_USER', 'mydbuser'); define('DB_PASSWORD', 'mydbpass'); define('DB_DATABASE', 'mydbtable'); $errmsg_arr = array(); $errflag = false; $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } function clean($var){ return mysql_real_escape_string(strip_tags($var)); } $username = clean($_GET['user']); $password = clean($_GET['pass']); $test = clean($_GET['test']); $public = clean($_GET['public']); if (isset($_GET['user']) && (isset($_GET['pass']))) { if($username == '' || $password == '') { $errmsg_arr[] = 'username or password are missing'; $errflag = true; } } elseif (isset($_GET['user']) || (isset($_GET['test'])) || (isset($_GET['public']))) { if($username == '' || $test == '' || $public == '') { $errmsg_arr[] = 'user or others are missing'; $errflag = true; } } if($errflag) { $_SESSION['ERRMSG_ARR'] = $errmsg_arr; echo implode('<br />',$errmsg_arr); } else { $qry="SELECT * FROM members WHERE username='$username' AND passwd='$password'"; $result=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if ($username && $password) { if(mysql_num_rows($result) > 0) { $qrytable1="SELECT images, id, test, links, Public FROM user_channel_list WHERE username='$username'"; $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); while ($row = mysql_fetch_array($result1)) { echo "<p id='test'>"; echo $row['test'] . "</p>"; echo '<p id="images"> <a href="images.php?test=test&id='.$row['id'].'">Images</a></td> | <a href="http://' . $row["links"] . '">Link</a> </td> | <a href="delete.php?test=test&id='.$row['id'].'">Delete</a> </td> | <span id="test">'.$row['Public'].'</td>'; } } else { echo "user not found"; } } elseif($username && $test && $public) { $qry="SELECT * FROM members WHERE username='$username'"; $result1=mysql_query($qry) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result1) > 0) { $qrytable1="SELECT Public FROM user_channel_list WHERE username='$username' && test='$test'"; $result2=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error()); if(mysql_num_rows($result2) > 0) { $row = mysql_fetch_row($result2); mysql_query("UPDATE user_list SET Public=('$_GET[public]') WHERE username='$username' AND test='$test'"); echo "update!"; } else { echo "already updated!"; } } else { echo "user not found"; } } } ?> When I run debug the code on my php, if i input the data in a url bar while the records are the same as the data that I enter in the url, i should get the print out on my php "already updated", but I keep getting "update!". Do you know how i can check on mysql database to see if the records have been updated or not?? Hi all, i want delete old updated images with considering its index in array. <?php global $oldimg; $oldimg = array(); //action: edit news if (isset($_GET['id'])) { $NewsID = (int)$_GET['id']; if ($NewsID == 0) { $rdir = '<META HTTP-EQUIV="Refresh" CONTENT="1.4;URL=panel-news.php">'; die($rdir);} //get user from the database and put data into $_POST variables. //Include database connection details require_once('../config.php'); //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $rs = mysql_query("SELECT newsimg1, newsimg2, ". " newsimg3 FROM news WHERE id = $NewsID"); if (mysql_num_rows($rs) == 0) die('no such a newsID!'); $row = mysql_fetch_assoc($rs); $oldimg[0] = $row['newsimg1']; $oldimg[1] = $row['newsimg2']; $oldimg[2] = $row['newsimg3']; } ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" enctype="multipart/form-data"> <input type=file name="file[]" size=20 accept="image/jpg,image/jpeg,image/png"> <input type=file name="file[]" size=20 accept="image/jpg,image/jpeg,image/png"> <input type=file name="file[]" size=20 accept="image/jpg,image/jpeg,image/png"> <input type="hidden" name="MAX_FILE_SIZE" value="2097152" /> <input type="hidden" name="NewsID" value='<?php echo (isset($NewsID))?$NewsID:"0";?>'> <input type="submit" value="edit" id="save" name="save"/> </form> <?php if (isset($_POST['save']) && isset($_POST['NewsID'])){ $NewsID = (int)$_POST['NewsID']; //Include database connection details require_once('../config.php'); //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } //max fle size value $max_file_size = 2097152; //Global newsimg global $newsimg;global $ctr; $ctr = 0; //timestamp to make files unique names $timestamp = time(); //destination folder path $destpath = "../Dir/Newsimg/"; //looping each file or image from the form while(list($key,$value) = @each($_FILES["file"]["name"])) { //check if any empty or errors if(!empty($value)){ if ($_FILES["file"]["error"][$key] > 0) { $edir ='<div id="fail" class="info_div">'; $edir .='<span class="ico_cancel"><strong>'; $edir .="err : ". $_FILES["file"]["error"][$key] .'</strong></span></div>'; echo($edir); } else { //add the timestamp to filename $file_name = $timestamp.$_FILES['file']['name']; //temp name from upload form, key of each is set $source = $_FILES["file"]["tmp_name"][$key] ; //getting the file type $file_type = $_FILES["file"]["type"][$key]; //placing each file name into a variable $filename1 = $_FILES["file"]["name"][$key]; //lowering the file names $filename = strtolower($filename1); //adding timestamp to front of file name $filename = "$timestamp$filename"; ++$timestamp; if ($file_type != "image/jpeg" && $file_type != "image/png" && $file_type != "image/jpg") { die(" <div id='fail' class='info_div'> <span class='ico_cancel'><strong> Invalid Format!</strong></span><br /> <a href=\"javascript: history.go(-1)\">Retry</a> </div>"); } //moving the file to be saved from the temp location to the destination path move_uploaded_file($source, $destpath . $filename); //the actual final location with timestamped name $final_file_location = "$destpath$filename"; if (file_exists($final_file_location)) { if (isset($oldimg[$ctr])) { chdir('../Dir/Newsimg/'); echo $oldimg[$ctr]; unlink($oldimg[$ctr]);} $newsimg[$ctr] = $filename; $ctr++; ?>TNX. I am creating a stream page that updates automatically without the page reloading by reloading a div on the page using a timer. However, I only want it to run the update and fade in/fade out when there is a new status in the table. I tried doing it through PHP getting the number of rows in the table on the page itself and then checking the number of rows on an action page, however, the number of rows didnt update when the div was reloaded. I then tried doing it using jquery/javscript but had the same problem. How can I acheive this? Thanks in advance I'm trying to get a simple javascript popup script going anytime the database is updated in real-time. I'm not sure as to what to do next, because I'm still a newbie with jQuery and ajax, but the following code is what I have right now:
PHP MySQL query page:
<?php $con = mysqli_connect('localhost','root','root','mydb'); if (!$con) { die('Could not connect: ' . mysqli_error($con)); } mysqli_select_db($con,"mydb"); $sql="SELECT * FROM incoming_calls"; $result = mysqli_query($con,$sql); while($row = mysqli_fetch_array($result)) { $callArray[] = array('phonenumber' => $row['phone_number'], 'id' => $row['phone_login_id']); } if (!empty($callArray)) { //echo json_encode($callArray); for ($i = 0; $i < count($callArray); ++$i) { print $callArray[$i]['id'] . ": " . $callArray[$i]['phonenumber'] . "<br>"; } } mysqli_close($con); ?>MySQL "incoming_calls" db table (I have a node.js script, that draws SMDR data from a phone system and posts it to this table): id phone_number phone_login_id date_created 3 000-000-0000 1225 12/15/2014 14:53 6 000-000-0000 1222 12/15/2014 14:53 9 000-000-0000 1202 12/15/2014 14:53 12 000-000-0000 1201 12/15/2014 14:55 18 000-000-0000 1232 12/15/2014 14:55 21 000-000-0000 1222 12/15/2014 14:57 24 000-000-0000 1222 12/15/2014 14:57 27 000-000-0000 1201 12/15/2014 14:58 30 000-000-0000 1207 12/15/2014 14:58 33 000-000-0000 1212 12/15/2014 14:59HTML ajax call page: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Phone calls</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> </head> <body> <script language="javascript" type="text/javascript"> function getCall(){ $.get("phonecall.php", function(data){ $("#call").html(data); }); } setInterval(getCall,5000); </script> <div id="call"></div> </body> </html>Any help with this is greatly appreciated! Thanks ahead of time! Edited by Juan1989, 16 December 2014 - 11:07 AM. I am trying to set the hidden input in the javascript but it doesn't set it in the php. This is the form with the hidden input. It corresponds to a field in the database table with the name of draggables. <form method="post" accept-charset="utf-8" id="myForm2" action="/mealplans/add"> <input type="hidden" name="draggables" id="drag12"/> <button id="myId" type="submit">Submit Form</button> </form> This is where I change the value in the javascript: if(data == "draggable3"){ alert("data " + data); var x = document.getElementById("drag12").value; x = "draggable3"; alert(x); } //end if
I've also tried getElementsByName but that didn't work either. var y = document.getElementsByName("draggables").value; //only changes it on the client This is actually a cakephp site but this problem is with the PHP so I am publishing it here. So I'm having issue with trying to pull the ID from my database out correctly. This is the ideal way I want the ID to be pulled. http://a7.sphotos.ak.fbcdn.net/hphotos-ak-snc6/226659_219275201434540_100000561868489_827151_3402533_n.jpg But then it always pulls the ID like this and stacks the number ID ontop of each other and I want it to have separate DIVS. http://photos-e.ak.fbcdn.net/hphotos-ak-snc6/226659_219275204767873_100000561868489_827152_3422285_n.jpg This is the code that I'm using. Tell me what I'm doing wrong. Code: [Select] <? mysql_connect("localhost", "mysql_user", "mysql_password") or die("Could not connect: " . mysql_error()); mysql_select_db("mydb"); $result = mysql_query("SELECT id, name FROM mytable"); echo "<div class=\"body_resize\"><div class=\"left\"><br /><span class='date'>$timedate</span><br /><br />"; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { printf("<h2>#%s</h2>", $row["id"], $row["name"]); } mysql_free_result($result); echo "<br /><div class=\"comment_gravatar left\"><img alt=\"\" src=\"http://photos-b.ak.fbcdn.net/hphotos-ak-snc6/229186_219276548101072_100000561868489_827154_8135363_n.jpg\" height=\"32\" width=\"32\" /></div><p>Posted By $name<br><br /><p>$message</p><br></div><div class=\"clr\"></div></div>"; if ($ip==$userip && $delcom==1) { ?> hello. please could someone help me with this conundrum im trying to pull my content dynamically. im almost there but im stuck with some code. so i have a layout with 3 columns and in each column i have a place holder. ph01, ph02, ph03 each page has its own id and depending on what the page id is i what to pull different elements into the 3 placeholders. so for this code in the database i have the following: table name: placeholders pages_id = page id ph_number = placeholder number contElements_id = element ids id pages_id ph_number contElements_id 1 1 1 1, 2, 3 2 1 2 4, 5, 6 3 1 3 7, 8, 9 table name: contelements name = name of the element id name 1 E1 2 E2 3 E3 4 E4 5 E5 6 E6 7 E7 8 E8 9 E9 SO, page_ID=1 has 3 placeholders and they should show: ph01 should display = E1, E2, E3 ph02 should display = E4, E5, E6 ph03 should display = E7, E8, E9 this is the code im trying to put together. on the page im using this include function in the left, center and right columns. Code: [Select] $phNo = "1"; echo include_admin_contElements($phNo, $pageID); $phNo = "2"; echo include_admin_contElements($phNo, $pageID); $phNo = "3"; echo include_admin_contElements($phNo, $pageID); now this is where the problem is.... i think in the function file i have this but its a mess.. Code: [Select] function include_admin_contElements($phNo, $pageID){ $PH = Placeholders::find_all(); foreach ($PH as $PHs){ $PHid = $PHs->id; $PHpid = $PHs->pages_id; $PHce = $PHs->contElelments_id; $PHn = $PHs->ph_number; if($pageID == $PHpid){ $CE = Contelements::find_by_PHce($PHce); foreach ($CE as $CEs){ echo $CEid = $CEs->id; echo $CEname = $CEs->name; } } } } - so the idea is i get $phNo, $pageID from the page, - then find all the placeholders in the database Quote Placeholders::find_all(); - then if the $pageID is the same as the $PHpid in the placeholder database Quote if($pageID == $PHpid){ get the content elents for that page. - then i want to get the elements that belong to that page using Quote Contelements::find_by_PHce($PHce); but that does not work Code: [Select] public static function find_by_PHce($PHce=0){ $sql = "SELECT * FROM ".self::$table_name." WHERE id=".$PHce.""; $result_array = self::find_by_sql($sql); return $result_array; } anyway... im stuck. this code doesn't even seperate the 3 different placeholders. it needs a more experienced eye.. its a mess please help thanks ricky Code: [Select] <?php ob_start(); session_start(); $pagerank=2; if ($rank < $pagerank){ header('Location:main.php?id=lowrank.php'); } else{ $name1 = $_GET["name"]; $type2 = $_GET['type']; Echo "Your seach for ".$name1." gave the following results: "; $records_per_page = 15; $total = mysql_result(mysql_query("SELECT COUNT(*) FROM systems WHERE '$type2' LIKE '%$name1%'"), 0) or die(mysql_error()); $page_count = ceil($total / $records_per_page); Echo $total." Records Found"; echo "<table border=0>"; $page = 1; if (isset($_GET['page']) && $_GET['page'] >= 1 && $_GET['page'] <= $page_count) { $page = (int)$_GET['page']; } $skip = ($page - 1) * $records_per_page; $result = mysql_query("SELECT * FROM systems WHERE $type2 LIKE '%$name1%' ORDER BY Security DESC LIMIT $skip, $records_per_page") or die(mysql_error()); echo "<table border=1>"; echo "<td>System Name</td><td>Security</td><td>Class</td>"; while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td valign =top>".$row['System Name']."</td>"; echo "<td valign =top>".round($row['Security'],1)."</td>"; echo "<td valign =top>".$row['System Type']."</td>"; echo "</tr>"; } echo "</table>"; echo "<br>"; for ($i = 1; $i <= $page_count; ++$i) { echo '<a href="main.php?id=' . $_GET['id'] .'&name='.$name1.'&type='.$type1. '&page=' . $i . '">' . $i . '</a> '; } } ?> The above code takes data entered in a form and is suppose to show the matching results, but no records are showing, it works when I replace the $name1 and $type2 with the actual values, any ideas? I am creating a music blogging site however the main page will only show one video the code is below anyone have any ideas? " <?php //open database $connect = mysql_connect("******","username","password") or die("Not connected"); mysql_select_db("collegebooxboox") or die("could not log in"); $query = "SELECT * FROM boox ORDER BY date DESC"; $result = mysql_query($query); // Get the page number, if none is set - it is 0 if( isset($_GET['page']) ) { $page =$_GET['page']; } else { $page = 0; } $resultsPerPage = 15; $num = mysql_num_rows($result); // amount of rows $loops = $page*$resultsPerPage; // starting loops at.. while ($loops < $num && $loops < ($page+1)*$resultsPerPage ) { $link = mysql_result($result,$loops,"link"); // get result from the 'Title' field in the table $username = mysql_result($result,$loops,"username"); // get result from the 'Content' field in the table $messsage = mysql_result($result,$loops,"message"); $date = mysql_result($result,$loops,"date"); if ($pagelimit == 0) { $pagelimit == 1; } if ($pagelimit <= 15) // echo stuff here $loopz = $loops + 1; echo "   </br><align='left'><table width='297' height='900' border='1' align='center' bgcolor='#111'> <tr> <td>$loopz. $link </br> $message </br> Posted By: $username $date </td> </tr> </table></br><br>"; $count++ ; $pagelimit++; $loops++; } if ( $page!=0 ) // Show 'Previous' link { $page--; $prevpage = ($page + 1); echo "<br><br><br><a href='index.php?page=$page'>Previous $prevpage </a>"; $page++; } if ($loops > 5&&($page+1)*$resultPerPage < $num ) // Show 'next' link { $page++; $nextpage = ($page + 1); echo "<a href='index.php?page=$page'> Next $nextpage</a>"; } ?> " Good evening, This has been bugging me for 24 hours now. I have created 2 web applications. The first one is the dummy, and the second one is the final. Basically, this two web applications does the same, just a few modifications made on the final one. I have a process of pulling out of information from the database should the user would want to modify a field. I have a problem though, the dummy one works perfectly, but the new one don't. In fact, if I use the dummy php file together with the new files, the dummy won't be working. But if I use it together with the old files, it works perfectly fine. This is the error I am getting: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\invent-asia\edit_client.php on line 46 <?php include("dbconnection.php"); if(isset($_POST["btnSubmit"])) { $id = $_POST["id"]; $territory = $_POST["territory"]; $job_title = $_POST["job_title"]; $area_of_work = $_POST["area_of_work"]; $employer = $_POST["employer"]; $location = $_POST["location"]; $job_title = $_POST["job_title"]; $date_posted = $_POST["date_posted"]; $closing_date = $_POST["closing_date"]; $department = $_POST["department"]; $gender = $_POST["gender"]; $first_name = $_POST["first_name"]; $last_name = $_POST["last_name"]; $title = $_POST["title"]; $telephone = $_POST["telephone"]; $address_1 = $_POST["address_1"]; $address_2 = $_POST["address_2"]; $address_3 = $_POST["address_3"]; $country = $_POST["country"]; $city = $_POST["city"]; $postal_code = $_POST["postal_code"]; $website = $_POST["website"]; $email_address = $_POST["email_address"]; $comment_by_cg = $_POST["comment_by_cg"]; $date_emailed = $_POST["date_emailed"]; $mailing_comments = $_POST["mailing_comments"]; $telesales_comments = $_POST["telesales_comments"]; $query = "UPDATE contacts SET territory= '".$territory."', job_title = '".$job_title."', area_of_work = '".$area_of_work."', employer = '".$employer."', location = '".$location."', job_title = '".$job_title."', employer = '".$employer."', date_posted = '".$date_posted."', department = '".$department."', closing_date = '".$closing_date."', gender = '".$gender."', first_name = '".$first_name."', last_name = '".$last_name."', title = '".$title."', telephone = '".$telephone."', address_1 = '".$address_1."', address_2 = '".$address_2."', address_3 = '".$address_3."', country = '".$country."', city = '".$city."', postal_code = '".$postal_code."', website = '".$website."', email_address = '".$email_address."', comment_by_cg = '".$comment_by_cg."', date_emailed = '".$date_emailed."', mailing_comments = '".$mailing_comments."', telesales_comments = '".$telesales_comments."' WHERE id = '".$id."'"; mysql_query($query) or die(mysql_error()); echo "<script> alert('You have successfully updated a record'); window.location = 'view.php'; </script>"; } $query = "SELECT * FROM contacts WHERE id = '".$_GET["id"]."'"; $result = mysql_query($query, $connection); if(mysql_num_rows($result) > 0) - THIS IS THE 46th LINE IN THE CODE { $territory = mysql_result($result,0, "territory"); $job_title = mysql_result($result, 0, "job_title"); $area_of_work = mysql_result($result, 0, "area_of_work"); $employer = mysql_result($result, 0, "employer"); $status = mysql_result($result, 0, "status"); $location = mysql_result($result,0, "location"); $department = mysql_result($result,0, "department"); $date_posted = mysql_result($result,0, "date_posted"); $closing_date = mysql_result($result,0, "closing_date"); $gender = mysql_result($result,0, "gender"); $first_name = mysql_result($result,0, "first_name"); $last_name = mysql_result($result,0, "last_name"); $title = mysql_result($result,0, "title"); $telephone = mysql_result($result,0, "telephone"); $address_1 = mysql_result($result,0, "address_1"); $address_2 = mysql_result($result,0, "address_2"); $address_3 = mysql_result($result,0, "address_3"); $city = mysql_result($result,0, "city"); $country = mysql_result($result,0, "country"); $postal_code = mysql_result($result,0, "postal_code"); $website = mysql_result($result,0, "website"); $email_address = mysql_result($result,0, "email_address"); $comment_by_cg = mysql_result($result,0, "comment_by_cg"); $date_emailed = mysql_result($result,0, "date_emailed"); $mailing_comments = mysql_result($result,0, "mailing_comments"); $telesales_comments = mysql_result($result,0, "telesales_comments"); } ?> Can anyone help me solve this issue? This is the only feature in my project that is left bugged Your quick response is well appreciated. Thank you very much I am having trouble pulling a youtube embedded code from my database. Everything else comes out fine however it just doesnt pull anything out where the embedded code is supposed to be. Any ideas I put the code below. All help would be greatly appreciated, also if anyone is feeling generous and would like to help me some more please message me I have a couple other small questions. Code: [Select] <?php //open database $connect = mysql_connect("Database","name","password") or die("Not connected"); mysql_select_db("database") or die("could not log in"); $query = "SELECT * FROM boox ORDER BY date DESC"; $result = mysql_query($query); // Get the page number, if none is set - it is 0 if( isset($_GET['page']) ) { $page =$_GET['page']; } else { $page = 0; } $resultsPerPage = 15; $num = mysql_num_rows($result); // amount of rows $loops = $page*$resultsPerPage; // starting loops at.. while ($loops < $num && $loops < ($page+1)*$resultsPerPage ) { $link = mysql_result($result,$loops,"link"); // get result from the 'Title' field in the table $username = mysql_result($result,$loops,"username"); // get result from the 'Content' field in the table $messsage = mysql_result($result,$loops,"message"); $date = mysql_result($result,$loops,"date"); if ($pagelimit == 0) { $pagelimit == 1; } if ($pagelimit <= 15) // echo stuff here $loopz = $loops + 1; echo "   </br><align='left'><table width='297' height='900' border='1' align='center' bgcolor='#111'> <tr> <td>$loopz. </br> $message </br> Posted By: $username $date </td> </tr> </table></br><br>"; $count++ ; $pagelimit++; $loops++; } if ( $page!=0 ) // Show 'Previous' link { $page--; $prevpage = ($page + 1); echo "<br><br><br><a href='index.php?page=$page'>Previous $prevpage </a>"; $page++; } if ($loops > 5&&($page+1)*$resultPerPage < $num ) // Show 'next' link { $page++; $nextpage = ($page + 1); echo "<a href='index.php?page=$page'> Next $nextpage</a>"; } ?> Hi the I have a PDF form that generates an XFDF file (form field valies in XML form) and I am passing it to PHP for processing. I am having trouble pulling a specific value from the XML block because of the way that the XML data is generated and organized. Please see a sample of the XML block below: 'test.xml' file: Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve"> <annots/><fields> <field name="Non"> <value>Off</value> </field> <field name="PayRequest"> <value>XYZ</value> </field> From the above XML snip it, once it's sent to PHP, I would like to somehow reference the "PayRequest" field value and retrieve the value "XYZ" and assign it to a variable. I have been kicking around some code that I thought should work, but doesn't appear to. If anyone could offer any insight to get it working that would be greatly appreciated. PHP Code: Code: [Select] $prq_ret = simplexml_load_file('test.xml'); foreach($prq_ret->xpath("//field[@name='PayRequest']") as $item) { $row = simplexml_load_string($item->asXML()); //print $item->value; print $row; } |