PHP - Undefined Variable Error Message
This is code from a voting script which does work, yet I am getting a notice that the variables inside the array are undefined, here's a showcase:
Code: [Select] // POST BUTTONS inside the table if (isset($_POST['likes'])) $likes = $_POST['likes']; if (isset($_POST['dislikes'])) $dislikes = $_POST['dislikes']; if (isset($_POST['hidden_con_id'])) { $con_id = $_POST['hidden_con_id']; //$favorite = $_POST['favorite']; } $array = array ($likes, $dislikes, $con_id, $user_id); The error message: Code: [Select] Notice: Undefined variable: likes Notice: Undefined variable: dislikes How can I solve this one? Similar TutorialsThis script displays a flyover box in the viewable browser screen, moving the flyover box either up or down to ensure visibility. It functions correctly, however, the line if (new_pos.top != old_pos.top) posts SCRIPT5007: 'undefined' is null or not an object error in Explorer 8 and 9. Any suggestions appreciated. Thanks. var count_login = 0; var count_hook = 0; var timer_nf; var old_pos; var new_pos; var new_top_pos; function flyover_user_disp(user) { timer_nf = setTimeout(function() { showtip(user); }, 600); } function flyover_user_h(user) { clearTimeout(timer_nf); new_pos = $("#"+user).offset(); if (new_pos.top != old_pos.top) { $("#"+user).animate({top: old_pos.top}, 'fast'); } flyover_user_hide(); } function getBodyScrollTop() { return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop); } function showtip(user) { $(".user-profile-popup").hide('fast'); var html = document.documentElement; $("#"+user).show(); var br=document.getElementById(user).getBoundingClientRect(); old_pos = $("#"+user).offset(); new_top_pos = old_pos.top; if (br.bottom > html.clientHeight) { new_top_pos = old_pos.top - $("#"+user).height() - 95; $("#"+user).animate({top: new_top_pos}, 'fast'); } $("#"+user).hide(); $("#"+user).animate({opacity: "show", left: br.left, top: new_top_pos}, 'fast'); } function slide() { if(count_login == parseInt(user_Info.length)-1) { count_login=0; $("#feat_member").html("<h3><span>Featured Member</span></h3>"+user_Info[count_login]); } else { count_login++; $("#feat_member").html("<h3><span>Featured Member</span></h3>"+user_Info[count_login]); } } setInterval("slide()",10000); function chage_hook() { if(count_hook == parseInt(hookup.length)-1) { count_hook = 0; } else { count_hook += 1; } $("#hook_up_alert").html(hookup[count_hook]); } setInterval("chage_hook()",15000); Hi, I am very new to PHP and I am trying to execute the below code but getting these errors : Notice: Undefined variable: mysql_query in C:\wamp\www\process.php on line 16 Fatal error: Function name must be a string in C:\wamp\www\process.php on line 16 Code: <html><body> <?php mysql_connect("localhost","root",""); mysql_select_db("encryption") or die(mysql_error()); $username = $_POST['username']; $password = $_POST['password']; $mysql_query("INSERT INTO login (username,password) VALUES ('$username','$password')") or die(mysql_error()); ?> </body></html> ` $_POST['username'] & $_POST['password'] come from a previous page. I have no problem with that. Please help.. Thanks in advance. I am trying to display some text "THIS IS A TEST" on the html page. I am getting this error: Notice: Undefined variable: text1 in /home/public_html/themes/videos/content.html on line 23
line 23 is this: <div class="test"><font color="#696969" font size="3" face="Arial">HELLO<?php echo $text1;?></font> The php file, related to the html page shows this (partially):
$text1 = "THIS IS A TEST"; $cateogry_id = ''; $videos = array(); if ($page == 'trending') { $title = $lang->trending; $db->where('privacy', 0); $videos = $db->where('time', time() - 172800, '>')->orderBy('views', 'DESC')->get(T_VIDEOS, $limit); } else if ($page == 'latest') { $title = $lang->latest_videos; echo "$text1"; $db->where('privacy', 0); $videos = $db->orderBy('id', 'DESC')->get(T_VIDEOS, $limit); } else if ($page == 'top') { $title = $lang->top_videos; $db->where('privacy', 0); $videos = $db->orderBy('views', 'DESC')->get(T_VIDEOS, $limit); } else if ($page == 'category') { if (!empty($_GET['id'])) { if (in_array($_GET['id'], array_keys($categories))) { $cateogry = PT_Secure($_GET['id']); $title = $categories[$cateogry]; $cateogry_id = "data-category='$cateogry'"; $db->where('privacy', 0); $videos = $db->where('category_id', $cateogry)->orderBy('id', 'DESC')->get(T_VIDEOS, $limit); } else { header("Location: " . PT_Link('404')); exit(); } } } what do I need to correct to remedy the error? Any help is appreciated. Everything seems to be working like it should iam getting Undegined variable Error : return in /Applications/MAMP/htdocs/modernCMS/_class/cms_class.php on line 37. cms_class.php file Code: [Select] <?php class modernCMS { var $host; var $username; var $password; var $db; function connect() { $con = mysql_connect($this->host, $this->username, $this->password) or die(mysql_error()); mysql_select_db($this->db, $con) or die(mysql_error()); } function get_content($id = '') { if($id != ""): $id = mysql_real_escape_string($id); $sql = "SELECT * FROM cms_content WHERE id = '$id'"; $return = '<p><a href="index.php">Go Back To Content</a></p>'; else: $sql = "SELECT * FROM cms_content ORDER BY id DESC"; endif; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) != 0): while($row = mysql_fetch_assoc($res)) { echo '<h1><a href="index.php?id=' . $row['id'] . '">' . $row['title'] . '</a></h1>'; echo '<p>' . $row['body'] . '</p>'; } else: echo '<p>Uh Oh!, this doesn\'t exist!</p>'; endif; echo $return; } } //Class ends here index.php ?> Code: [Select] <?php include '_class/cms_class.php'; $obj = new modernCMS(); $obj->host = 'localhost'; $obj->username = 'root'; $obj->password = 'root'; $obj->db = 'modernCMS'; $obj->connect(); ?> <!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> <link rel="stylesheet" href="style.css" type="text/css" media="screen" title="no title" charset="utf-8"> </head> <body> <div id="page-wrap"> <?php if(isset($_GET['id'])): $obj->get_content($_GET['id']); else: $obj->get_content(); endif; ?> </div> </body> </html> if anyone could help would be great. thanks. After recent updates to a wordpress site (updated non-related plugins, changed theme), the php code snippets are shooting back an error at the end of the feeds -- which were previously working fine for years. no other changes were made.
Notice: Undefined variable: response in /nas/content/live/usafact/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(26) : eval()'d code on line 8
URL: PHP code: function do_post($url, $params) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $result = curl_exec($ch); curl_close($ch); return $response; } echo do_post("https://content.newbenefits.com/Feednocss.aspx", "hash=hDSJYjIb56KfGtxWE0I3OQ&Section=short_b2c"); The plugin developer said to replace $response with $result, but that did not work. Same error shows. Can someone please assist? Hi, I am testing out some simple code while trying out PHP OOP to connect to the MySQL DB. I am getting an undefined variable error, but not sure why. the test code is: <?PHP error_reporting(E_ALL); include('includes/db.php'); $db = new db(); $db->query("SELECT title FROM blog_posts WHERE id = '7'"); if($sql) { while($r = mysql_fetch_array($sql)) { echo $r['title']; } } ?> and the code to connect to the DB is: <?PHP class db { private $hostname; private $username; private $password; private $database; private $connect; private $select_db; public function db() { $this->hostname = ""; $this->username = ""; $this->password = ""; $this->database = ""; } public function open_connection() { try { $this->connect = mysql_connect($this->hostname,$this->username,$this->password); $this->select_db = mysql_select_db($this->database); } catch(exception $e) { return $e; } } public function close_connection() { try { mysql_close($this->connect); } catch(exception $e) { return $e; } } public function query($sql) { try { $this->open_connection(); $sql = mysql_query($sql); } catch(exception $e) { return $e; } $this->close_connection(); return $sql; } } ?> the specific error is... Code: [Select] Undefined variable: sql in E:\DBTest.php on line 9 Hey Everyone. I've been using a piece of code several times before and its worked fine but now (after updating my php version) I get an error. Heres the code: Code: [Select] if(isset($_GET['id']) == TRUE){ if(is_numeric($_GET['id'])==FALSE) { $error = 1; } if($error == 1){ header("Location: " . $config_basedir); } else{ $validentry = $_GET['id']; } } else{ $validentry = 1; } The line with "if($error == 1){" gets flagged with an error saying: Notice: Undefined variable: error in C:\xampp\htdocs\sites\smd\index.php on line 8 I've used the code before with no problems and uploaded to my web server I also have no errors. What did I do wrong. I hope it isn't a seriously stupid error. Thanks in advance. Still new to PHP, trying to get around an error! Scenario is pretty simple, i'm trying to do a sample form validation via php, this is the code, Code: [Select] <?php if($_POST){ $t_name=trim($_POST["name"]); $t_email=trim($_POST["email"]); if($t_name==""){ $n_err=1; } elseif($t_email==""){ $e_err=1; } } ?> then towards the form fields i do this, Code: [Select] <?php if($n_err)echo "Please enter correct name"."</br"; ?> <?php if($e_err)echo "Please enter correct email"."</br>"; ?> But this gives an error Quote Notice: Undefined variable: n_err in C:\wamp\www\php\form\index.php on line 30 As far i see you can use php vars defined in section on others, only var inside function are local in nature if they are not using "global" prefix. Please help me figure out why im getting this error, i know it might be something simple, so kindly help, thanks!
Hi! The file login.php and the config file containing the db connection are in the model folder and the login_view is in view folder. I am trying to make a login form am display some error messages to the user, but I don't get the error messages. Can you help me figure it out? PS: the connection to the db works fine! Thx! LOGIN.PHP <?php //start the session session_start(); foreach (glob("model/*.php") as $filename) { include $filename; } //form defaults $error["alert"]= ""; $error["user"]= ""; $error["pass"]= ""; $input["user"]= ""; $input["pass"]= ""; if(isset($_POST["submit"])) { //process form if($_POST["username"] == "" || $_POST["password"] == ""){ //display errors if($_POST["username"] == ""){$error["user"] = "required";} if($_POST["password"] == ""){$error["pass"] = "required";} $error["alert"] = "Please fill in the required fields"; //get the values for the username and password $input["user"]= $_POST["username"]; $input["pass"]= $_POST["password"]; include("../views/login_view.php"); } }else{ include("../views/login_view.php"); } LOGIN_VIEW.PHP <?php session_start(); foreach (glob("model/*.php") as $filename) { include $filename; } ?> <link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <!--author:starttemplate--> <!--reference site : starttemplate.com--> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="keywords" content="unique login form,leamug login form,boostrap login form,responsive login form,free css html login form,download login form"> <meta name="author" content="leamug"> <title>Unique Login Form | Bootstrap Templates</title> <link href="/styles/style.css" rel="stylesheet" id="style" type="text/css"> <!-- Bootstrap core Library --> <link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!-- Google font --> <link href="https://fonts.googleapis.com/css?family=Dancing+Script" rel="stylesheet"> <!-- Font Awesome--> <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> </head> <body> <!-- Page Content --> <div class="container"> <div class="row"> <div class="col-md-offset-5 col-md-4 text-center"> <h1 class='text-white'>Login Form</h1> <form action ="" method="POST"> <div class="form-login"></br> </br> <?php if($error["alert"] != ''){ echo "<div class='alert'>".$error["alert"]."</div>"; } ?> <div> <input type="text" name ="username" id="userName" class="form-control input-sm chat-input" placeholder="Username" value= "<?php echo $input['user'] ?>" required/> <?php echo $error['user'] ?> </div> </br></br> <input type="text" name ="password" id="userPassword" class="form-control input-sm chat-input" placeholder="Password" value= "<?php echo $input['password'] ?>" required/> <div class="error"> <?php echo $error['pass'] ?> </br></br> <div class="wrapper"> <input type="submit" class="btn btn-primary" value="submit"> </div> </div> </div> </form> </div> </div> </body> </html> Edited October 28, 2020 by Alexa Sorry again , but it seems I still have some problem with my $_GET. Here is the error I get: Notice: Undefined variable: id in /opt/lampp/htdocs/EMC/customer-search.php on line 248 Notice: Undefined index: Page in /opt/lampp/htdocs/EMC/customer-search.php on line 255 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /opt/lampp/htdocs/EMC/customer-search.php on line 302 And my code for second error: Code: [Select] $Per_Page = 2; // Per Page $Page = isset($_GET["Page"]); if (!$_GET["Page"]) { $Page=1; } I'm not really sure what's the problem with my first and third error so I will post the whole code he Code: [Select] <?php require_once("./include/fg_membersite.php"); require_once("./include/membersite_config.php"); $objConnect = mysql_connect("localhost","root","") or die(mysql_error()); $objDB = mysql_select_db("EMC"); $haha = $fgmembersite->UserEmail(); $_SESSION['storedemail']= $haha; $query4 = mysql_query("SELECT * FROM Register WHERE Email= '$haha'"); while ($row4 = mysql_fetch_array($query4)){ $id = $row4['ID']; } mysql_free_result($query4); ?> <html> <body> <form name="frmSearch" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>"> <table width="599" border="1"> <tr> <th>Keyword <input name="txtFirstName" type="text" id="txtFirstName" value="<?= isset($_GET["txtFirstName"]) ;?>"> <input name="txtLastName" type="text" id="txtLastName" value="<?= isset($_GET["txtLastName"]) ;?>"> <input name="txtCell" type="text" id="txtCell" value="<?= isset($_GET["txtCell"]) ;?>"> <? $opselect="SELECT DISTINCT Custgroup FROM UserAddedRecord"; $result = mysql_query ($opselect); while($nt=mysql_fetch_array($result)) { ?> <option><?= $nt[Custgroup]?></option>"; <? } ?> </select> <input type="submit" value="Search"> </tr> </table> </form> <? if (isset($_GET["txtFirstName"]) != "" || isset($_GET["txtLastName"]) != "" || isset($_GET["txtCell"]) != "" || isset($_GET["txtGroup"]) != "") { $objConnect = mysql_connect("localhost","root","") or die(mysql_error()); $objDB = mysql_select_db("EMC"); // Search By Name or Email $strSQL = "SELECT * FROM UserAddedRecord WHERE (FirstName LIKE '%".$_GET["txtFirstName"]."%' and LastName LIKE '%".$_GET["txtLastName"]."%' and Cell LIKE '%".$_GET["txtCell"]."%' and Custgroup LIKE '%".$_GET["txtGroup"]."%')"; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); $Num_Rows = mysql_num_rows($objQuery); $Per_Page = 2; // Per Page $Page = isset($_GET["Page"]); if (!$_GET["Page"]) { $Page=1; } $Prev_Page = $Page-1; $Next_Page = $Page+1; $Page_Start = (($Per_Page*$Page)-$Per_Page); if($Num_Rows<=$Per_Page) { $Num_Pages =1; } else if(($Num_Rows % $Per_Page)==0) { $Num_Pages =($Num_Rows/$Per_Page) ; } else { $Num_Pages =($Num_Rows/$Per_Page)+1; $Num_Pages = (int)$Num_Pages; } $strSQL .=" order by addedrec_ID DESC LIMIT $Page_Start , $Per_Page"; $objQuery = mysql_query($strSQL); ?> <table width="600" border="1"> <tr> <th width="50"> <div align="center">#</div></th> <th width="91"> <div align="center">CustomerID </div></th> <th width="98"> <div align="center">Name </div></th> <th width="198"> <div align="center">Email </div></th> <th width="97"> <div align="center">CountryCode </div></th> <th width="59"> <div align="center">Budget </div></th> <th width="71"> <div align="center">Used </div></th> </tr> <? while($objResult = mysql_fetch_array($objQuery)) { ?> <tr> <td><div align="center"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?=$objResult["addedrec_ID"];?>"></div></td> <td><div align="center"><?=$objResult["addedrec_ID"];?></div></td> <td><?=$objResult["FirstName"];?></td> <td><?=$objResult["LastName"];?></td> <td><div align="center"><?=$objResult["MobileCompany"];?></div></td> <td align="right"><?=$objResult["Cell"];?></td> <td align="right"><?=$objResult["Workphone"];?></td> </tr> <? } ?> </table> <br> Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page : <? if($Prev_Page) { if($_GET["txtFirstName"] == "") { echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtLastName=$_GET[txtLastName]'><< Back</a> "; } else { echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtFirstName=$_GET[txtFirstName]'><< Back</a> "; } } for($i=1; $i<=$Num_Pages; $i++){ if($i != $Page) { echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtFirstName=$_GET[txtFirstName]'>$i</a> ]"; } else { echo "<b> $i </b>"; } } if($Page!=$Num_Pages) { if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "" && $_GET["txtCell"] == "") { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtGroup=$_GET[txtGroup]'>Next>></a> "; } else if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "") { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtCell=$_GET[txtCell]'>Next>></a> "; } else if($_GET["txtFirstName"] == "" ) { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtLastName=$_GET[txtLastName]'>Next>></a> "; } else { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtFirstName=$_GET[txtFirstName]'>Next>></a> "; } } mysql_close($objConnect); } else { $strSQL = "SELECT * FROM UserAddedRecord WHERE user_id='$id'"; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); $Num_Rows = mysql_num_rows($objQuery); $Per_Page = 2; // Per Page $Page = isset($_GET["Page"]); if (!$_GET["Page"]) { $Page=1; } $Prev_Page = $Page-1; $Next_Page = $Page+1; $Page_Start = (($Per_Page*$Page)-$Per_Page); if($Num_Rows<=$Per_Page) { $Num_Pages =1; } else if(($Num_Rows % $Per_Page)==0) { $Num_Pages =($Num_Rows/$Per_Page) ; } else { $Num_Pages =($Num_Rows/$Per_Page)+1; $Num_Pages = (int)$Num_Pages; } $strSQL .=" order by id DESC LIMIT $Page_Start , $Per_Page"; $objQuery = mysql_query($strSQL); ?> <table width="600" border="1"> <tr> <th width="50"> <div align="center">#</div></th> <th width="91"> <div align="center">ID </div></th> <th width="198"> <div align="center">First Name </div></th> <th width="198"> <div align="center">Last Name </div></th> <th width="250"> <div align="center">Mobile Company </div></th> <th width="100"> <div align="center">Cell </div></th> <th width="100"> <div align="center">Workphone </div></th> <th width="100"> <div align="center">Group </div></th> </tr> <? echo "<form name='form1' method='post' action=''>"; while($objResult = mysql_fetch_array($objQuery)) { echo "<tr>"; echo "<td align='center'><input name=\"checkbox[]\" type=\"checkbox\" id=\"checkbox[]\" value=\"$objResult[addedrec_ID]\"></td>"; echo "<td>$objResult[addedrec_ID] </td>"; echo "<td>$objResult[FirstName]</td>"; echo "<td>$objResult[LastName] </td>"; echo "<td>$objResult[MobileCompany] </td>"; echo "<td>$objResult[Cell] </td>"; echo "<td>$objResult[WorkPhone] </td>"; echo "<td>$objResult[Custgroup] </td>"; echo "</tr>"; } echo "<td colspan='7' align='center'><input name=\"delete\" type=\"submit\" id=\"delete\" value=\"Delete\">"; if(isset($_POST['delete'])) // from button name="delete" { $checkbox = $_POST['checkbox']; //from name="checkbox[]" $countCheck = count($_POST['checkbox']); for($d=0;$d<$countCheck;$d++) { $del_id = $checkbox[$d]; $sql = "DELETE from UserAddedRecord where addedrec_ID = $del_id"; $result2=mysql_query($sql); } if($result2) { header('Location: customer-adddata.php'); } else { echo "Error: ".mysql_error(); } } echo "</form>"; ?> </table> <br> Total <?= $Num_Rows;?> Record : <?=$Num_Pages;?> Page : <? if($Prev_Page) { if($_GET["txtFirstName"] == "") { echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtLastName=$_GET[txtLastName]'><< Back</a> "; } else { echo " <a href='$_SERVER[SCRIPT_NAME]?Page=$Prev_Page&txtFirstName=$_GET[txtFirstName]'><< Back</a> "; } } for($i=1; $i<=$Num_Pages; $i++){ if($i != $Page) { echo "[ <a href='$_SERVER[SCRIPT_NAME]?Page=$i&txtFirstName=$_GET[txtFirstName]'>$i</a> ]"; } else { echo "<b> $i </b>"; } } if($Page!=$Num_Pages) { if($_GET["txtFirstName"] == "" && $_GET["txtLastName"] == "") { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtCell=$_GET[txtCell]'>Next>></a> "; } else if($_GET["txtFirstName"] == "" ) { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtLastName=$_GET[txtLastName]'>Next>></a> "; } else { echo " <a href ='$_SERVER[SCRIPT_NAME]?Page=$Next_Page&txtFirstName=$_GET[txtFirstName]'>Next>></a> "; } } mysql_close($objConnect); } ?> </body> </html> And one more error , when I tried to search data and typed some keywords in the textbox , three of the textbox will keep return me value "1" , I really tried to solve the error but still there....can anyone help me for this? Thanks in advanced. Hi i have created a query where i want some columns to be retrieved. i get these 2 errors and i dont understand why.
Notice: Undefined variable: db
Fatal error: Call to a member function query() on a non-object in
this is my query
function get_products_all() { $connect = get_connected_db(); try { $results = $db->query(" ***** error on this line**** SELECT id, product, description, price, picc FROM products ORDER BY id DESC "); } catch (Exception $e) { echo "Data could not be retrieved from the database."; exit; } $result = $results->fetchALL(PDO::FETCH_ASSOC); return $result; }what am i doing wrong? Hello i am new to this forum and coding. I am trying to fix a auto torrent downloading script which is php and curl. I have been stucked with Undefined offset error. Your help will be very appretiated, thanks. Starting download: Mp3-data1 Notice: Undefined variable: temp in /var/www/html/torrents/bgrahul2.php on line 338 Array ( => HTTP/1.1 200 OK Server: Transmission Content-Type: application/json; charset=UTF-8 Date: Wed, 21 Sep 2011 19:58:44 GMT Content-Length: 49 {"arguments":{"torrents":[]},"result":"success"} [1] => ) Marked those lines to bold Quote $result = callTransmission(array("filename" => "/var/www/html/donofwarez/xxx/torrents/$torrentfile", "download-dir" => "/home/Downloads/$title/"), "torrent-add", $arr[1]); callTransmission(array("seedRatioLimit" => 50, "seedRatioMode" => 1), "torrent-set", $arr[1]); /* echo "<pre>"; print_r($result); echo "</pre>"; */ if (preg_match('/"percentDone":[0-9.]+/i', $result[0], $matches)) $temp = str_replace('"id":', "", $matches[0]); // $temp="hlDr1wqu2ONtM3McVGHoVzfrkp2UgUcGwDt66IuxAe0LBkru"; $id[0] = $temp; //***OMG! We need the ids as integers! *** foreach ($id as $key => $value) { $id[$key] = (int) $value; } Hello 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'); } Code: [Select] Notice: Undefined variable: page in C:\Program Files (x86)\EasyPHP5.2.10\www\admin.php on line 119 That line is: <?php session_start(); $_SESSION['prev_page'] = $_SERVER['REQUEST_URI']; if (!session_is_registered('username')) { header("location:login.php"); } ?> <hr> <style type="text/css"> table.gridtable { color:#333333; border-width: 1px; border-color: #666666; border-collapse: collapse; width: 100%; } table.gridtable th { border-width: 1px; padding: 1px; border-style: solid; border-color: #666666; background-color: #dedede; } table.gridtable td { border-width: 1px; padding: 1px; border-style: solid; border-color: #666666; } .valid { border-width: 1px; padding: 1px; border-style: solid; border-color: #666666; background-color: transparent; } </style> </div> <div class="newsJustify"> <script type="text/javascript"> function checkall(delchk) { for (i = 0; i < delchk.length; i++) delchk[i].checked = true; } </script> <script type="text/javascript"> function uncheckall(delchk) { for (i = 0; i < delchk.length; i++) delchk.checked = false; } </script> <script language="JavaScript"> function loadPage(list) { location.href=list.options[list.selectedIndex].value } </script> <?php mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("chat") or die(mysql_error()); if (isset($_POST['del'])) { for ($count = 0; $count < count($_POST["delchk"]); $count++) { $delete = $_POST["delchk"][$count]; $query = "DELETE FROM members_shouts WHERE id = '$delete'"; $result = mysql_query($query); if (!$result) { die("Error deleting accounts! Query: $query<br />Error: " . mysql_error()); } } } $data = mysql_query("SELECT * FROM `members_shouts`") or die(mysql_error()); $rows = mysql_num_rows($data); if (isset($_GET['limit'])) { $page_rows = $_GET["limit"]; if ($page_rows == '') { $page_rows = 5; // no double quotes (int) } elseif ($page_rows == 'all') { $page_rows = $rows; } else { $page_rows = $_GET['limit']; /* validate this */ } if (!isset($_GET['pagenum'])) { $page = 1; } else { $page = (int) $_GET['pagenum']; } } else { $page_rows = 10; } ?> <?php $max_pages = ceil($rows / $page_rows); $last = ceil($rows / $page_rows); $pagenum = ($page && $page > 0 && $page <= $last) ? $page : 1; $max = 'limit ' . ($pagenum - 1) * $page_rows . ',' . $page_rows; $data_p = mysql_query("SELECT * FROM members_shouts $max") or die(mysql_error()); ?> <?php $result = mysql_query("SELECT * FROM members_shouts"); if (mysql_num_rows($result) > 0) { ?> <span style="float: left;margin-left: 2px;"> <form> <select name="file" size="1" onchange="loadPage(this.form.elements[0])" target="_parent._top"> <option value="" <?php if ($page_rows == 0) { echo 'selected'; } ?>>Select Limit</option> <option value="?limit=9" <?php if ($page_rows == 9) { echo 'selected'; } ?>>9</option> <option value="?limit=15" <?php if ($page_rows == 15) { echo 'selected'; } ?>>15</option> <option value="?limit=30" <?php if ($page_rows == 30) { echo 'selected'; } ?>>30</option> <option value="?limit=all" <?php if ($page_rows == 'all') { echo 'selected'; } ?>>All</option> </select> </form> </span> <span style="float: right;margin-top: 2px;margin-right: 2px;"> <center> <?php if ($pagenum == 1) { } else { echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1&limit={$page_rows}'>First</a> "; echo " | "; echo " "; $previous = $pagenum - 1; $current = $pagenum; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous&limit={$page_rows}'>$previous</a> "; echo " | "; } echo "$pagenum"; if ($pagenum == $last || $last == 0) { } else { $next = $pagenum + 1; echo " | "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next&limit={$page_rows}'>$next</a> "; echo " "; echo " | "; echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last&limit={$page_rows}'>Last</a> "; } ?> </center> </span> <style type="text/css"> .clear2 { clear:both; height:0px; overflow:hidden; } </style> <div class="clear2"></div> <hr> <?php echo "<table class=\"gridtable\"> <thead> <tr> <th align=\"center\" scope=\"col\">user</th> <th align=\"center\" scope=\"col\">message</th> <th align=\"center\" scope=\"col\">when</th> <th align=\"center\" scope=\"col\">Delete?</th> </tr> </thead> <tbody>"; echo "<form name = 'myform' action='' method='post'>"; ?> <?php while ($info = mysql_fetch_array($data_p)) { echo "<tr align=\"center\">"; echo "<td class=\"valid\" >" . $info['user'] . "</td>"; echo "<td class=\"valid\" >" . $info['message'] . "</td>"; echo "<td>" . $info['when'] . "</td>"; echo '<td><input type="checkbox" id="delchk" name="delchk[]" value="' . $info['id'] . '" /></td>'; echo "</tr>"; } echo "</tbody>"; echo "</table>"; echo "<hr>"; echo "<input type='submit' name = 'del' value='Delete Selected'></form>"; echo "<input type='button' onclick='checkall(document.myform[\"delchk\"]);' value='Select All'>"; echo "<input type='button' onclick='uncheckall(document.myform[\"delchk\"]);' value='Deselect All'>"; echo "<hr>"; ?> <?php } else { // No rows were found ... echo '<center>No logged accounts.</center><hr>'; } ?> </hr> The line its refferring too is: $pagenum = ($page && $page > 0 && $page <= $last) ? $page : 1;[/QUOTE] in this block: $max_pages = ceil($rows / $page_rows); $last = ceil($rows / $page_rows); $pagenum = ($page && $page > 0 && $page <= $last) ? $page : 1; $max = 'limit ' . ($pagenum - 1) * $page_rows . ',' . $page_rows; $data_p = mysql_query("SELECT * FROM members_shouts $max") or die(mysql_error()); [/i]
First let me explain my code. This is later included in project_status.php] . In project_status.php] , I have included another file project_status_app.php which contains a HTML form.
<?php include 'inc_fn_header_and_menu.php'; function includeFile($file,$variable) { $var = $variable; include($file); } if (isset($_GET['id']) && $_GET['id']!="") { $pid = $_GET['id']; $_SESSION['pidForApproval'] = $_GET['id']; $query = 'SELECT * FROM `profile` WHERE pid ='.'\''.$pid.'\''; $result=mysqli_query($db,$queryToRetrievePP) or die("There are no records to display ... \n" . mysqli_error()); foreach ($result as $row) { $status = $row['status']; } } ...........some PHP and HTML code....... <div id="customerPurchaseApprovalForm"> <?php echo '<p>APPROVAL FOR CUSTOMER PURCHASE</p>'; $discountApprovalStatus = "Granted"; if ($discountApprovalStatus == "Granted") { includeFile("project_status_app.php",$highestannualvalue); } else { //......... } In project_status_app.php I am attempting to retrieve pidForApproval from the $_SESSION array. <?php // put your code here UPDATE `pp` SET `customer_purchase_remarks` = 'hahaha' WHERE `pp`.`id` = 207; if ($_SERVER['REQUEST_METHOD'] == 'POST') { include '../../inc/fastlogin.php'; $sql = "UPDATE pp SET customer_purchase_remarks ='{$_POST['remarkstxt']}' WHERE pp.pid='{$_SESSION['pidForApproval']}'"; $result = mysqli_query ( $fastdb, $sql ) ; if (mysqli_affected_rows($fastdb) != 1) { $_SESSION['err_cpa_rmks'] = "<p>Error while updating WHERE id='{$_SESSION['pidForApproval']}'</p>"; //echo "<p>Error while updating WHERE id='{$_POST['pidForApproval']}'</p>".mysqli_error($fastdb); } else { $_SESSION['suc_cpa_rmks'] = "<p>Records was updated successfully.</p>"; //echo "Records was updated successfully."; } header ("location: project_status.php?id="$_SESSION['pidForApproval']); exit(); } ?> When I load project_status.php, project_status_app.php is supposed to display the form. Once the user fills in the form the and the submit button has been pressed, the UPDATE statement is supposed to run and then it is supposed to navigate back to project_status.php?id=FA142. But the update is failing and the when the project_status.php is loaded back, the url looks like this http://localhost/fast/project_status.php?id= . The id is empty. It is supposed to be something like this http://localhost/fast/project_status.php?id=FA142. With the id being populated at the header ("location: project_status.php?id=".$_SESSION['pidForApproval']);
Missing some information. Hello, I have just upgraded my wampserver and with it MySQL, PHP and PhpMyAdmin versions. And my scripts, which ran normally before, not burst hundreds of undefined variable and undefined index notices. I realize it's "notices", not "errors" but this is quite irritating. I believe it might be due to some upgrade in PHP scripting rules or something but I don't know what. I hope you can help me. The first type of notice is "undefined variable". This function will return the notice if I remove the bold red line, where I define the variable as empty before I use it in the loop. I didn't need to do this before. function statistics($array) { [color=red][b]$list = '';[/b][/color] if(is_array($array)) { foreach($array as $name => $value) { // Rip out the name of the client. $list .= "<li>".$name." - "; // set an integer so we know how many tier2 values we have read. $x = 0; foreach($value as $difference => $sum_total) { // if this is the more than the first tier2 values, use a '+' between the units. $list .= (++$x > 1) ? " + ".$sum_total." ".$difference : $sum_total." ".$difference; } // close the line out. $list .= "</li>"; } } return $list; } To avoid the 10+ like notices on the page I declare them empty before the variable's first occurrence. But this sounds stupid to me. Wasn't this one of PHP's benefits, not to have to declare the variable before using it? I also get about 30+ undefined index notices, e.g. Quote Notice: Undefined index: COMPANY XXX in F:\wamp\www\Project Management\main.php on line 37 Notice: Undefined index: USD in F:\wamp\www\Project Management\main.php on line 37 Notice: Undefined index: USD in F:\wamp\www\Project Management\main.php on line 41 Here are those lines: $income_total = calculate("income"); foreach($income_total as $row) { $clientID = $row['clientID']; $clientname = $row['clientname']; //$client = "<a href=\"index.php?page=Client&do=view&clientID=$clientID\">".$clientname."</a>"; $client = "<a href=\"index.php?page=Project&do=view&sortby=$clientID\">".$clientname."</a>"; $currency = $row['currency']; $client_sum = $row['client_sum']; $year_sum = ''; $year_sum += $client_sum; $income = ''; $income[$client][$currency] += $client_sum; $income_list = statistics($income); $income_all = ''; $income_all[$currency] += $client_sum; } Line 37 is: Quote $income[$client][$currency] = It's the values assigned to $client and to $currency that seem to cause the notice. How do I deal with this? I don't just want to turn error/notice display off, I want to resolve this issue. I am a new developer, trying to figure out what causing a memory error. The code goes through registered appointments and depends on the service ID, I have to free a 45 minutes for another service to be booked. Now, once I book an appointment for any of the services that can have 45 minutes free spot, the website takes forever to load the hours but doesn't show them, instead I get this error A PHP Error was encountered Severity: Error Message: Maximum execution time of 120 seconds exceeded
foreach ($appointments as $appointment) { foreach ($periods as $index => &$period) { $appointment_start = new DateTime($appointment['start_datetime']); $appointment_end = new DateTime($appointment['end_datetime']); if ($appointment_start >= $appointment_end) { continue; } $period_start = new DateTime($date . ' ' . $period['start']); $period_end = new DateTime($date . ' ' . $period['end']); $serviceId=$appointment['id_services']; $color1=1; $color2=2; $color3=3; $color4=4; $color5=5; $color6=6; $color7=7; $color8=8; $color9=9; $color10=10; $color11=11; $color12=12; $color13=13; $color14=14; $color15=15; $color16=16; $color17=17; $color18=18; $color19=19; $period_s=''; $period_e=''; if ($appointment_start <= $period_start && $appointment_end <= $period_end && $appointment_end <= $period_start) { // The appointment does not belong in this time period, so we will not change anything. continue; } else { if ($appointment_start <= $period_start && $appointment_end <= $period_end && $appointment_end >= $period_start) { // The appointment starts before the period and finishes somewhere inside. We will need to break // this period and leave the available part. //open slot for services 45,45,45 if($serviceId == $color1 || $serviceId == $color3 || $serviceId == $color7 || $serviceId == $color9|| $serviceId == $color10 || $serviceId == $color11 || $serviceId == $color12){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } //Open slot for service 45,45,60 else if($serviceId == $color2 || $serviceId == $color8){ $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } // // //Open slot for service 30,45,45 else if($serviceId == $color4 || $serviceId == $color6 ||$serviceId == $color16 || $serviceId == $color18){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } // // //Open slot for service 30,45,60 else if($serviceId == $color5 || $serviceId == $color17){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } // // //Open slot for service 60,45,45 else if($serviceId == $color13 || $serviceId == $color15){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } // // //Open slot for service 60,45,60 else if($serviceId == $color14 ){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['start'] = $appointment_end->format('H:i'); } // //for the rest of services else { $period['start'] = $appointment_end->format('H:i');} } else { if ($appointment_start >= $period_start && $appointment_end < $period_end) { // The appointment is inside the time period, so we will split the period into two new // others. unset($periods[$index]); if($serviceId == $color1 || $serviceId == $color3 || $serviceId == $color7 || $serviceId == $color9|| $serviceId == $color10 || $serviceId == $color11 || $serviceId == $color12){ $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } // //Open slot for service 45,45,60 else if($serviceId == $color2 || $serviceId == $color8){ $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } // // //Open slot for service 30,45,45 else if($serviceId == $color4 || $serviceId == $color6 ||$serviceId == $color16 || $serviceId == $color18){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } // // //Open slot for service 30,45,60 else if($serviceId == $color5 || $serviceId == $color17){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } // // //Open slot for service 60,45,45 else if($serviceId == $color13 || $serviceId == $color15){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } // // //Open slot for service 60,45,60 else if($serviceId == $color14 ){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } //for other services once The code is completely correct else{ $periods[] = [ 'start' => $period_start->format('H:i'), 'end' => $appointment_start->format('H:i') ]; $periods[] = [ 'start' => $appointment_end->format('H:i'), 'end' => $period_end->format('H:i') ]; } } else if ($appointment_start == $period_start && $appointment_end == $period_end) { if($serviceId == $color1 || $serviceId == $color3 || $serviceId == $color7 || $serviceId == $color9|| $serviceId == $color10 || $serviceId == $color11 || $serviceId == $color12){ unset($periods[$index]); $period_s= $appointment_start; $period_s->modify('+45 minutes'); $period_e= $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } //Open slot for service 45,45,60 else if($serviceId == $color2 || $serviceId == $color8){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // // //Open slot for service 30,45,45 else if($serviceId == $color4 || $serviceId == $color6 ||$serviceId == $color16 || $serviceId == $color18){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // // //Open slot for service 30,45,60 else if($serviceId == $color5 || $serviceId == $color17){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // // //Open slot for service 60,45,45 else if($serviceId == $color13 || $serviceId == $color15){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // // //Open slot for service 60,45,60 else if($serviceId == $color14 ){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ];} // //for the rest of services else { unset($periods[$index]);} // The whole period is blocked so remove it from the available periods array. } else { if ($appointment_start >= $period_start && $appointment_end >= $period_start && $appointment_start <= $period_end) { // The appointment starts in the period and finishes out of it. We will need to remove //the time that is taken from the appointment. if($serviceId == $color1 || $serviceId == $color3 || $serviceId == $color7 || $serviceId == $color9|| $serviceId == $color10 || $serviceId == $color11 || $serviceId == $color12){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $period['end'] = $appointment_start->format('H:i'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } //Open slot for service 45,45,60 else if($serviceId == $color2 || $serviceId == $color8){ $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $period['end'] = $appointment_start->format('H:i'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // // //Open slot for service 30,45,45 else if($serviceId == $color4 || $serviceId == $color6 ||$serviceId == $color16 || $serviceId == $color18){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['end'] = $appointment_start->format('H:i'); } // // //Open slot for service 30,45,60 else if($serviceId == $color5 || $serviceId == $color17){ $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['end'] = $appointment_start->format('H:i'); } // // //Open slot for service 60,45,45 else if($serviceId == $color13 || $serviceId == $color15){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['end'] = $appointment_start->format('H:i'); } // // //Open slot for service 60,45,60 else if($serviceId == $color14 ){ $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; $period['end'] = $appointment_start->format('H:i'); } // for the rest of services else{ $period['end'] = $appointment_start->format('H:i'); } } else { if ($appointment_start >= $period_start && $appointment_end >= $period_end && $appointment_start >= $period_end) { // The appointment does not belong in the period so do not change anything. continue; } else { if ($appointment_start <= $period_start && $appointment_end >= $period_end && $appointment_start <= $period_end) { //Open slot for service 45,45,45 if($serviceId == $color1 || $serviceId == $color3 || $serviceId == $color7 || $serviceId == $color9|| $serviceId == $color10 || $serviceId == $color11 || $serviceId == $color12){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } //Open slot for service 45,45,60 else if($serviceId == $color2 || $serviceId == $color8){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+45 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ]; } // //Open slot for service 30,45,45 else if($serviceId == $color4 || $serviceId == $color6 ||$serviceId == $color16 || $serviceId == $color18){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ];} //Open slot for service 30,45,60 else if($serviceId == $color5 || $serviceId == $color17){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+30 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ];} // // //Open slot for service 60,45,45 else if($serviceId == $color13 || $serviceId == $color15){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-45 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ];} // // //Open slot for service 60,45,60 else if($serviceId == $color14 ){ unset($periods[$index]); $period_s= clone $appointment_start; $period_s->modify('+60 minutes'); $period_e= clone $appointment_end; $period_e->modify('-60 minutes'); $periods[] = [ 'start' => $period_s->format('H:i'), 'end' =>$period_e->format('H:i') ];} else{ unset($periods[$index]); } } } } } } } } } return array_values($periods); } Hello all,
Appreciate if you folks could pls. help me understand (and more importantly resolve) this very weird error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 'ASC, purchase_later_flag ASC, shopper1_buy_flag AS' at line 3' in /var/www/index.php:67 Stack trace: #0 /var/www/index.php(67): PDO->query('SELECT shoplist...') #1 {main} thrown in /var/www/index.php on line 67
Everything seems to work fine when/if I use the following SQL query (which can also be seen commented out in my code towards the end of this post) :
$sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id";However, the moment I change my query to the following, which essentially just includes/adds the ORDER BY clause, I receive the error quoted above: $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master ORDER BY purchased_flag ASC, purchase_later_flag ASC, shopper1_buy_flag ASC, shopper2_buy_flag ASC, store_name ASC) WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id";In googling for this error I came across posts that suggested using "ORDER BY FIND_IN_SET()" and "ORDER BY FIELD()"...both of which I tried with no success. Here's the portion of my code which seems to have a problem, and line # 67 is the 3rd from bottom (third last) statement in the code below: <?php /* $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id"; */ $sql = "SELECT shoplist.*, store_master.store_name, item_master.item_name FROM shoplist, store_master, item_master ORDER BY FIND_IN_SET(purchased_flag ASC, purchase_later_flag ASC, shopper1_buy_flag ASC, shopper2_buy_flag ASC, store_name ASC) WHERE shoplist.store_id = store_master.store_id AND shoplist.item_id = item_master.item_id"; $result = $pdo->query($sql); // foreach ($pdo->query($sql) as $row) { foreach ($result as $row) { echo '<tr>'; print '<td><span class="filler-checkbox"><input type="checkbox" name="IDnumber[]" value="' . $row["idnumber"] . '" /></span></td>';Thanks I am using the following code
foreach ($fbdata->data as $post ) { $posts .= '<li>'; $posts .= '<p>' . $post->message . '</p>'; $posts .= date('d-M-y', strtotime($post->created_time)); $posts .= '</li>'; } and if the message propeerty doesn't exist I get the message above. Any ideas on the best way to fix this? I am pretty sure I defined these, by making it something like $blah="blah" and `blah` = ' {$blah}' So why am I getting these errors = Notice: Use of undefined constant petid - assumed 'petid' in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 38 Notice: Use of undefined constant adopter - assumed 'adopter' in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 41 Notice: Undefined variable: fulldate in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 44 Fatal error: Call to undefined function showpet_forum() in /home/vhosts/foggyjungle.6te.net/viewpet_forum.php on line 45 $time = mysql_query("SELECT * FROM `pets_adopted`"); $date = mysql_fetch_array($time); $fulldate = "$date[fulldate]"; $halfdate = "$date[halfdate]"; function check(){ $pid = mysql_real_escape_string($_GET['id']); $result = mysql_query("SELECT * FROM `pets_adopted` WHERE `id` = '{$pid}'"); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $results = mysql_query("SELECT * FROM `pets_list` WHERE `id` = '{$row[petid]}'"); $pet = mysql_fetch_array($results); $results2 = mysql_query("SELECT * FROM `users` WHERE `id` = '{$row[adopter]}'"); $usercc = mysql_fetch_array($results2); There's the snippet. Thank you for any help. I am just really lost. |