Forum Moderators: coopster

Message Too Old, No Replies

T_constant_encapsed?

What the hells going on, i see nuttin wrong

         

guvna2004

10:58 am on May 3, 2005 (gmt 0)

10+ Year Member



Heres the script i did, i cant find no faults, ive been through it hundreds of times and cant find nuttin. I suppose im pretty poor as i doing the PHP & MYSQL tutorial.


<?

$username="myusername";
$password="mypassword";
$database="my_db_name";

$first=$_POST['first'];
$last=$_POST['last'];
$phone=$_POST['phone'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$email=$_POST['email'];
$web=$_POST['web'];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Unable to connect to select database");

$query = "INSERT INTO contacts VALUES (",'$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query);

mysql_close();

?>

Blackie

11:06 am on May 3, 2005 (gmt 0)

10+ Year Member



What is the problem? Do you get any error mssages?

guvna2004

11:08 am on May 3, 2005 (gmt 0)

10+ Year Member



Oh yeah, sorry i forgot to put it down, He he. This is the error message i get.

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/guvna2004/domains/example.co.uk/public_html/test/insert.php on line 18

[edited by: jatar_k at 9:04 pm (utc) on May 3, 2005]
[edit reason] generalized url [/edit]

Blackie

11:35 am on May 3, 2005 (gmt 0)

10+ Year Member



Here are four changed lines for you to try:

$dbi = mysql_connect(localhost,$username,$password);
mysql_select_db($database, $dbi) or die("Unable to connect to select database");

$query = "INSERT INTO contacts VALUES (",'$first','$last','$phone','$mobile','$fax','$email','$web')";
mysql_query($query, $dbi);

guvna2004

11:40 am on May 3, 2005 (gmt 0)

10+ Year Member



Thanx ill give them a try. Could you just explain what it is im doing as im new to this and i wanna be able to understand waht it is im changing. Cheers mate.

guvna2004

11:47 am on May 3, 2005 (gmt 0)

10+ Year Member



No Joy mate, that dont work. I changed it as you saud but i still get the error on line 17. Go here and check it.

[example.co.uk...]

Fill in some fake info and try it

[edited by: jatar_k at 8:59 pm (utc) on May 3, 2005]
[edit reason] generalized url [/edit]

Blackie

11:58 am on May 3, 2005 (gmt 0)

10+ Year Member



Going into meeting, will revert back later on...

Blackie

12:02 pm on May 3, 2005 (gmt 0)

10+ Year Member



You have a simple one here...
change " to ''
in the first value
$query = "INSERT INTO contacts VALUES (",'$first','$last','$phone','$mobile','$fax','$email','$web')";

guvna2004

12:12 pm on May 3, 2005 (gmt 0)

10+ Year Member



Lol, i did wonder why there were qoteation marks in a bracket. Good problem solving tho, im new to MYSQL and PHP but im understanding it easy now. Its been 5 years ive been trying to learn databases. A mate who mooved into my flat is a wizz at it and he disscussed databases and PHP with me and told me how to learn, im definatly loving it.

Blackie

12:56 pm on May 3, 2005 (gmt 0)

10+ Year Member



I would say the more you learn the more you love. :-)
Keep up!

Blackie

1:10 pm on May 3, 2005 (gmt 0)

10+ Year Member



One more tip.

As long as those variables have the same name as the form input fields:
$first=$_POST['first'];
$last=$_POST['last'];
$phone=$_POST['phone'];
$mobile=$_POST['mobile'];
$fax=$_POST['fax'];
$email=$_POST['email'];
$web=$_POST['web'];

you can skip these lines. PHP-script knows the names of all input fields from the html page you do POST from. And variables $first, $last etc will be accesible automatically.