LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-18-2003, 02:27 PM   #1
jakublgz
Member
 
Registered: Apr 2002
Location: Wood Dale IL
Distribution: redhat, slackware
Posts: 110

Rep: Reputation: 15
Question php+mysql dbconnect


Hello guys. I am new to php and mysql but I Installed both with apache. I am trying to learn php but I got stock on first project. I went follow one of the howto's "GUESTBOOK". I created the input fields, also database in mysql as a root cause It wont let me do it for any other user. Now when tried to proces and sign in my book It gets stock and I gues it doesnt process that part

mysql_connect("localhost", "nobody","password") or
die ("Could not connect to database");
mysql_select_db("guestbook") or
die ("Could not select database");

Cause after you press sign it just show that text like it doesnt recognize it or something.
Well I don't know what doesnt work (((.
mysql> show databases;
+-----------+
| Database |
+-----------+
| guestbook |
| mysql |
| test |
+-----------+
3 rows in set (0.07 sec)

Could please anyone give me a hint?
Thanx a lot.
Jakub.
 
Old 02-18-2003, 02:29 PM   #2
keevitaja
Member
 
Registered: Aug 2002
Location: Estonia
Distribution: XP PRO
Posts: 119

Rep: Reputation: 15
do this:

$db = mysql_connect(put here you stuff) or die(mysql_error());
mysql_select_db(your_db, $db) or die(mysql_error());

it will give some info.
 
Old 02-18-2003, 02:51 PM   #3
jakublgz
Member
 
Registered: Apr 2002
Location: Wood Dale IL
Distribution: redhat, slackware
Posts: 110

Original Poster
Rep: Reputation: 15
hello
now thats what it gives me back
$db = mysql_connect("localhost", "nobody","password") or die(mysql_error());
mysql_select_db("guestbook", $db) or die(mysql_error());

Well when I went to mysql
mysql> use guestbook;
Database changed
mysql> show database;
ERROR 1064: You have an error in your SQL syntax near 'database' at line 1
mysql>
Hmm. I don't know what am I doin wrong. I wrote that database as an root. In that script I see user nobody and password password. WEll I am really newbe to it so have no experience but I would gues that maby php doesnt know about mysql but when I was compiling it I did --with-mysql. how to check that ?
Thank you.
jakub
 
Old 02-18-2003, 03:25 PM   #4
keevitaja
Member
 
Registered: Aug 2002
Location: Estonia
Distribution: XP PRO
Posts: 119

Rep: Reputation: 15
this mysql syntaks error. may you will be so kind and will show us your php code?
 
Old 02-18-2003, 03:32 PM   #5
jakublgz
Member
 
Registered: Apr 2002
Location: Wood Dale IL
Distribution: redhat, slackware
Posts: 110

Original Poster
Rep: Reputation: 15
Hi,
This is for my index.php
<h2> hi, sign my guest book</h2>

<form method=post action="create_entry.php">
<b> Name: </b>
<input type=text size=40 name=name>
<br>
<b> Location </b>
<input type=text size=40 name=location>
<br>
<b>Email:</b>
<input type=text size=40 name=email>
<br>
<b>Home Page Url:</b>
<input type=text size=40 name=url>
<br>
<b>Comments:</b>
<textarea name=comments cols=40 rows=4 wrap=virtual></textarea>
<br>
<input type=submit name=submit value="sign!">
<input type=reset name=reset value="Start Over">
</form>


This is for dbconnect.php
$db = mysql_connect("localhost", "nobody","password") or die(mysql_error());
mysql_select_db("guestbook", $db) or die(mysql_error());




and this is for create_entry.php

<?php
include("dbconnect.php");

if ($submit == "Sign!")
{
$query = "insert into guestbook
(name,location,email,url,comments) values
('$name','$location','$email','$url','$comments')"
;
mysql_query($query) or
die (mysql_error());
?>
<h2>Thanks</h2>
<h2><a href="view.php">View my guest book</a></h2>
<?php
}
else
{
include("index.php");
}
?>



thanx.
 
Old 02-18-2003, 04:09 PM   #6
keevitaja
Member
 
Registered: Aug 2002
Location: Estonia
Distribution: XP PRO
Posts: 119

Rep: Reputation: 15
<?php
include("dbconnect.php");

if ($submit == "Sign!")
{
mysql_query("insert into guestbook values('$name','$location','$email','$url','$comments')", $db) or die (mysql_error());
?>
<h2>Thanks</h2>
<h2><a href="view.php">View my guest book</a></h2>
<?php
}
else
{
include("index.php");
}
?>

this should be correct... if you still get errors, you really need to check out your db connection.
 
Old 02-18-2003, 04:20 PM   #7
jakublgz
Member
 
Registered: Apr 2002
Location: Wood Dale IL
Distribution: redhat, slackware
Posts: 110

Original Poster
Rep: Reputation: 15
hello
Still wont work. What is your feeiling about it? Is that php fault or mysql fault. How to figure out/.?
again its my first time setting it up.
Thank you.
 
Old 02-19-2003, 03:51 AM   #8
keevitaja
Member
 
Registered: Aug 2002
Location: Estonia
Distribution: XP PRO
Posts: 119

Rep: Reputation: 15
can you eshtablish connection with mysql or not? is yes, then what about database... may be it doesnt exist. or you might not have table...
do you know that database and table are two different things? you enter data into table. database contains tables.

Last edited by keevitaja; 02-19-2003 at 03:57 AM.
 
Old 02-19-2003, 10:29 AM   #9
cli_man
Member
 
Registered: Apr 2002
Location: New York, USA
Distribution: Redhat 7.2, 9.0 Slackware 9.1
Posts: 428

Rep: Reputation: 30
It looks like your guestbook does not have any tables, as was said above, if you type in at the mysql prompt:

use guestbook;
show tables;

you can see if you have any tables in your database, if you want, I could email you the source and mysql layout for a simple guestbook I just wrote so you can see how it works.
 
Old 02-19-2003, 08:02 PM   #10
macewan
Senior Member
 
Registered: Jan 2002
Distribution: Ubuntu, Debian
Posts: 1,055
Blog Entries: 1

Rep: Reputation: 45
Quote:
Originally posted by jakublgz

Well when I went to mysql
mysql> use guestbook;
Database changed
mysql> show database;
ERROR 1064: You have an error in your SQL syntax near 'database' at line 1
show databases;
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql-server4.1 and mod php-mysql conflig kernelvn *BSD 0 06-18-2005 12:52 PM
Problem getting PHP to recognize MySQL, Using PHP 4.0 and MySQL 4.0.20 d2army Programming 4 06-27-2004 09:54 PM
php4 mysql, installation, php-pages with mysql info stay empty dnla Linux - Software 2 03-14-2004 03:54 PM
Installing MySQL.4.0.17 and php support for Mysql on RedHat 9.0 Neha Linux - Software 13 12-29-2003 01:06 AM
Apache Mysql Php: mysql with php doesn't work breakerfall Linux - Networking 6 12-27-2003 09:59 PM


All times are GMT -5. The time now is 01:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration