php-general Digest 27 Mar 2004 17:38:21 -0000 Issue 2671
Topics (messages 181605 through 181616):
REsource Identifier( PHP_MYSQL)
181605 by: Gimic
181606 by: David Robley
181607 by: Burhan Khalid
181609 by: Gimic
181610 by: Burhan Khalid
Re: simple, but missing something?
181608 by: Burhan Khalid
PHP5RC1 Windows problem
181611 by: Aidan Lister
Re: multi-dim array from text file
181612 by: Burhan Khalid
4.3.5 compiler error
181613 by: Jan Urbansky
Re: Can't to insert data ( via variable ) into MS-SQL
181614 by: Rob Adams
181616 by: edwardspl.ita.org.mo
Re: Local sysadmin DFW needed
181615 by: Don Read
Administrivia:
To subscribe to the digest, e-mail:
[EMAIL PROTECTED]
To unsubscribe from the digest, e-mail:
[EMAIL PROTECTED]
To post to the list, e-mail:
[EMAIL PROTECTED]
----------------------------------------------------------------------
--- Begin Message ---
Hey y'all, I'm having problems trying to get the
MySql_Query() function to return the resource ID when using a $string as the
argument to pass to it. It returns when I hard code the argument but not the
string. Any ideas? here is what the function looks like:
function GetVals() {
$db = mysql_connect("localhost", "root");
$str_Query=("Select * from " . $subject);
mysql_select_db("books",$db);
$result = mysql_query($str_Query);
echo $result;
}
but when I use the query:
$result=mysql_query("Select * from math") it works. Am I setting my string
up wrong? Because it's not running into any errors when I do this.
--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] (Gimic) wrote in
news:[EMAIL PROTECTED]:
> Hey y'all, I'm having problems trying to get the
> MySql_Query() function to return the resource ID when using a $string
> as the argument to pass to it. It returns when I hard code the
> argument but not the string. Any ideas? here is what the function
> looks like:
>
> function GetVals() {
> $db = mysql_connect("localhost", "root");
> $str_Query=("Select * from " . $subject);
>
> mysql_select_db("books",$db);
>
> $result = mysql_query($str_Query);
> echo $result;
>
> }
> but when I use the query:
> $result=mysql_query("Select * from math") it works. Am I setting my
> string up wrong? Because it's not running into any errors when I do
> this.
>
The string $subject is almost certainly empty, as it is not passed as an
argument to the function, nor is it declared global in the function. Try a
little debugging, echoing your query and the output of mysql_error. For
example:
function GetVals() {
$db = mysql_connect("localhost", "root");
$str_Query=("Select * from " . $subject);
mysql_select_db("books",$db);
$result = mysql_query($str_Query);
echo "Query: $str_query<BR>".mysql_error();
echo $result;
}
Then either pass $subject as an argument to the function, or declare it
global within the function.
Lastly, if $string is passed from another script, make sure it is populated
via the GET or POST globals.
--- End Message ---
--- Begin Message ---
Gimic wrote:
Hey y'all, I'm having problems trying to get the
MySql_Query() function to return the resource ID when using a $string as the
argument to pass to it. It returns when I hard code the argument but not the
string. Any ideas? here is what the function looks like:
function GetVals() {
$db = mysql_connect("localhost", "root");
$str_Query=("Select * from " . $subject);
mysql_select_db("books",$db);
$result = mysql_query($str_Query);
echo $result;
}
but when I use the query:
$result=mysql_query("Select * from math") it works. Am I setting my string
up wrong? Because it's not running into any errors when I do this.
First thing, how would you know if it was returning any errors or not?
Try mysql_errno() and mysql_error().
Secondly, I suspect that your "string" is not what you think.
print_r($str_Query); and see what its giving you.
--- End Message ---
--- Begin Message ---
The entire script looks like this:
<?php
if ($_POST["Subject"] != NULL) {
echo "results for " . $_POST["Subject"];
$subject = $_POST["Subject"];
$qry = ("select * from " . $subject);
$sqlQry = (string) $qry;
GetVals();
}
function GetVals() {
$db = mysql_connect("localhost", "root");
mysql_select_db("books",$db);
$result = mysql_query($sqlQry,$db);
echo mysql_errno($db);
echo mysql_error($db);
echo $result;
}
?>
Where the name of the table is stored in the $_POST varible. The string
isn't empty, yet it is empty. It may be a bug... Or do any of you see any
problem with my varible scope? because I don't.
"Gimic" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hey y'all, I'm having problems trying to get the
> MySql_Query() function to return the resource ID when using a $string as
the
> argument to pass to it. It returns when I hard code the argument but not
the
> string. Any ideas? here is what the function looks like:
>
> function GetVals() {
> $db = mysql_connect("localhost", "root");
> $str_Query=("Select * from " . $subject);
>
> mysql_select_db("books",$db);
>
> $result = mysql_query($str_Query);
> echo $result;
>
> }
> but when I use the query:
> $result=mysql_query("Select * from math") it works. Am I setting my
string
> up wrong? Because it's not running into any errors when I do this.
--- End Message ---
--- Begin Message ---
Gimic wrote:
The entire script looks like this:
<?php
if ($_POST["Subject"] != NULL) {
echo "results for " . $_POST["Subject"];
$subject = $_POST["Subject"];
$qry = ("select * from " . $subject);
$sqlQry = (string) $qry;
GetVals();
}
function GetVals() {
$db = mysql_connect("localhost", "root");
mysql_select_db("books",$db);
$result = mysql_query($sqlQry,$db);
echo mysql_errno($db);
echo mysql_error($db);
echo $result;
}
?>
GetVals() has no ide what is $sqlQry because it is out of its scope.
Try this instead
GetVals($sqlQry);
function GetVals($query) {
//Trimmed rest
$result = mysql_query($query,$db);
//Trimmed
}
Please cc: your replies to [EMAIL PROTECTED] so others may also
contribute.
--- End Message ---
--- Begin Message ---
Jas wrote:
Not sure why I am not able to get this to work, but to make my stuff
easier to configure for different environments I am trying to re-code
some of my stuff to work with options from an array.
$cfg['hostname'] = "www.server.com"; // Server domain or ip address
$cfg['username'] = "username"; // Database user name
$cfg['password'] = "password"; // Database password
$cfg['bugemail'] = "[EMAIL PROTECTED]";
The do something like this:
function database_connection() {
@mysql_connect($cfg[hostname],$cfg[username],$cfg[password]);
@mysql_select_database($cfg[database]); }
I think your array isn't in scope here, that's why you can't see the array.
--- End Message ---
--- Begin Message ---
Hi,
Trying to run PHP5RC1 on Apache1.3 I get the following error in my syslog:
Faulting application Apache.exe, version 0.0.0.0, faulting module
php5ts.dll, version 5.0.0.0, fault address 0x0003c773.
... and Apache terminates.
Anyone have a solution?
--- End Message ---
--- Begin Message ---
Larry Pisani wrote:
Hi,
I need to do some text file manipulation of a text file from an html
interface. I have a file with multiple lines where each line has 2 fields
each (a mac address and an associated vlan). Here's an example of rht text
file:
/tmp/TEST:
====================
a1b2.c3d4.e5cc VLAN3
a1b2.c3d4.e5dd VLAN4
a1b2.c3d4.e5ee IS
a1b2.c3d4.e5ff VLAN6
a1b2.c3d4.e5a1 VLAN7
a1b2.c3d4.e5b2 VLAN8
a1b2.c3d4.e5c3 Printer
a1b2.c3d4.e5d4 Guest
a1b2.c3d4.e5e5 IS
a1b2.c3d4.e5f6 VLAN6
a1b2.c3d4.e5a2 VLAN2
a1b2.c3d4.e5a3 VLAN4
====================
Being an admin and not a developer of any kind, I'm having trouble reading
in the file and being able to output specific lines and fields of a php
array.
[ snip ]
Try this
<?php
$infile = "/tmp/TEST";
$contents = file($infile);
if (!$contents) { die("Could not read ".$infile); }
$tmp = array();
$lookup = array();
while(list($num,$line) = each($contents))
{
$tmp = explode(" ",$line);
$lookup[$tmp[0]] = $tmp[1];
}
?>
Now you have an array with the "key" being the mac address, and the
value being your vlan, something like this (actual output of the snippet
above):
Array
(
[a1b2.c3d4.e5cc] => VLAN3
[a1b2.c3d4.e5dd] => VLAN4
)
You can search this array for the mac address, and then output the
associated lan, or you be a bit more on-topic, create a form with the
associated data, like so :
<?php
echo '<table border="0">';
echo '<tr><td colspan="2">VLAN Editor</td></tr>';
while(list($mac,$vlan) = each($lookup))
{
echo '<tr><td>';
echo $mac;
echo '</td><td>';
echo '<input type="text" name="'.$mac.'" value="'.$vlan."' />';
echo '</td></tr>';
}
echo '</table>';
?>
You can add the form bits however you like :)
What I want to eventually do is read in the "records" and fields of this
file, present it as a form, allow admins to modify the second field and
write that back to the text file (while backing up the original file).
In order to preserve your original data, I would suggest you make a
backup of it first (copy the file if you have to).
If you will be doing a lot of read/writes and updates, consider using a
database to store the information.
[ trimmed rest ]
Hope this helps,
Burhan
--- End Message ---
--- Begin Message ---
Hi...
I'd always use following settings to compile every PHP on my machine (SuSE
8.1) without any problems:
./configure --prefix=/usr/share --datadir=/usr/share/php --bindir=/usr/bin -
-libdir=/usr/share --includedir=/usr/include --with-_lib=lib --with-config-f
ile-path=/etc --with-exec-dir=/usr/lib/php/bin --disable-debug --enable-bcma
th --enable-calendar --enable-ctype --enable-dbase --enable-discard-path --e
nable-exif --enable-filepro --enable-force-cgi-redirect --enable-ftp --enabl
e-gd-imgstrttf --enable-gd-native-ttf --enable-inline-optimization --enable-
magic-quotes --enable-mbstr-enc-trans --enable-mbstring --enable-memory-limi
t --enable-safe-mode --enable-shmop --enable-sigchild --enable-sysvsem --ena
ble-sysvshm --enable-track-vars --enable-trans-sid --enable-versioning --ena
ble-wddx --with-bz2 --with-ftp --with-gdbm --with-gettext --with-gmp --with-
imap=no --with-iodbc --with-jpeg-dir=/usr --with-mcal=/usr --with-mysql=/usr
--with-ndbm --with-png-dir=/usr --with-xpm-dir=/usr/X11R6 --with-zlib=yes -
-with-gd=shared --with-openssl --with-mm --with-apxs=/usr/sbin/apxs
Since 4.3.5 I've got a compiler error and I can't fix this problem:
ext/ctype/ctype.lo: file not recognized: File truncated
collect2: ld returned 1 exit status
make: *** [libphp4.la] Error 1
What's wrong?
_______________________
Jan Urbansky
--- End Message ---
--- Begin Message ---
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> Rob Adams wrote:
>
> > <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> > > $str = " INSERT INTO staff (name,job,subject)
> > 1 2 3
> > > VALUES('$name','$job','$date','$subject',)";
> > 1 2 - 3
>
> $date=date('Y-m-d H:i:s');
>
> Any idea for me to fix this kind of problem ?
I guess I wasn't explicit enough. I would start by chaning your insert
statement to:
insert into staff (name, job, date_field, subject) values ... (etc.)
-- Rob
--- End Message ---
--- Begin Message ---
Rob Adams wrote:
> <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> > Rob Adams wrote:
> >
> > > <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > > > $str = " INSERT INTO staff (name,job,subject)
> > > 1 2 3
> > > > VALUES('$name','$job','$date','$subject',)";
> > > 1 2 - 3
> >
> > $date=date('Y-m-d H:i:s');
> >
> > Any idea for me to fix this kind of problem ?
>
> I guess I wasn't explicit enough. I would start by chaning your insert
> statement to:
>
> insert into staff (name, job, date_field, subject) values ... (etc.)
>
> -- Rob
Hello Rob,
Just enable global function of php.ini, then it is ok now !
Thank for your reply !
Edward.
--- End Message ---
--- Begin Message ---
On 26-Mar-2004 Roger Spears wrote:
>>
> I'm going to guess DFW is just south of BFE
>
It just seems like it.
;->
--
Don Read [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to
steal the neighbor's newspaper, that's the time to do it.
--- End Message ---