Here's the working code...
<?
//include ("../lib/db1.php"); // Connect to database
$db_host = 'xxxx';
$db_user = 'xxxx';
$db_pass = 'xxxx';
$db_name = 'xxxx';
$db = mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name,$db);
$sql1 = "INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75')";
$result1 = mysql_query($sql1,$db);
if (!$result1) {
echo("<P>Error performing 3st query: " .
mysql_error() . "</P>");
}
echo $sql1;
echo "<br />";
echo $db_select;
exit();
?>
This works fine either as is or using the include... :-)
9el wrote:
> But the question is PJ, have you got it out of errors yet? :)
>
> www.twitter.com/nine_L <http://www.twitter.com/nine_L>
> www.lenin9l.wordpress.com <http://www.lenin9l.wordpress.com>
> -----------------------------------------------------------------------
> Use FreeOpenSourceSoftwares, Stop piracy, Let the developers live. Get
> a Free CD of Ubuntu mailed to your door without any cost. Visit :
> www.ubuntu.com <http://www.ubuntu.com>
> ----------------------------------------------------------------------
>
>
> 2009/2/27 Ashley Sheridan <[email protected]
> <mailto:[email protected]>>
>
> On Thu, 2009-02-26 at 13:34 -0500, Darryle Steplight wrote:
> > Hi PJ,
> > $db_host = 'biggie';
> > $db_user = 'root';
> > $db_pass = 'gu...@#$';
> > $db_name = 'biblane';
> >
> >
> >
> > Everyone here is trying to help you and that's cool, but EVERYONE on
> > this list may not be so nice. The above credentials is
> definitely the
> > type of information you want to keep private, unless you don't mind
> > people potentially accessing your database tables and doing whatever
> > they like with them.
> >
> > I suggest doing something like
> > $db_host = 'localhost;
> > $db_user = 'foo';
> > $db_pass= ''bar;
> > $db_name =''xxxxxx;
> >
> > if you are going to post it on the list.
> >
> > On Thu, Feb 26, 2009 at 1:22 PM, PJ <[email protected]
> <mailto:[email protected]>> wrote:
> > > Ricardo Dias Marques wrote:
> > >> Hi PJ,
> > >>
> > >> On Thu, Feb 26, 2009 at 17:28, PJ <[email protected]
> <mailto:[email protected]>> wrote:
> > >>
> > >>
> > >>> What is wrond with this file? same identical insert works
> from console
> > >>> but not from this file :-(
> > >>>
> > >>> [snip]
> > >>>
> > >>> <?
> > >>> //include ("lib/db1.php"); // Connect to database
> > >>>
>
> mysql_connect('biggie', 'user', 'password', 'test') or die("Error
> connecting DB".mysql_error());
> > >>> $sql1 = "INSERT INTO example (name, age) VALUES ('Joe Blow', '69')";
>
> $result1 = mysql_query($sql1,$db) or die("<P>Error performing 1st
> query: " .mysql_error() . "</P>");
>
> > >>> ?>
> > >>>
> > >>
> > >> I haven't coded in PHP for a long time, but I think that your problem
> > >> is in this line:
> > >>
> > >> $result1 = mysql_query($sql1,$db);
> > >>
> > >> Up to that point, $db (that should point to a database link
> > >> identifier) is not defined. You probably want to assign the
> > >> "mysql_connect" result to that $db variable.
> > >>
> > >>
> > >> So, I think that you will solve your problem by changing your
> > >> "mysql_connect" line FROM the current form:
> > >>
> > >> mysql_connect('biggie', 'user', 'password', 'test');
> > >>
> > >> .. TO this one:
> > >>
> > >> $db = mysql_connect('biggie', 'user', 'password', 'test');
> > >>
> > >>
> > >> Am I right?
> > > Partly. I had an error in the location of the include. Ashley
> corrected
> > > the rest but it only works with the include. Not as whown below
> > > <?
> > > //include ("../lib/db1.php"); // Connect to database
> > >
> > > $db_host = 'biggie';
> > > $db_user = 'root';
> > > $db_pass = 'gu...@#$';
> > > $db_name = 'biblane';
> > >
> > > $db_connect = mysql_connect($db_host, $db_user, $db_pass);
> > > $db_select = mysql_select_db($db_name, $db_connect);
> > >
> > > $sql1 = "INSERT INTO test (name, age) VALUES ('Arnie Shwartz', '75')";
> > > $result1 = mysql_query($sql1,$db);
> > > if (!$result1) {
> > > echo("<P>Error performing 1st query: " .
> > > mysql_error() . "</P>");
> > > exit();
> > > }
> > > ?>
> > >
> > > --
> > >
> > > Phil Jourdan --- [email protected] <mailto:[email protected]>
> > > http://www.ptahhotep.com
> > > http://www.chiccantine.com
> > >
> > >
> > > --
> > > MySQL General Mailing List
> > > For list archives: http://lists.mysql.com/mysql
> > > To unsubscribe:
> http://lists.mysql.com/[email protected]
> > >
> > >
> >
>
> I agree. I wouldn't trust me at all! ;)
>
>
> Ash
> www.ashleysheridan.co.uk <http://www.ashleysheridan.co.uk>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Phil Jourdan --- [email protected]
http://www.ptahhotep.com
http://www.chiccantine.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php