thedevilz Posted May 4, 2009 Share Posted May 4, 2009 Dear all I made a table `Order`(this is the sign above below~ before number 1). Now how can I use this table in PHP like If I want to run a query of Insert so how can i write this table's name?? "INSERT INTO `Order` (COLUMN) VALUES (Values)"; This statement gives error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING Kindly need ur help Regards sK Quote Link to comment https://forums.phpfreaks.com/topic/156753-solved-how-to-use-order-name/ Share on other sites More sharing options...
mikesta707 Posted May 4, 2009 Share Posted May 4, 2009 well.. what you have their is technically right. show us your actual code, it looks like a simple syntax error based on the message you got. probably an extra quote or something Quote Link to comment https://forums.phpfreaks.com/topic/156753-solved-how-to-use-order-name/#findComment-825451 Share on other sites More sharing options...
Mchl Posted May 4, 2009 Share Posted May 4, 2009 This error usually occurs when you use array variables in double quoted ("") strngs. Like: $foo = "SELECT $arr['column'] FROM"; to avoid it you have to use curly braces around the variable $foo = "SELECT {$arr['column']} FROM"; BTW: 'Order' is MySQL's reserved word, and you should try to avoid using it as a table name. Quote Link to comment https://forums.phpfreaks.com/topic/156753-solved-how-to-use-order-name/#findComment-825455 Share on other sites More sharing options...
thedevilz Posted May 4, 2009 Author Share Posted May 4, 2009 This is my script where I am inserting my table <?php $host="localhost"; class class_mysql { var $host = "localhost"; var $into_db_id = ""; var $selectid = ""; var $updateid = ""; var $insertid = ""; var $result = array(); function db_con() { $dbname = "dts_powersaver"; $loginname = "root"; $loginpass = ""; // $dbname = "hajj"; // $loginname = ""; // $loginpass = ""; $dbhost = "localhost"; $db=mysql_connect($host, $loginname, $loginpass) or die("Could not connect!"); mysql_select_db($dbname); return $db; } function into_db($f_n,$l_n,$e,$qn,$mop) { $f_n = mysql_real_escape_string($f_n,$this->db_con()); $l_n = mysql_real_escape_string($l_n,$this->db_con()); $e = mysql_real_escape_string($e,$this->db_con()); $qn = mysql_real_escape_string($qn,$this->db_con()); $counter_file = "./count.dat"; $lines = file($counter_file); $counter = (int) $lines[0]; $counter++; //echo "You're visitor No. $counter."; if(!($fp = fopen($counter_file, "w"))) { die ("Cannot open $counter_file."); } fwrite($fp, $counter); fclose($fp); $q = "SELECT CID FROM Customer WHERE Email='$e'"; $r = mysql_query($q,$this->db_con()); if(mysql_num_rows($r) == 0) { $q = "INSERT INTO Customer(First_Name,Last_Name,Email)VALUES('$f_n','$l_n','$e')"; @mysql_query($q,$this->db_con()); $q = "SELECT CID FROM Customer WHERE email='$e'"; $r = @mysql_query($q,$this->db_con()); } //$row = mysqli_fetch_array($r,MYSQLI_ASSOC); while($row = mysql_fetch_array($r)) $q = "INSERT INTO Order (CID,Prod_Ref,Quantity,Order_Date,Method_of_Pay) VALUES ($row['CID'],$counter,$q,CURDATE(),$mop)"; if($this->into_db_id = mysql_query($q,$this->db_con())) { { return TRUE; } } else { echo $this->getError("Mysql error."); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/156753-solved-how-to-use-order-name/#findComment-825464 Share on other sites More sharing options...
thedevilz Posted May 4, 2009 Author Share Posted May 4, 2009 anyways Thank You so much for your kind concern I am really greatfull to you for your precious time. I have changed the line# 65 $q = "INSERT INTO order_cust (CID,Prod_Ref,Quantity,Order_Date,Method_of_Pay) VALUES ({$row['CID']},$counter,$q,CURDATE(),$mop)"; Thanx again I was doing mistake that I was using reserved keyword. Regards sK Quote Link to comment https://forums.phpfreaks.com/topic/156753-solved-how-to-use-order-name/#findComment-825468 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.