473,660 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Quick two Code questions..

Sorry I am new to PHP. First question, I hate to ask this but is there
an or statement in PHP that I can use in an IF clause? I can't seem to
find the format. Like say '|' or 'or'.

Question: I am trying to do a SQL table insert. OK, no big deal. Well I
am having a problem with this code. I build a data structure
$fields_values and pass it to a function insertIntoDB() to issue the
insert.

The problem is in the actual INSERT Statement. The values for the column
data do not have "" around the Col values. So SQL flags the fields as
wrong. Example:

INSERT INTO `Log` (ipAddress,acti on,groupPageNam e,namePageName, system)
VALUES (127.0.0.1,brow se,Main,HomePag e,Testing new code)

Can some one point me in the right direction on wrapping " around the
data values so it will insert into the table.

$table = 'myTable';

$fields_values = array
(
'ipAddress' =$_SERVER['REMOTE_ADDR'],
'action' =$action,
'groupPageName' =FmtPageName('$ Group', $pagename),
'namePageName' =FmtPageName('$ Name', $pagename);,
'system' =$system
);

insertIntoDB($t able, $fields_values) ;

function insertIntoDB($t able, $fields_values)
{
$fields = implode(array_k eys($fields_val ues), ',');
$values = implode(array_v alues($fields_v alues), ',');
$sqlStatement = 'INSERT INTO `'.$table.'` ('.$fields.') VALUES
('.$values.')';
$res = mysql_query($sq lStatement)OR die(mysql_error ());
return true;
}

--
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Sep 7 '06 #1
2 1161
IchBin wrote:
Sorry I am new to PHP. First question, I hate to ask this but is there
an or statement in PHP that I can use in an IF clause? I can't seem to
find the format. Like say '|' or 'or'.

Question: I am trying to do a SQL table insert. OK, no big deal. Well I
am having a problem with this code. I build a data structure
$fields_values and pass it to a function insertIntoDB() to issue the
insert.

The problem is in the actual INSERT Statement. The values for the column
data do not have "" around the Col values. So SQL flags the fields as
wrong. Example:

INSERT INTO `Log` (ipAddress,acti on,groupPageNam e,namePageName, system)
VALUES (127.0.0.1,brow se,Main,HomePag e,Testing new code)

Can some one point me in the right direction on wrapping " around the
data values so it will insert into the table.

$table = 'myTable';

$fields_values = array
(
'ipAddress' =$_SERVER['REMOTE_ADDR'],
'action' =$action,
'groupPageName' =FmtPageName('$ Group', $pagename),
'namePageName' =FmtPageName('$ Name', $pagename);,
'system' =$system
);

insertIntoDB($t able, $fields_values) ;

function insertIntoDB($t able, $fields_values)
{
$fields = implode(array_k eys($fields_val ues), ',');
$values = implode(array_v alues($fields_v alues), ',');
$sqlStatement = 'INSERT INTO `'.$table.'` ('.$fields.') VALUES
('.$values.')';
$res = mysql_query($sq lStatement)OR die(mysql_error ());
return true;
}
Logical or is copied from C et al. It is '||'. '|' is bit wise or of two
integers. Reference
http://php.benscom.com/manual/en/lan...rs.logical.php

The statement INSERT should look like the following:

INSERT INTO `Log` (ipAddress,acti on,groupPageNam e,namePageName, system)
VALUES ('127.0.0.1','b rowse','Main',' HomePage','Test ing new code')

If, as it appears, all your db columns are either CHAR, VARCHAR, or DATE
then this is easily done by:

$values = "'" . implode(array_v alues($fields_v alues), "','") . "'";

If they are of mixed numeric and the aforementioned types, then your
fields_values assignment statement must be modified as follows for each
CHAR etc. column:

'action' ="'$action'" ,
Sep 7 '06 #2
Bob Stearns wrote:
IchBin wrote:
>Sorry I am new to PHP. First question, I hate to ask this but is there
an or statement in PHP that I can use in an IF clause? I can't seem to
find the format. Like say '|' or 'or'.

Question: I am trying to do a SQL table insert. OK, no big deal. Well
I am having a problem with this code. I build a data structure
$fields_valu es and pass it to a function insertIntoDB() to issue the
insert.

The problem is in the actual INSERT Statement. The values for the
column data do not have "" around the Col values. So SQL flags the
fields as wrong. Example:

INSERT INTO `Log` (ipAddress,acti on,groupPageNam e,namePageName, system)
VALUES (127.0.0.1,brow se,Main,HomePag e,Testing new code)

Can some one point me in the right direction on wrapping " around the
data values so it will insert into the table.

$table = 'myTable';

$fields_valu es = array
(
'ipAddress' =$_SERVER['REMOTE_ADDR'],
'action' =$action,
'groupPageName ' =FmtPageName('$ Group', $pagename),
'namePageNam e' =FmtPageName('$ Name', $pagename);,
'system' =$system
);

insertIntoDB($ table, $fields_values) ;

function insertIntoDB($t able, $fields_values)
{
$fields = implode(array_k eys($fields_val ues), ',');
$values = implode(array_v alues($fields_v alues), ',');
$sqlStatement = 'INSERT INTO `'.$table.'` ('.$fields.') VALUES
('.$values.')' ;
$res = mysql_query($sq lStatement)OR die(mysql_error ());
return true;
}
Logical or is copied from C et al. It is '||'. '|' is bit wise or of two
integers. Reference
http://php.benscom.com/manual/en/lan...rs.logical.php

The statement INSERT should look like the following:

INSERT INTO `Log` (ipAddress,acti on,groupPageNam e,namePageName, system)
VALUES ('127.0.0.1','b rowse','Main',' HomePage','Test ing new code')

If, as it appears, all your db columns are either CHAR, VARCHAR, or DATE
then this is easily done by:

$values = "'" . implode(array_v alues($fields_v alues), "','") . "'";

If they are of mixed numeric and the aforementioned types, then your
fields_values assignment statement must be modified as follows for each
CHAR etc. column:

'action' ="'$action'" ,
Thanks you Bob for your help, all works now.

--
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Sep 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2070
by: Elaine Jackson | last post by:
Two quick newbie questions: 1) Does Python have passing-by-reference? 2) In ordinary parlance, "deep" implies "shallow" but not conversely. In the Python "copy" module (if I understand correctly), the implication goes the other way. Do you find this a nuisance? Peace, EJ
1
1527
by: YT | last post by:
Couple of quick ASP (3.0) Cookie questions: 1/ I'm using a cookie in my asp script to place cookies (within a key) so my code looks like: Response.Cookies( "quoteform" )( "name" ) = Session( "name" ) Response.Cookies( "quoteform" )( "organization" ) = Session( "organization" ) Response.Cookies( "quoteform" )( "address1" ) = Session( "address" ) Response.Cookies( "quoteform" )( "address2" ) = Session( "suite" ) Response.Cookies(...
3
2205
by: Chris Johnson | last post by:
Greetings all: I come across an interesting question (to me anyway) and I do not know the answer. Code/Questions follow: #include <iostream> #if 0 // uncommenting *should* make call ambigous because of // odering deduction of the function signature,
2
4890
by: Daren Hawes | last post by:
Hi I need a quick code example how to get the Session ID from an ASP.NET page in VB. Thx *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
4
1213
by: ryan_s | last post by:
1) My coding experience has all been with Visual Basic 6 (what I learned in school). Now with the whole ".NET" products, can I code using the same syntax (provided that I don't need to use the ".NET" functionality in my apps) as in VB6. I guess the real question is how much of a transition is it to Visual Basic .NET from VB6? 2) When you compile an application into an executable file, do you need to send any supporting files to the...
3
2120
by: Bart Van Hemelen | last post by:
I'm working on a project where the user of a site will receive custom content, depending on a set of parameters. The content will all be contained in UserControls (.ascx), that will be used as webparts on a page. We need to add the webparts dynamically to the site, depending on the status of the user: this involves a personalisation of a travel website, so a user can be "before" a trip, "during" a trip and "after" a trip, and depending...
4
2271
by: Thiengineer | last post by:
Given the following code in C: char *s = {"program","test","load","frame","stack",NULL}; char **p = s + 2; Questions:
4
1275
by: Phil Latio | last post by:
Firstly, is the following code allowed assuming the addContent function expects as single argument? $page->addContent($form = new Form()); Secondly, I've been reading a tutorial and noticed the use of an "&" in front of the word "new" when instantiating a new object. See example below, I just wondered what is it's significance? The code was purely a snippet. $textField1 = &new inputTextObject("blah", "blah", "blah"); Cheers
4
2252
by: tdahsu | last post by:
All, I'd appreciate any help. I've got a list of files in a directory, and I'd like to iterate through that list and process each one. Rather than do that serially, I was thinking I should start five threads and process five files at a time. Is this a good idea? I picked the number five at random... I was thinking that I might check the number of processors and start a multiple of that, but then I remembered KISS and it seemed that...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2759
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.