can you show us the errors????
ome2012
Junior Poster in Training
57 posts since Sep 2012
Reputation Points: 2
Solved Threads: 16
Skill Endorsements: 1
The database connection has nothing to do with his problem. These kind of output errors are often caused by hidden unicode characters in the source script. If mysql_query would crash due to errors, the script stops and nothing after it would be outputted.
pritaeas
Posting Prodigy
9,316 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,467
Skill Endorsements: 86
If you have no password in the connection, your connection will fail. Think of it as logging in to an email account without a password (:)) http://php.net/manual/en/function.mysql-connect.php
@Squidge: If you check the function definition in the link you posted, you will see that all parameters (including the password) are optional. So the connection will not necessarily fail.
pritaeas
Posting Prodigy
9,316 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,467
Skill Endorsements: 86
Always use error code in development:
$link = mysql_connect('localhost', 'root', ''); //either leave off pw or =''
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo "Connected successfully<br />";
mysql_close($link);
$db_selected = mysql_select_db('cart0902', $link);
if (!$db_selected) {
die ('Can\'t use database : ' . mysql_error());
}
echo "db selected fine<br />";
$category = mysql_real_escape_string($_POST['category']) //CLEAN INPUT!!
$sql="INSERT INTO tblcategory (category) VALUES ('$category')";
echo $sql; //you can copy this from the screen and paste into phpmyadmin
$result = mysql_query($sql);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
It's really odd that you get ouptut to the screen with the script stuff. You may have some weird invisible characters in there. You could try creating a new file, typing out the code again and then replacing the old one - no copy/paste.
The phpmyadmin idea is also impt, you'll probably get more info from that.
diafol
Keep Smiling
10,672 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
I assume the following:
1) You've checked that Apache and MySQL server are running.
2) PHP is actually able to run (try echo 'hello world';)
3) You've changed the code to the one suggested in a clean (new) file.
4) You get the echoed INSERT INTO tblcategory (category) VALUES ('newcat') to the screen (where 'newcat' is the new category placed in the form).
5) You've pasted this SQL into phpmyadmin to see if it works.
That right?
diafol
Keep Smiling
10,672 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
OK, the fail on #2 suggests php is the problem. Odd, I can't suggest much without more info. Is this a XAMPP installation?
diafol
Keep Smiling
10,672 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
What about the XAMPP test page? Did it appear OK once installed? Did you follow the security advice?
diafol
Keep Smiling
10,672 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57
Question Answered as of 7 Months Ago by
diafol,
pritaeas,
Squidge
and 2 others