PHP - Which Line Is It ? (in Mysql Error Message Number 1064)
I’ve just read several manual pages and forum comments on "Error number 1064" but I still don’t understand what’s going on with the problem I'm having now … Also, I'm surprised that the error message mentions two different line numbers (1 and 35).
Here is the error message I get : And here are the contents of my "one_more_visit_to_topic.php" file : <?php include("includes/model/database_searches/see_readings.php"); include("includes/model/database_searches/see_watchings.php"); function one_more_visit_to_topic($user_id,$topic_id) { global $db; $request_string='UPDATE forum_topic '. 'SET topic_vu = topic_vu + 1 WHERE topic_id = :topic'; $query=$db->prepare($request_string); $query->bindValue(':topic',$topic_id,PDO::PARAM_INT); $query->execute(); $query->CloseCursor(); // Remember that topic has been read by user if(!(see_if_user_has_read_topic($user_id,$topic_id))) { $request_string='INSERT INTO forum_read (fr_topic_id,fr_user_id) '. 'VALUES (:topic,:user)'; $query=$db->prepare($request_string); $query->bindValue(':topic',$topic_id,PDO::PARAM_INT); $query->bindValue(':user',$user_id,PDO::PARAM_INT); $query->execute(); $query->CloseCursor(); } // If user has already received a warning by mail, // the "alert" value needs to be toggled in the fw_watch table if(see_if_user_has_been_warned($user_id,$topic_id)) { $request_string='UPDATE forum_read SET fw_alert = :alt '. 'WHERE fw_topic_id = :topic AND fw_user_id= :user)'; $query=$db->prepare($request_string); $query->bindValue(':topic',$topic_id,PDO::PARAM_INT); $query->bindValue(':user',$user_id,PDO::PARAM_INT); $one=(int)1; $query->bindValue(':alt',$one,PDO::PARAM_INT); $query->execute(); $query->CloseCursor(); } return; } ?> Similar TutorialsHello 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 have been pulling my hair out for the lasy 3 hours i am trying to update a MySql table but i cant get it too work, i just keep getting MySql error #1064 - You have an error in your SQL syntax; if i just update 1 field it works fine but if i try to update more than 1 field it dosent work, Help Please! <?php $root = $_SERVER['DOCUMENT_ROOT']; require("$root/include/mysqldb.php"); require("$root/include/incpost.php"); $con = mysql_connect("$dbhost","$dbuser","$dbpass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$dbame", $con); mysql_query("UPDATE Reg_Profile_p SET build='$build' col='$col' size='$size' WHERE uin = '$uinco'"); ?>
Hello everyone,
1 <?php
7 // Create connection
10 // Check connection
14 $firstname = $conn->real_escape_string($_REQUEST['firstname']); 25 $sql2 = "INSERT INTO countries VALUES ('$country')"; 27 $sql3 = "INSERT INTO Contacts (firstname, lastname, address, city, country, phone, email) VALUES ('$firstname', '$lastname', '$address', $city, $country, '$phone_number','$email')";
29 SELECT * FROM cities;
if($conn->query($sql2) === true){
if($conn->query($sql3) === true){ PHP = 5.5.14
MySQL = 5.2.17
I've cloned a mysqli_connect() statement in a 'require' file placed in a non-public access location on the server. It's the same format (and location) currently working fine with another application, EXCEPT i changed the database name to what I need to use for this application, AND added the $con= part on the front end to substitute for the commented out $con= line in the example code I'm modifying to insert data into a new MySQL DB Table.
The dB Table is fine and I have Inserted data via myPHPAdmin with no problems. Only two form variables are in the simple PHP script thus far just to test if it will work before proceeding.
I've used pseudonames for the actual /home/.... location and filename, and am now Baffled about the Line 2 Error Message I'm getting (below the code).
<?php require '/home/myusername/domains/mydomain.com/myclonedrequire.php'; //$con=mysqli_connect("example","uid","pwd","my_db"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // escape variables for security $year = mysqli_real_escape_string($con, $_POST['year']); $callsign = mysqli_real_escape_string($con, $_POST['callsign']); $sql="INSERT INTO `lqplogs` (`year`, `callsign`) VALUES ('$year', '$callsign'); if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "1 record added"; mysqli_close($con); ?>ERROR Message: Warning: Unexpected character in input: '\' (ASCII=92) state=1 in (above file & location) on line 2 There are NO '\' characters in any of my files. Here is the simple Form file code: <?php ?> <html: <head><title></title></head> <body> <form action="insert.php" method="post"> YEAR: <input type="text" name="year"> CALLSIGN: <input type="text" name="callsign"> <input type="submit"> </form> </body> </html> <?php ?>Thanks for any assistance! -FreakingOUT I have a pdo prepared statement that fetches records from mysql database. The records show up on the page. However if there are no records on a page, I get this error message.
"QLSTATE[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 '-10' at line 4"
Here is my statement
$getCategoryId = $_GET['id']; $limit = 10; $offset = ($page - 1) * $limit; $statement = $db->prepare("SELECT records.*, categories.* FROM records LEFT JOIN categories ON records.category_id = categories.category_id WHERE records.category_id = :category_id ORDER BY record_id DESC LIMIT {$limit} OFFSET ".$offset); $statement->bindParam('category_id', $getCategoryId); $statement->execute(); $results = $statement->fetchAll(PDO::FETCH_ASSOC);If I remove try and catch block, it'll tell me exactly which line is giving the issue. So from the above code, the error has to do with "$statement->execute();". This is where the error occurs. As far as I know, the above pdo statement is correct. Can you tell me if something is wrong with it? Edited by helloworld001, 16 December 2014 - 04:14 PM. Hi guys,
I am having a hard time trying to figure out why this gives me an error?
#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 '' at line 10
/** * Baobab (an implementation of Nested Set Model) * * Copyright 2010 Riccardo Attilio Galli <riccardo@sideralis.org> [http://www.sideralis.org] * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * .. note:: * Each occurrence of the word "GENERIC" across this file is meant to be * replaced with the name of the tree (which must be a valid string to use * as SQL table name). */ /* ############################### */ /* ###### TABLES AND VIEWS ####### */ /* ############################### */ CREATE TABLE IF NOT EXISTS GENERIC ( tree_id INTEGER UNSIGNED NOT NULL, id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, lft INTEGER NOT NULL CHECK (lft > 0), rgt INTEGER NOT NULL CHECK (rgt > 1), INDEX(tree_id), INDEX(lft), CONSTRAINT order_okay CHECK (lft < rgt) ) ENGINE INNODB; DROP VIEW IF EXISTS GENERIC_AdjTree; CREATE VIEW GENERIC_AdjTree (tree_id,parent,child,lft) AS SELECT E.tree_id,B.id, E.id, E.lft FROM GENERIC AS E LEFT OUTER JOIN GENERIC AS B ON B.lft = ( SELECT MAX(lft) FROM GENERIC AS S WHERE E.lft > S.lft AND E.lft < S.rgt AND E.tree_id=S.tree_id) AND B.tree_id=E.tree_id ORDER BY lft ASC; /* ##### LIST OF TREE NAMES IN USE ##### */ CREATE TABLE IF NOT EXISTS Baobab_ForestsNames ( name VARCHAR(200) PRIMARY KEY ) ENGINE INNODB DEFAULT CHARSET=utf8; INSERT INTO Baobab_ForestsNames(name) VALUES ('GENERIC') ON DUPLICATE KEY UPDATE name=name; /* ##################################### */ /* ########################### */ /* ###### ERRORS CONTROL ##### */ /* ########################### */ CREATE TABLE IF NOT EXISTS Baobab_Errors ( code INTEGER UNSIGNED NOT NULL PRIMARY KEY, name VARCHAR(50) NOT NULL, msg TINYTEXT NOT NULL, CONSTRAINT unique_codename UNIQUE (name) ) ENGINE INNODB; INSERT INTO Baobab_Errors(code,name,msg) VALUES (1000,'VERSION','1.3.1'), (1100,'ROOT_ERROR','Cannot add or move a node next to root'), (1200,'CHILD_OF_YOURSELF_ERROR','Cannot move a node inside his own subtree'), (1300,'INDEX_OUT_OF_RANGE','The index is out of range'), (1400,'NODE_DOES_NOT_EXIST',"Node doesn't exist"), (1500,'VERSION_NOT_MATCH',"The library and the sql schema have different versions") ON DUPLICATE KEY UPDATE code=code,name=name,msg=msg; DROP FUNCTION IF EXISTS Baobab_getErrCode; CREATE FUNCTION Baobab_getErrCode(x TINYTEXT) RETURNS INT DETERMINISTIC RETURN (SELECT code from Baobab_Errors WHERE name=x); /* ########################## */ /* ######## DROP TREE ####### */ /* ########################## */ DROP PROCEDURE IF EXISTS Baobab_GENERIC_DropTree; CREATE PROCEDURE Baobab_GENERIC_DropTree ( IN node INTEGER UNSIGNED, IN update_numbers INTEGER) LANGUAGE SQL DETERMINISTIC MODIFIES SQL DATA BEGIN DECLARE drop_tree_id INTEGER UNSIGNED; DECLARE drop_id INTEGER UNSIGNED; DECLARE drop_lft INTEGER UNSIGNED; DECLARE drop_rgt INTEGER UNSIGNED; /* declare exit handler for not found rollback; declare exit handler for sqlexception rollback; declare exit handler for sqlwarning rollback; */ /* save the dropped subtree data with a singleton SELECT */ START TRANSACTION; /* save the dropped subtree data with a singleton SELECT */ SELECT tree_id, id, lft, rgt INTO drop_tree_id, drop_id, drop_lft, drop_rgt FROM GENERIC WHERE id = node; /* subtree deletion is easy */ DELETE FROM GENERIC WHERE tree_id=drop_tree_id AND lft BETWEEN drop_lft and drop_rgt; IF update_numbers = 1 THEN /* close up the gap left by the subtree */ UPDATE GENERIC SET lft = CASE WHEN lft > drop_lft THEN lft - (drop_rgt - drop_lft + 1) ELSE lft END, rgt = CASE WHEN rgt > drop_lft THEN rgt - (drop_rgt - drop_lft + 1) ELSE rgt END WHERE tree_id=drop_tree_id AND (lft > drop_lft OR rgt > drop_lft); END IF; COMMIT; END; /* ########################## */ /* ###### APPEND CHILD ###### */ /* ########################## */ /* Add a new child to a parent as last sibling If parent_id is 0, insert a new root node, moving the previous root (if any) as his child. If choosen_tree is 0, use the first available integer as id. If choosen_tree is not present as tree_id in the table, it is used. */ DROP PROCEDURE IF EXISTS Baobab_GENERIC_AppendChild; CREATE PROCEDURE Baobab_GENERIC_AppendChild( IN choosen_tree INTEGER UNSIGNED, IN parent_id INTEGER UNSIGNED, OUT new_id INTEGER UNSIGNED, OUT cur_tree_id INTEGER UNSIGNED) LANGUAGE SQL DETERMINISTIC BEGIN DECLARE num INTEGER UNSIGNED; START TRANSACTION; SET cur_tree_id = IF(choosen_tree > 0, choosen_tree, IFNULL((SELECT MAX(tree_id)+1 FROM GENERIC),1) ); IF parent_id = 0 THEN /* inserting a new root node*/ UPDATE GENERIC SET lft = lft+1, rgt = rgt+1 WHERE tree_id=cur_tree_id; SET num = IFNULL((SELECT MAX(rgt)+1 FROM GENERIC WHERE tree_id=cur_tree_id),2); INSERT INTO GENERIC(tree_id, id, lft, rgt) VALUES (cur_tree_id, NULL, 1, num); ELSE /* append a new node as last right child of his parent */ SET num = (SELECT rgt FROM GENERIC WHERE id = parent_id ); UPDATE GENERIC SET lft = CASE WHEN lft > num THEN lft + 2 ELSE lft END, rgt = CASE WHEN rgt >= num THEN rgt + 2 ELSE rgt END WHERE tree_id=cur_tree_id AND rgt >= num; INSERT INTO GENERIC(tree_id, id, lft, rgt) VALUES (cur_tree_id,NULL, num, (num + 1)); END IF; SELECT LAST_INSERT_ID() INTO new_id; COMMIT; END; /* ############################### */ /* ###### INSERT NODE AFTER ###### */ /* ############################### */ DROP PROCEDURE IF EXISTS Baobab_GENERIC_insertAfter; CREATE PROCEDURE Baobab_GENERIC_insertAfter( IN sibling_id INTEGER UNSIGNED, OUT new_id INTEGER UNSIGNED, OUT error_code INTEGER UNSIGNED) LANGUAGE SQL DETERMINISTIC main:BEGIN IF 1 = (SELECT lft FROM GENERIC WHERE id = sibling_id) THEN BEGIN SELECT Baobab_getErrCode('ROOT_ERROR') INTO error_code; LEAVE main; END; ELSE BEGIN DECLARE lft_sibling INTEGER UNSIGNED; DECLARE choosen_tree INTEGER UNSIGNED; START TRANSACTION; SELECT tree_id,rgt INTO choosen_tree,lft_sibling FROM GENERIC WHERE id = sibling_id; IF ISNULL(lft_sibling) THEN BEGIN SELECT Baobab_getErrCode('NODE_DOES_NOT_EXIST') INTO error_code; LEAVE main; END; END IF; UPDATE GENERIC SET lft = CASE WHEN lft < lft_sibling THEN lft ELSE lft + 2 END, rgt = CASE WHEN rgt < lft_sibling THEN rgt ELSE rgt + 2 END WHERE tree_id=choosen_tree AND rgt > lft_sibling; INSERT INTO GENERIC(tree_id,id,lft,rgt) VALUES (choosen_tree,NULL, (lft_sibling + 1),(lft_sibling + 2)); SELECT LAST_INSERT_ID() INTO new_id; COMMIT; END; END IF; END; /* ################################ */ /* ###### INSERT NODE BEFORE ###### */ /* ################################ */ DROP PROCEDURE IF EXISTS Baobab_GENERIC_insertBefore; CREATE PROCEDURE Baobab_GENERIC_insertBefore( IN sibling_id INTEGER UNSIGNED, OUT new_id INTEGER UNSIGNED, OUT error_code INTEGER UNSIGNED) LANGUAGE SQL DETERMINISTIC main:BEGIN IF 1 = (SELECT lft FROM GENERIC WHERE id = sibling_id) THEN BEGIN SELECT Baobab_getErrCode('ROOT_ERROR') INTO error_code; LEAVE main; END; ELSE BEGIN DECLARE rgt_sibling INTEGER UNSIGNED; DECLARE choosen_tree INTEGER UNSIGNED; START TRANSACTION; SELECT tree_id,lft INTO choosen_tree,rgt_sibling FROM GENERIC WHERE id = sibling_id; IF ISNULL(rgt_sibling) THEN BEGIN SELECT Baobab_getErrCode('NODE_DOES_NOT_EXIST') INTO error_code; LEAVE main; END; END IF; UPDATE IGNORE GENERIC SET lft = CASE WHEN lft < rgt_sibling THEN lft ELSE lft + 2 END, rgt = CASE WHEN rgt < rgt_sibling THEN rgt ELSE rgt + 2 END WHERE tree_id=choosen_tree AND rgt >= rgt_sibling ORDER BY lft DESC; /* order by is meant to avoid uniqueness violation on update */ INSERT INTO GENERIC(tree_id,id,lft,rgt) VALUES (choosen_tree,NULL, rgt_sibling, rgt_sibling + 1); SELECT LAST_INSERT_ID() INTO new_id; COMMIT; END; END IF; END; /* ################################### */ /* ###### INSERT CHILD AT INDEX ###### */ /* ################################### */ /* Add a new child to parent 'parent_id' at index 'index'. index is the new child position, 0 will put the new node as first. index can be negative, where -1 will put the new node before the last one */ DROP PROCEDURE IF EXISTS Baobab_GENERIC_InsertChildAtIndex; CREATE PROCEDURE Baobab_GENERIC_InsertChildAtIndex( IN parent_id INTEGER UNSIGNED, IN idx INTEGER, OUT new_id INTEGER UNSIGNED, OUT error_code INTEGER UNSIGNED) LANGUAGE SQL DETERMINISTIC BEGIN DECLARE nth_child INTEGER UNSIGNED; DECLARE cur_tree_id INTEGER UNSIGNED; SET error_code=0; SET new_id=0; CALL Baobab_GENERIC_getNthChild(parent_id,idx,nth_child,error_code); IF NOT error_code THEN CALL Baobab_GENERIC_insertBefore(nth_child,new_id,error_code); ELSE IF idx = 0 AND error_code = (SELECT Baobab_getErrCode('INDEX_OUT_OF_RANGE')) THEN BEGIN SET error_code = 0; CALL Baobab_GENERIC_AppendChild((SELECT tree_id FROM GENERIC WHERE id = parent_id), parent_id, new_id, cur_tree_id); END; END IF; END IF; END; /* ########################### */ /* ###### GET NTH CHILD ###### */ /* ########################### */ DROP PROCEDURE IF EXISTS Baobab_GENERIC_getNthChild; CREATE PROCEDURE Baobab_GENERIC_getNthChild( IN parent_id INTEGER UNSIGNED, IN idx INTEGER, OUT nth_child INTEGER UNSIGNED, OUT error_code INTEGER UNSIGNED) LANGUAGE SQL DETERMINISTIC main:BEGIN DECLARE num_children INTEGER; SET error_code=0; SELECT COUNT(*) INTO num_children FROM GENERIC_AdjTree WHERE parent = parent_id; IF num_children = 0 OR IF(idx<0,(-idx)-1,idx) >= num_children THEN /* idx is out of range */ BEGIN SELECT Baobab_getErrCode('INDEX_OUT_OF_RANGE') INTO error_code; LEAVE main; END; ELSE SELECT child INTO nth_child FROM GENERIC_AdjTree as t1 WHERE (SELECT count(*) FROM GENERIC_AdjTree as t2 WHERE parent = parent_id AND t2.lft<=t1.lft AND t1.tree_id=t2.tree_id ) = (CASE WHEN idx >= 0 THEN idx+1 ELSE num_children+1+idx END ) LIMIT 1; END IF; END; /* ###################################### */ /* ###### MOVE SUBTREE BEFORE NODE ###### */ /* ###################################### */ DROP PROCEDURE IF EXISTS Baobab_GENERIC_MoveSubtreeBefore; CREATE PROCEDURE Baobab_GENERIC_MoveSubtreeBefore( IN node_id_to_move INTEGER UNSIGNED, IN reference_node INTEGER UNSIGNED, OUT error_code INTEGER UNSIGNED) LANGUAGE SQL DETERMINISTIC main:BEGIN DECLARE node_revised INTEGER UNSIGNED; DECLARE move_as_first_sibling BOOLEAN; DECLARE ref_left INTEGER UNSIGNED; DECLARE ref_node_tree INTEGER UNSIGNED; SET error_code=0; /* 0 means no error */ SET move_as_first_sibling = TRUE; SELECT tree_id,lft INTO ref_node_tree,ref_left FROM GENERIC WHERE id = reference_node; IF ref_left = 1 THEN BEGIN /* cannot move a parent node before or after root */ SELECT Baobab_getErrCode('ROOT_ERROR') INTO error_code; LEAVE main; END; END IF; /* if reference_node is the first child of his parent, set node_revised to the parent id, else set node_revised to NULL */ SET node_revised = ( SELECT id FROM GENERIC WHERE tree_id=ref_node_tree AND lft = -1+ ref_left); IF ISNULL(node_revised) THEN /* if node_revised is NULL we must find the previous sibling */ BEGIN SET node_revised= (SELECT id FROM GENERIC WHERE tree_id=ref_node_tree AND rgt = -1 + ref_left); SET move_as_first_sibling = FALSE; END; END IF; CALL Baobab_GENERIC_MoveSubtree_real( node_id_to_move, node_revised , move_as_first_sibling, error_code ); END; /* ##################################### */ /* ###### MOVE SUBTREE AFTER NODE ###### */ /* ##################################### */ DROP PROCEDURE IF EXISTS Baobab_GENERIC_MoveSubtreeAfter; CREATE PROCEDURE Baobab_GENERIC_MoveSubtreeAfter( IN node_id_to_move INTEGER UNSIGNED, IN reference_node INTEGER UNSIGNED, OUT error_code INTEGER UNSIGNED) LANGUAGE SQL DETERMINISTIC BEGIN SELECT 0 INTO error_code; /* 0 means no error */ CALL Baobab_GENERIC_MoveSubtree_real( node_id_to_move,reference_node,FALSE,error_code ); END; /* ##################################### */ /* ####### MOVE SUBTREE AT INDEX ####### */ /* ##################################### */ DROP PROCEDURE IF EXISTS Baobab_GENERIC_MoveSubtreeAtIndex; CREATE PROCEDURE Baobab_GENERIC_MoveSubtreeAtIndex( IN node_id_to_move INTEGER UNSIGNED, IN parent_id INTEGER UNSIGNED, IN idx INTEGER, OUT error_code INTEGER) LANGUAGE SQL DETERMINISTIC main:BEGIN DECLARE nth_child INTEGER UNSIGNED; DECLARE num_children INTEGER; DECLARE parent_of_node_to_move INTEGER UNSIGNED; DECLARE s_lft INTEGER UNSIGNED; DECLARE current_idx INTEGER; SET error_code=0; SELECT COUNT(*) INTO num_children FROM GENERIC_AdjTree WHERE parent = parent_id; IF idx < 0 THEN SET idx = num_children + idx; ELSEIF idx > 0 THEN BEGIN SELECT parent, lft INTO parent_of_node_to_move, s_lft FROM GENERIC_AdjTree WHERE child = node_id_to_move; IF parent_of_node_to_move = parent_id THEN BEGIN SELECT count(*) INTO current_idx FROM GENERIC_AdjTree WHERE parent = parent_id AND lft < s_lft; IF idx > current_idx THEN SET idx = idx + 1; END IF; END; END IF; END; END IF; SET idx = IF(idx<0,num_children+idx,idx); IF idx = 0 THEN /* moving as first child, special case */ CALL Baobab_GENERIC_MoveSubtree_real(node_id_to_move,parent_id,TRUE,error_code); ELSE BEGIN /* search the node before idx, and we wil move our node after that */ CALL Baobab_GENERIC_getNthChild(parent_id,idx-1,nth_child,error_code); IF NOT error_code THEN CALL Baobab_GENERIC_MoveSubtree_real(node_id_to_move,nth_child,FALSE,error_code); END IF; END; END IF; END; /* ####################################### */ /* ####### MOVE SUBTREE REAL LOGIC #######*/ /* ####################################### */ /* If move_as_first_sibling is FALSE, move node_id_to_move after reference_node, else reference_node is the new father of node_id_to_move */ SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_UNSIGNED_SUBTRACTION'; DROP PROCEDURE IF EXISTS Baobab_GENERIC_MoveSubtree_real; CREATE PROCEDURE Baobab_GENERIC_MoveSubtree_real( IN node_id_to_move INTEGER UNSIGNED, IN reference_node INTEGER UNSIGNED, IN move_as_first_sibling BOOLEAN, OUT error_code INTEGER ) LANGUAGE SQL DETERMINISTIC main:BEGIN DECLARE s_lft INTEGER UNSIGNED; DECLARE s_rgt INTEGER UNSIGNED; DECLARE ref_lft INTEGER UNSIGNED; DECLARE ref_rgt INTEGER UNSIGNED; DECLARE source_node_tree INTEGER UNSIGNED; DECLARE ref_node_tree INTEGER UNSIGNED; DECLARE diff_when_inside_sourcetree BIGINT SIGNED; DECLARE diff_when_next_sourcetree BIGINT SIGNED; DECLARE ext_bound_1 INTEGER UNSIGNED; DECLARE ext_bound_2 INTEGER UNSIGNED; SET error_code=0; START TRANSACTION; /* select tree, left and right of the node to move */ SELECT tree_id,lft, rgt INTO source_node_tree, s_lft, s_rgt FROM GENERIC WHERE id = node_id_to_move; /* select left and right of the reference node If moving as first sibling, ref_lft will become the new lft value of node_id_to_move, (and ref_rgt is unused), else we're saving left and right value of soon to be previous sibling */ SELECT tree_id, IF(move_as_first_sibling,lft+1,lft), rgt INTO ref_node_tree, ref_lft, ref_rgt FROM GENERIC WHERE id = reference_node; IF move_as_first_sibling = TRUE THEN IF s_lft <= ref_lft AND s_rgt >= ref_rgt AND source_node_tree=ref_node_tree THEN /* cannot move a parent node inside his own subtree */ BEGIN SELECT Baobab_getErrCode('CHILD_OF_YOURSELF_ERROR') INTO error_code; LEAVE main; END; ELSE IF s_lft > ref_lft THEN BEGIN SET diff_when_inside_sourcetree = -(s_lft-ref_lft); SET diff_when_next_sourcetree = s_rgt-s_lft+1; SET ext_bound_1 = ref_lft; SET ext_bound_2 = s_lft-1; END; ELSEIF s_lft = ref_lft and source_node_tree = ref_node_tree THEN BEGIN /* we have been asked to move a node to his same position */ LEAVE main; END; ELSE BEGIN SET diff_when_inside_sourcetree = ref_lft-s_rgt-1; SET diff_when_next_sourcetree = -(s_rgt-s_lft+1); SET ext_bound_1 = s_rgt+1; SET ext_bound_2 = ref_lft-1; END; END IF; END IF; ELSE /* moving after an existing child */ IF ref_lft = 1 THEN /* cannot move a node before or after root */ BEGIN SELECT Baobab_getErrCode('ROOT_ERROR') INTO error_code; LEAVE main; END; ELSEIF s_lft < ref_lft AND s_rgt > ref_rgt AND source_node_tree=ref_node_tree THEN /* cannot move a parent node inside his own subtree */ BEGIN SELECT Baobab_getErrCode('CHILD_OF_YOURSELF_ERROR') INTO error_code; LEAVE main; END; ELSE IF s_lft > ref_rgt THEN BEGIN SET diff_when_inside_sourcetree = -(s_lft-ref_rgt-1); SET diff_when_next_sourcetree = s_rgt-s_lft+1; SET ext_bound_1 = ref_rgt+1; SET ext_bound_2 = s_lft-1; END; ELSE BEGIN SET diff_when_inside_sourcetree = ref_rgt-s_rgt; SET diff_when_next_sourcetree = -(s_rgt-s_lft+1); SET ext_bound_1 = s_rgt+1; SET ext_bound_2 = ref_rgt; END; END IF; END IF; END IF; IF source_node_tree <> ref_node_tree THEN BEGIN CALL Baobab_GENERIC_MoveSubtree_Different_Trees( node_id_to_move,reference_node,move_as_first_sibling); LEAVE main; END; END IF; UPDATE GENERIC SET lft = lft + CASE WHEN lft BETWEEN s_lft AND s_rgt THEN diff_when_inside_sourcetree WHEN lft BETWEEN ext_bound_1 AND ext_bound_2 THEN diff_when_next_sourcetree ELSE 0 END , rgt = rgt + CASE WHEN rgt BETWEEN s_lft AND s_rgt THEN diff_when_inside_sourcetree WHEN rgt BETWEEN ext_bound_1 AND ext_bound_2 THEN diff_when_next_sourcetree ELSE 0 END WHERE tree_id=source_node_tree; COMMIT; END; SET sql_mode=@OLD_SQL_MODE; DROP PROCEDURE IF EXISTS Baobab_GENERIC_MoveSubtree_Different_Trees; CREATE PROCEDURE Baobab_GENERIC_MoveSubtree_Different_Trees( IN node_id_to_move INTEGER UNSIGNED, IN reference_node INTEGER UNSIGNED, IN move_as_first_sibling BOOLEAN ) LANGUAGE SQL DETERMINISTIC main:BEGIN DECLARE s_lft INTEGER UNSIGNED; DECLARE s_rgt INTEGER UNSIGNED; DECLARE ref_lft INTEGER UNSIGNED; DECLARE ref_rgt INTEGER UNSIGNED; DECLARE source_node_tree INTEGER UNSIGNED; DECLARE ref_node_tree INTEGER UNSIGNED; START TRANSACTION; /* select tree, left and right of the node to move */ SELECT tree_id,lft, rgt INTO source_node_tree, s_lft, s_rgt FROM GENERIC WHERE id = node_id_to_move; /* The current select will behave differently whether we're moving the node as first sibling or not. If move_as_first_sibling, ref_lft will have the value of the "lft" field of node_id_to_move at end of move (ref_rgt here is discarded) else ref_lft and ref_rgt will have the values of the node before node_id_to_move at end of move */ SELECT tree_id, IF(move_as_first_sibling,lft+1,lft), rgt INTO ref_node_tree, ref_lft, ref_rgt FROM GENERIC WHERE id = reference_node; IF (move_as_first_sibling) THEN BEGIN /* create a gap in the destination tree to hold the subtree */ UPDATE GENERIC SET lft = CASE WHEN lft < ref_lft THEN lft ELSE lft + s_rgt-s_lft+1 END, rgt = CASE WHEN rgt < ref_lft THEN rgt ELSE rgt + s_rgt-s_lft+1 END WHERE tree_id=ref_node_tree AND rgt >= ref_lft; /* move the subtree to the new tree */ UPDATE GENERIC SET lft = ref_lft + (lft-s_lft), rgt = ref_lft + (rgt-s_lft), tree_id = ref_node_tree WHERE tree_id = source_node_tree AND lft >= s_lft AND rgt <= s_rgt; END; ELSE BEGIN /* create a gap in the destination tree to hold the subtree */ UPDATE GENERIC SET lft = CASE WHEN lft < ref_rgt THEN lft ELSE lft + s_rgt-s_lft+1 END, rgt = CASE WHEN rgt <= ref_rgt THEN rgt ELSE rgt + s_rgt-s_lft+1 END WHERE tree_id=ref_node_tree AND rgt > ref_rgt; /* move the subtree to the new tree */ UPDATE GENERIC SET lft = ref_rgt+1 + (lft-s_lft), rgt = ref_rgt+1 + (rgt-s_lft), tree_id = ref_node_tree WHERE tree_id = source_node_tree AND lft >= s_lft AND rgt <= s_rgt; END; END IF; /* close the gap in the source tree */ CALL Baobab_GENERIC_Close_Gaps(source_node_tree); COMMIT; END; /* ########################## */ /* ####### CLOSE GAPS ####### */ /* ########################## */ DROP PROCEDURE IF EXISTS Baobab_GENERIC_Close_Gaps; CREATE PROCEDURE Baobab_GENERIC_Close_Gaps( IN choosen_tree INTEGER UNSIGNED) LANGUAGE SQL DETERMINISTIC BEGIN UPDATE GENERIC SET lft = (SELECT COUNT(*) FROM ( SELECT lft as seq_nbr FROM GENERIC WHERE tree_id=choosen_tree UNION ALL SELECT rgt FROM GENERIC WHERE tree_id=choosen_tree ) AS LftRgt WHERE tree_id=choosen_tree AND seq_nbr <= lft ), rgt = (SELECT COUNT(*) FROM ( SELECT lft as seq_nbr FROM GENERIC WHERE tree_id=choosen_tree UNION ALL SELECT rgt FROM GENERIC WHERE tree_id=choosen_tree ) AS LftRgt WHERE tree_id=choosen_tree AND seq_nbr <= rgt ) WHERE tree_id=choosen_tree; END help - can you tell me why this is giving the following error
#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 'DROP TABLE IF EXISTS `admin`' at line 8
i am trying to import a data file ... first few lines of which are
-- MySQL dump 10.10 -- -- Host: localhost Database: bromleyone -- ------------------------------------------------------ -- Server version 5.0.22-Debian_0ubuntu6.06.10-log /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; /*!40103 SET TIME_ZONE='+00:00' */; /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; use bromleyone -- -- Table structure for table `admin` -- DROP TABLE IF EXISTS `admin`; CREATE TABLE `admin` ( `id` int(11) NOT NULL auto_increment, `username` varchar(30) NOT NULL default '', `password` varchar(30) NOT NULL default '', `name` varchar(40) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; I'm getting the err msg Error . "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 '$sqry' at line 1 " while executing query from php5.3.5 but its working directly in mysql5.5.8 Help? Dear All Good Day, i am new to PHP (a beautiful server side scripting language). i want to send a mail with line by line message i tried with different types like by placing the things in table and using <br /> but the thing is the tags are also visible in the message of the mail. Here is my code: $message1 = "Name :". $_REQUEST['name']."<br />"; $message1 .= "Surname :". $_REQUEST['surname']."<br />"; $message1 .= "Cellphone :". $_REQUEST['mobileno']."<br />"; $message1 .= "Telephone :". $_REQUEST['landno']."<br />"; $message1 .= "Fax :". $_REQUEST['fax']."<br />"; $message1 .= "Company :". $_REQUEST['company']."<br />"; $message1 .= "Email :". $_REQUEST['email']."<br />"; $message1 .= "Country :". $_REQUEST['country']."<br />"; $message1 .= "Enquity :". $_REQUEST['enquiry']."<br />"; $message1 .= "Date&Time :". $date."<br />"; For this code if try to print/echo it it is working fine it is displaying line by line, but using this variable ($message1) in the mail these <br /> are also visible. Can any one guide me to resolve(to remove these tags from the message part) this issue. Thanks in Advance. :confused: 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); } In my shopping cart i want an alert message when the maximum number of 5 for the item has been reached or ask them to delete the item if the press - when the item quantity is at 1.
i have it working in php:
//add to quantity of item if (isset($_POST['itemadd'])){ $additem = $_POST['additem']; $sqladd = "SELECT quantity FROM orders WHERE id = '$additem'"; $query_add = mysqli_query($db_conx, $sqladd); while($row = mysqli_fetch_array($query_add, MYSQLI_ASSOC)){ $itemqty = $row['quantity']; if ($itemqty < 5){ $addqty = $itemqty + 1; $adding = "UPDATE orders SET quantity = '$addqty' WHERE id = '$additem'"; $add_query = mysqli_query($db_conx, $adding); header('Location: http://www.quichlicious.co.uk/cart.php'); //print $additem; exit(); } else { $usemes = "You have reached maximum quantity"; } }But rather than display the message in a div i would like a javascript alert box to pop up, i tried the following code: <script type="text/javascript"> function CheckQtyPlus(){ var qty = '<?php echo $qty; ?>'; alert("message here"+qty); } </script>but i get the same quantity number for every item in the cart, i had this error with the php update but i got round that by querying sql to give me the quantity of an item by the items id. can the same thing be done in javascript / ajax? $qty by the way is referenced earlier in the script to get information for the cart table to display items. thanks Michael I want to validate a form field for a number with two decimals (ie. 894567.29), but my script gives me an error, asking me to correct the entry, Following is a snippet of the script:- elseif($field == "oil_waste_ltr") { if(!preg_match("/^[0-9]{1,10}\.{2}$/",$value) ) { $bad_format[] = $field; } } Hi Guyz, I need to check the variable $itemDescription to see if the client has entered a '1' before the item description(example: 1 table) Reason, is the client would like to add sales tax to all NOn-Food related items of 6.25% This is for a local auction house. It needs to be simple. i,e. Don't wanna add any more form fields. Just let the user type the number 1 before all items that need to be taxed. Here's my code: Code: [Select] <?php ob_start(); ?> <link rel="stylesheet" href="style.css" type="text/css"> <style type="text/css"> </style> </head> <?PHP session_start(); ob_start(); # Config settings below # Change these to whatever you want :) ############################# $cellsPerRow = '6'; ############################# include('connect.php'); // These queries get the amount of bidders that are in the database $getAllBidders = mysql_query("SELECT `id` FROM bidders"); $totalBidders = mysql_num_rows($getAllBidders); // This section is to check if the Add New Item form has been submitted if($_POST['addNewItem']) { // Retrieve Query Strings from URL $itemDescription = $_POST['itemDescription']; $itemPrice = $_POST['itemPrice']; $winningBidder = $_POST['winningBidder']; $totalDeals = $_POST['totalDeals']; $totalPrice = ($totalDeals*$itemPrice); // Check the submitted data and make sure all is correct if(!$itemDescription) { $message = 'You must enter an Item Description.'; } else if(!$itemPrice) { $message = 'You must enter an Item Price.'; } else if(!$winningBidder) { $message = 'You must enter a Winning Bidder ID.'; } else if(!$totalDeals) { $message = 'You must enter the amount of Deals.'; } else if(!is_numeric($winningBidder)) { $message = 'The Winning Bidder ID can only be numbers.'; } else { // Check to see if the bidder ID already exists $checkBidder = mysql_query("SELECT * FROM bidders WHERE biddersId='$winningBidder' LIMIT 1"); $checkBidder = mysql_fetch_assoc($checkBidder); // If the Bidder ID does not exist, we re-direct to allow us to save the Bidder ID if(!$checkBidder) { header("Location: ?action=confirmListing&iDesc=".$itemDescription."&iPrice=".$itemPrice."&wBidder=".$winningBidder."&tDeals=".$totalDeals.""); } else { // If Bidder ID exists we just insert the transaction accordingly mysql_query("INSERT INTO transactions (`itemDescription`, `itemPrice`, `bidderId`, `itemQty`, `totalPrice`) VALUES ('$itemDescription', '$itemPrice', '$winningBidder', '$totalDeals', '$totalPrice');"); $message1 = 'The transaction has been successfully added.'; mysql_query("SELECT owed From bidders WHERE biddersId='$winningBidder'") or die(mysql_error()); if ($row['owed']==0) { mysql_query("UPDATE bidders SET owed='1' WHERE biddersId='$winningBidder'") or die(mysql_error()); } } } } // This section is to check if the Add Bidder to database form has been submitted if($_POST['confirmBidder']) { $itemDescription = $_POST['itemDescription']; $itemPrice = $_POST['itemPrice']; $winningBidder = $_POST['winningBidder']; $totalDeals = $_POST['totalDeals']; $totalPrice = ($itemPrice*$totalDeals); $addBidder = $_POST['addBidder']; $checkInput= preg_match([1]+*); if ($itemDescription== $checkInput) $itemPrice= $itemPrice * 6.25%; mysql_query("INSERT INTO transactions (`itemDescription`, `itemPrice`, `bidderId`, `itemQty`, `totalPrice`) VALUES ('$itemDescription', '$itemPrice', '$winningBidder', '$totalDeals', '$totalPrice');"); $message1 = 'The transaction has been successfully added.'; if($addBidder == 'Yes') { mysql_query("INSERT INTO bidders (biddersId) VALUES ('$winningBidder');"); $message1 .= '<br> The Bidder ID has also been added.'; mysql_query("SELECT owed From bidders WHERE biddersId='$winningBidder'") or die(mysql_error()); if ($row['owed']==0) { mysql_query("UPDATE bidders SET owed='1' WHERE biddersId='$winningBidder'") or die(mysql_error()); } } if($addBidder == 'No') { $message1 = '<br><font color= "red"> Bidder has NOT been logged.</font>'; } // $itemDescription = ''; // $itemPrice = ''; // $winningBidder = ''; // $totalDeals = ''; // $totalPrice = ''; // $addBidder = ''; } ?> <?PHP // This line of code will check the current task we are doing if($_GET['action'] == 'confirmListing') { $itemDescription = $_GET['iDesc']; $itemPrice = $_GET['iPrice']; $winningBidder = $_GET['wBidder']; $totalDeals = $_GET['tDeals']; ?> <form name="confirmBidder" method="POST" action="?"> <?PHP // This is the hidden data from the previous form // Better than using sessions and GET query ?> <input type="hidden" name="itemDescription" id="itemDescription" value="<?PHP echo $itemDescription;?>"> <input type="hidden" name="itemPrice" id="itemPrice" value="<?PHP echo $itemPrice;?>"> <input type="hidden" name="winningBidder" id="winningBidder" value="<?PHP echo $winningBidder;?>"> <input type="hidden" name="totalDeals" id="totalDeals" value="1"> <table cellpadding="0" cellspacing="1" border="0" style="background: #ffffff; margin: auto;"> <tr> <td colspan="2" class="formHeader"> Add New Auction Item </td> </tr> <tr> <td class="formField"> Add This Bidder? </td> <td class="formValue"> <select name="addBidder" id="addBidder" class="input" style="width: 195px;"> <option value="Yes">Yes</option> <option value="No">No</option></select> </td> </tr> <tr> <td colspan="2" class="formButton"> <input type="submit" name="confirmBidder" id="confirmBidder" value="Confirm Bidder Action?"> <input type="reset" name="reset" id="reset" value="Reset Form"> </td> </tr> </table> </form> <?PHP // If the action is not to confirm a listing then show add item section } else { ?> <?PHP//----- Add New Item Section -----\\?> <?PHP if($message) { echo '<div class="Error">',$message,'</div><div style="height: 10px;"></div>'; } else if($message1) { echo '<div class="Success">',$message1,'</div><div style="height: 10px;"></div>'; } ?> <form name="addNewItem" method="POST" action="?"> <table cellpadding="0" cellspacing="1" border="0" style="background: #ffffff; margin: auto;"> <tr> <td colspan="2" class="formHeader"> Add New Auction Item </td> </tr> <tr> <td class="formField"> Item Description </td> <td class="formValue"> <input type="text" name="itemDescription" class="formText" id="itemDescription" value="<?=$itemDescription;?>" style="width: 195px;"> </td> </tr> <tr> <td class="formField"> Item Price </td> <td class="formValue"> <input type="text" name="itemPrice" class="formText" id="itemPrice" value="<?=$itemPrice;?>" style="width: 195px;"> </td> </tr> <tr> <td class="formField"> Winning Bidder ID </td> <td class="formValue"> <input type="text" name="winningBidder" class="formText" id="winningBidder" style="width: 195px;"> </td> </tr> <tr> <td class="formField"> How Many Deals? </td> <td class="formValue"> <input type="text" name="totalDeals" class="formText" id="totalDeals" value="1" style="width: 195px;"> </td> </tr> <tr> <td colspan="2" class="formButton"> <input type="submit" name="addNewItem" id="addNewItem" value="Add New Auction Item?"> <input type="reset" name="reset" id="reset" value="Reset Form"> </td> </tr> </table> </form> <?PHP//----- Add New Item Section -----\\?> <?PHP } ?> All help appreciated to the fullest... I don`t get it, waht is wrong?! Code: [Select] <?php require_once 'auth.php'; if (!isset($_SESSION['SESS_VERIFY'])) { header("location: access-denied.php"); exit(); } if ($_SESSION['lang'] == 'Ro') { // setare data romania date_default_timezone_set('Europe/Bucharest'); $today = getdate(); $zi = $today['mday']; $luna = $today['mon']; $lunastring = $today['month']; $an = $today['year']; $data = $zi.$luna.$an; $data = (string)$data; $ora = date('H:i:s'); $msg = array(); $err = array(); $luni = array ( 1=>'Ianuarie', 2=>'Februarie', 3=>'Martie', 4=>'Aprilie', 5=>'Mai', 6=>'Iunie', 7=>'Iulie', 8=>'August', 9=>'Septembrie', 10=>'Octobrie', 11=>'Noiembrie', 12=>'Decembrie'); // comun const SQL_ERR = 'SQL statement failed with error: '; const ADD_MODEL = 'ADAUGA UN MODEL NOU'; . .many constants.. . } elseif ($_SESSION['lang'] == 'It') {... Thank you! Code: [Select] <?php if (!isset($_POST['submit'])) { ?> <h2>Todays Special</h2> <p> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <select name="day"> <option value="1">Monday/Wednesday <option value="2">Tuesday/Thursday <option value="3">Friday/Sunday <option value="4">Saturday </select> input type="submit" name="submit" value="Go"> </form> <?php // get form selection $day = $_POST['day']; // check value and select appropriate item switch ($day) { case 1: $special = 'Chicken in oyster sauce'; break; case 2: $special = 'French onion soup'; break; case 3: $special = 'Pork chops with mashed potatoes and green salad'; break; default: $special = 'Fish and chips'; break; } ?> I keep getting an error code when running my php, it states: Parse error: syntax error, unexpected $end in W:\www\blog\login.php on line 33 Line 33 is </html> Code: [Select] <?php mysql_connect ("localhost", "root", ""); mysql_select_db("blog"); ?> <html> <head> <title>Login</title> </head> <body> <?php if(isset($_POST['submit'])){ $name = $_POST['name']; $pass = $_POST['password']; $result = mysql_query("SELECT * FROM users WHERE name='$name' AND pass='$pass'"); $num = mysql_num_rows($result); if($num == 0){ echo "Bad login, go <a href='login.php'>back</a>"; }else{ session_start(); $SESSION ['name'] = $name; header("Location: admin.php"); } ?> <form action='login.php' method='post'> Username: <input type='text' name='name' /><br /> Password: <input type='password' name='password' /><br /> <input type='submit' name='sumbit' value='Login!' /> </form> </body> </html>Can any one advise me whats wrong? This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=344105.0 |