Forum Moderators: coopster

Message Too Old, No Replies

connection problem please help

         

Flolondon

9:36 pm on Mar 22, 2006 (gmt 0)

10+ Year Member



<?php
$host = 'localhost';
$user = 'root';
$pass = '';
$database = 'house';

$connection = mysql_connect ("localhost", "root", "")
or die("Could not connect to server");

mysql_select_db("house", $connection) // profile is the name of your DB
or die("Could not select database");

$name = addslashes ($_POST['name']);
$address = addslashes($_POST['address']);
$email = addslashes($_POST['email']);
$telephone = addslashes($_POST['telephone']);
$comments = addslashes($_POST['comments']);
$deliverytime = $_POST['deliverytime'];
$bread = $_POST['bread'];

$query = "INSERT INTO house (name, address, email, telephone, comments, deliverytime, bread)
VALUES ( '$name', '$address', '$email', '$telephone', '$comments', '$deliverytime', '$bread',)";

$result = mysql_query($query) or die ("Could Not Insert Record Into Database.");

mysql_close($connection);

?>

i get the comment, could not insert record into database

jatar_k

9:39 pm on Mar 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



change that from

$result = mysql_query($query) or die ("Could Not Insert Record Into Database.");

to

$result = mysql_query($query) or die ("Could Not Insert Record Into Database: " . mysql_error());

that should give you the error from mysql

Flolondon

9:52 pm on Mar 22, 2006 (gmt 0)

10+ Year Member



Could Not Insert Record Into Database: 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 'Johne, 53 Stewart Street, Street@yahoo, 23432, asdfsdfff, , ,)' at line 2

this is the error it gave me.. please help

jatar_k

9:57 pm on Mar 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



it doesn't look like the code you posted and what is actually trying to interact with your db are the same

this has quotes around values
( '$name', '$address', '$email', '$telephone', '$comments', '$deliverytime', '$bread',)

check the manual that corresponds to your MySQL server version for the right syntax to use near 'Johne, 53 Stewart Street, Street@yahoo, 23432, asdfsdfff, , ,)' at line 2

the above does not and should cause an error

also in the top snippet the trailing comma should be removed

Flolondon

9:58 pm on Mar 22, 2006 (gmt 0)

10+ Year Member



MySQL 3.23 is the version i am using at present

Flolondon

10:04 pm on Mar 22, 2006 (gmt 0)

10+ Year Member




Heo Jatar... so you are saying that the values should have quotes or they should not have quotes? sorry i am bit confused with your answer..

jatar_k

10:08 pm on Mar 22, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



they should have them

Flolondon

10:15 pm on Mar 22, 2006 (gmt 0)

10+ Year Member



OK. THANKS JATAR

Habtom

8:36 am on Mar 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might have not null values for the last null values, otherwise the code looks ok to me.

scriptmasterdel

8:48 am on Mar 23, 2006 (gmt 0)

10+ Year Member



If its still failing then could it be something to do with the comma at the end of the insert values?

( '$name', '$address', '$email', '$telephone', '$comments', '$deliverytime', '$bread',)

to ...

( '$name', '$address', '$email', '$telephone', '$comments', '$deliverytime', '$bread')

If this makes no difference then please let me know

Del

Flolondon

7:14 pm on Mar 23, 2006 (gmt 0)

10+ Year Member



Thanks so much... it has worked... thanks..

Flolondon

7:57 pm on Mar 23, 2006 (gmt 0)

10+ Year Member



Please help. I notice that the last two variables deliverytime and bread were not posted to the database... please help.. what have i done

please note that the last two variables are drop down/select menu

coopster

7:59 pm on Mar 23, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If the rest of the columns were populated then you just don't have data in the variables of the same name there, 'deliverytime' and 'bread'. Have you checked that the <form> variables and the $_POST variables have the same exact-spelled name?

Flolondon

8:06 pm on Mar 23, 2006 (gmt 0)

10+ Year Member



ok i can see what i did wrong.. was used the same name for a table for a variable hence it did not go..

but for one of the variables it has not gone through.. ie deliverytime

Flolondon

8:28 pm on Mar 23, 2006 (gmt 0)

10+ Year Member



ok i can see what else i did wrong as well. Deliverytime must been some kind of php variable or mysql synax variable or so because as soon as I changed deliverytime to delivery... it worked... thanks... all