Same ol', same ol... problem. With connecting!
Posted by: sakuraness (---.dsl.bell.ca)
Date: December 13, 2009 05:07AM

Hello! So here it is:

I have a project which requires me to connect and select my database. Am I able to connect? Yes. Am I able to select my database? Of course not! Why?? I keep getting the following error:

Notice: Undefined variable: test in C:\wamp\www\css\connect.php on line 10
fail: No database selected

Line 10 of my code would be:

$sql = mysql_select_db("$test"winking smiley;

apache error log:

[Sat Dec 12 22:57:22 2009] [error] [client 127.0.0.1] PHP Notice: Undefined variable: test in C:\\wamp\\www\\css\\connect.php on line 10
[Sat Dec 12 22:57:22 2009] [error] [client 127.0.0.1] File does not exist: C:/wamp/www/favicon.ico


Yes, I did create a database under the name of test. This is just a test code I created in order to pinpoint the problem. On my other project, where I have a form which (is supposed to) insert the data into the database, the whole thing crashes whenever I press submit. I get that silly windows error stating that the apache HTTP server encountered a problem.

The apache server log:

[Sat Dec 12 22:54:14 2009] [error] [client 127.0.0.1] File does not exist: C:/wamp/www/favicon.ico
[Sat Dec 12 22:54:21 2009] [notice] Parent: child process exited with status 3221225477 -- Restarting.
[Sat Dec 12 22:54:21 2009] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Sat Dec 12 22:54:21 2009] [notice] Server built: Dec 10 2008 00:10:06
[Sat Dec 12 22:54:21 2009] [notice] Parent: Created child process 5356
[Sat Dec 12 22:54:21 2009] [notice] Child 5356: Child process is running
[Sat Dec 12 22:54:21 2009] [notice] Child 5356: Acquired the start mutex.
[Sat Dec 12 22:54:21 2009] [notice] Child 5356: Starting 64 worker threads.
[Sat Dec 12 22:54:21 2009] [notice] Child 5356: Starting thread to listen on port 80.
[Sat Dec 12 22:54:25 2009] [notice] Parent: child process exited with status 3221225477 -- Restarting.
[Sat Dec 12 22:54:26 2009] [notice] Apache/2.2.11 (Win32) PHP/5.3.0 configured -- resuming normal operations
[Sat Dec 12 22:54:26 2009] [notice] Server built: Dec 10 2008 00:10:06
[Sat Dec 12 22:54:26 2009] [notice] Parent: Created child process 4404
[Sat Dec 12 22:54:26 2009] [notice] Child 4404: Child process is running
[Sat Dec 12 22:54:26 2009] [notice] Child 4404: Acquired the start mutex.
[Sat Dec 12 22:54:26 2009] [notice] Child 4404: Starting 64 worker threads.
[Sat Dec 12 22:54:26 2009] [notice] Child 4404: Starting thread to listen on port 80.


So there it is, my flaws bare to the world! What am I doing wrong? Why won't this work! I get error messages even after I upload it onto the server, at least it doesn't crash?

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'chezlien'@'server404.webhostingpad.com' (using password: YES) in /home/chezlien/public_html/insert_ac.php on line 10
You suck, check your info


"You such, check your info" Yes I was getting a bit loopy in the head at that point. Any help?

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: stevenmartin99 (---.b-ras2.blp.dublin.eircom.net)
Date: December 13, 2009 05:59AM

ok heres how to fix this

first error

i preumse is $test

did u declare this anywhere

you have to declare ur variables such as $test=something

otherwise $test = undeclared- error

ifthe DB is called test then remove the $




second error(sorry but this is the only reason possible!)

Access denied for user 'chezlien'@'server404.webhostingpad.com' there is something wrong wiith

chezlien'@'server404.webhostingpad.com or the password in

/home/chezlien/public_html/insert_ac.php

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: sakuraness (---.dsl.bell.ca)
Date: December 14, 2009 04:53AM

Thanks for your reply! You're right my database code wasn't defined, so now that works!
But I'm still getting errors on the form! v_v'

The test form I created still crashes whenever I click submit.

Here is my code (if it'll help, also, I like to comment because I forget easily, don't laugh):

<?php

// Connect to server and select database.
mysql_connect("localhost", "joomla", "joomla"winking smileyor die("check your info"winking smiley;
mysql_select_db("test"winking smileyor die("cannot select DB"winking smiley;

// Get values from form
$name=$_POST['name'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];

// Insert data into mysql
$sql="INSERT INTO test_mysql (name, lastname, email)VALUES('$name', '$lastname', '$email')";
$result=mysql_query($sql);

// if successfully insert data into database, displays message "Successful".

if($result){
echo "Successful";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}

else {
echo "ERROR";
}

// close connection
mysql_close();
?>


*sigh* Did I make another silly mistake?? I'm assuming it's having trouble inserting the information into the database because my test run revealed that it was, indeed, able to connect and select the database...


Carol

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: stevenmartin99 (---.b-ras2.blp.dublin.eircom.net)
Date: December 14, 2009 05:02AM

ur db is called test and the table is called text_mysql?


secondy remove the '' around the variables in the sql line

('$a','$b','$c') = ($a,$b,$c)

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: Alex.h (---.zone4.bethere.co.uk)
Date: December 14, 2009 05:15AM

Change your 'echo "ERROR";' line to:

echo '[', mysql_errno(), ']: ', mysql_error();

as well. Should give you details on exactly why the MySQL code has failed.

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: sakuraness (---.dsl.bell.ca)
Date: December 14, 2009 05:17AM

Okay, I did what you said for the variables. I thought that would solve the problem but oh no! lol too easy...

yes, my db is test and table is test_mysql. Thanks for your help!

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: sakuraness (---.dsl.bell.ca)
Date: December 14, 2009 05:21AM

Alex! I changed the error log as well but I don't get to see it since it just crashes. I get the Windows error popup window stating:

Apache HTTP server has encountered a problem and needs to close.

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: stevenmartin99 (---.b-ras2.blp.dublin.eircom.net)
Date: December 14, 2009 05:22AM

yes can u post upu the errors?
if ur not getting any and no line is in db.. are you filling in the full row? maybe there is 4 columns?

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: stevenmartin99 (---.b-ras2.blp.dublin.eircom.net)
Date: December 14, 2009 05:24AM

oh !- thats a bug



mysql_close();

needs to be

mysql_close($sql);




it doesnt usually but its a bug in php 5.3.0

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: sakuraness (---.dsl.bell.ca)
Date: December 14, 2009 05:32AM

Yay no more crashing!
Still have a problem though... And I'm starting to feel silly with these mistakes in my code... v_v;

[1064]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@yahoo.com)' at line 1
Warning: mysql_close() expects parameter 1 to be resource, string given in C:\wamp\www\css\insert_ac.php on line 30

What syntax error am I making?

Thanks for all the help, although I feel like my problems are starting to stray from those of this forum hehe

Carol

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: sakuraness (---.dsl.bell.ca)
Date: December 14, 2009 05:34AM

Oh and I do have 4 columns in my database... id, name, lastname and email. Id is set to primary, with AI... I dunno if that it relevant..

Carol (getting sad)

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: stevenmartin99 (---.b-ras2.blp.dublin.eircom.net)
Date: December 14, 2009 05:57AM

u need to

chnage

mysql_connect("localhost", "joomla", "joomla"or die("check your info";

to

$link = mysql_connect("localhost", "joomla", "joomla"winking smiley or die("check your info"winking smiley;



add id and '' like so . put the '' around the varibles again lol cos u might have spaces in ur variables or '

$sql="INSERT INTO test_mysql (id, name, lastname, email)VALUES('','$name', '$lastname', '$email')";


and change

mysql_close($sql)

to

mysql_close($link)

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: sakuraness (---.dsl.bell.ca)
Date: December 14, 2009 05:34PM

Okay! So I did everything you said but now I'm getting this error:

you connected

you selected the database

[1064]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'carol', 'trang', 'teh_ness@yahoo.com')' at line 1

I'm assuming it's something really silly at this point *sigh* lol

<?php


// Connect to server and select database.
$link = mysql_connect("localhost", "joomla", "joomla"winking smiley;

if (!$link)
{
die('Could not connect: ' . mysql_error());
}
else {
echo "you connected";
}
$sel= mysql_select_db("test"winking smileyor die("cannot select DB"winking smiley;

// Checking if database was selected
if (!$sel)
{
die('Could not select: ' . mysql_error());
}
else {
echo "you selected the database";
}

// Get values from form
$name=$_POST['name'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];

// Insert data into mysql
$sql="INSERT INTO test_mysql (id, name, lastname, email)VALUES('', ''$name', '$lastname', '$email')";
$result=mysql_query($sql);

// if successfully insert data into database, displays message "Successful".

if($result){
echo "Successfully entered into database";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}

else {
echo '[', mysql_errno(), ']: ', mysql_error();
}

// close connection
mysql_close($link);

?>

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: stevenmartin99 (---.b-ras2.blp.dublin.eircom.net)
Date: December 14, 2009 06:05PM

before $name u have '' instead of just '





also

$sel= mysql_select_db("test"or die("cannot select DB";

// Checking if database was selected
if (!$sel)
{
die('Could not select: ' . mysql_error());
}
else {
echo "you selected the database";
}


you only need

$sel= mysql_select_db("test"or die("cannot select DB";

as if this fails it will die with an error

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: sakuraness (---.dsl.bell.ca)
Date: December 14, 2009 07:18PM

Thanks a bajillion times for your patience and help with my lowly beginners php skills! Now I can finally work on my actual project instead of messing around with this silly code! lol

Wish me luck! (oh gosh... wish me LOTS of luck...lol ^_^)

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: stevenmartin99 (---.b-ras2.blp.dublin.eircom.net)
Date: December 14, 2009 07:35PM

if you need other help add me to msn,

stevenmartin99@hotmail.com

or email me

stevenmartin99@gmail.com

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Similar problem to Carol solved, BUT one more thing ...
Posted by: kaspencer (---.plus.com)
Date: December 25, 2009 12:49AM

Steve,

As you were so kind to Carol maybe you could just tell me why my PHP script doesn't return to the referrering script ... instead the screen goes blank, after the data is inserted ...

I know I should know better, but I have been working with ASP.NET2 for too long and have forgotten how to hand-code ...

Thanks in advance,

Ken. (It's Chrstmas Eve you know ten minutes to Chrstams Day - such dedication here!)

Kenneth Spencer
(SW England, UK)

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: stevenmartin99 (---.b-ras2.blp.dublin.eircom.net)
Date: December 25, 2009 07:56AM

its xmas day now smiling smiley id need to see code. add me to msn or email me with using the details above

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: Same ol', same ol... problem. With connecting!
Posted by: kaspencer (---.plus.com)
Date: December 28, 2009 11:39AM

Steve, thanks so much for responding on Christmas day!! Unfortunately a house full of guests prevented me from escaping to my office over the weekend, so I was unable to answer until now ...

What I have done at least to enable me to make progress with more of my investigation and familiarisation with the platform is to use the following:
CODE: header('Location: index.php'); CODE ENDS.
to return to the calling page.

Of course this is fine when there is only one page calling the PHP script. I do not like using query strings, and so would usually have used Session Variables to pass the calling page name to the script, but I haven't yet established whether or how Session Variables are supported and managed in PHP.

Another little thing is whether the action code in the PHP script could be built-in to the page as a PHP function rather than having the action called as a separate script ... I am sure that I will eventually sort out all these little thingys as I get more used to PHP/MySQL/Apache coding ...

I hope that you had a good Christmas, Steve, and thanks again,

Regards

Ken.

Options: ReplyQuote


Sorry, only registered users may post in this forum.