LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   php+mysql dbconnect (https://www.linuxquestions.org/questions/linux-software-2/php-mysql-dbconnect-46012/)

jakublgz 02-18-2003 01:27 PM

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.

keevitaja 02-18-2003 01:29 PM

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.

jakublgz 02-18-2003 01:51 PM

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.
:newbie: jakub

keevitaja 02-18-2003 02:25 PM

this mysql syntaks error. may you will be so kind and will show us your php code?

jakublgz 02-18-2003 02:32 PM

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.

keevitaja 02-18-2003 03:09 PM

<?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.

jakublgz 02-18-2003 03:20 PM

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.

keevitaja 02-19-2003 02:51 AM

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.

cli_man 02-19-2003 09:29 AM

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.

macewan 02-19-2003 07:02 PM

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;


All times are GMT -5. The time now is 10:08 PM.