Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/156753-solved-how-to-use-order-name/
Share on other sites

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.

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.");

    }

  }

}

  ?>

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.