PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
aalbright
Forum Newbie
Posts: 6 Joined: Sun Feb 15, 2009 8:32 pm
Post
by aalbright » Sun Mar 15, 2009 11:36 am
Code: Select all
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 25
Code: Select all
<?php
include ('config.php');
//sets date and time variables
$last = gmdate("Y-m-d");
$time = gmdate("H:i", time() + $zone);
//make the connection to the database
$connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error());
$db = @mysql_select_db($db_name,$connection)or die(mysql_error());
//build and issue the query
[color=#FF0000]$sql = "INSERT INTO messages VALUES ('$_SESSION[user_name]', '$time', '$date', '$_REQUEST['toemail']', '$_REQUEST['fromemail'], '$_REQUEST['subject']', '$_REQUEST['message']);[/color]
$res = mysql_query($mysql, $sql);
?>
Could anyone tell me what is wrong with this code? I'm new to php and mysql, so it may be an obvious error. The red line is line 25.
jh_1981
Forum Newbie
Posts: 22 Joined: Fri Jan 30, 2009 6:21 pm
Post
by jh_1981 » Sun Mar 15, 2009 11:42 am
$_SESSION[user_name] etc. need concat like this "".$_SESSION[user_name].""
aalbright
Forum Newbie
Posts: 6 Joined: Sun Feb 15, 2009 8:32 pm
Post
by aalbright » Sun Mar 15, 2009 11:48 am
Parse error: syntax error, unexpected T_VARIABLE in /homepages/28/d212747455/htdocs/Sender/contact.php on line 25
Code: Select all
<?php //include config file
include ('config.php');
//sets date and time variables
$last = gmdate("Y-m-d");
$time = gmdate("H:i", time() + $zone);
//make the connection to the database
$connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error());
$db = @mysql_select_db($db_name,$connection)or die(mysql_error());
//build and issue the query
[color=#FF0000]$sql = "INSERT INTO messages VALUES (".$_SESSION[user_name].", "$time", "$date", ".$_REQUEST['toemail'].", ".$_REQUEST['fromemail'].", ".$_REQUEST['subject'].", ".$_REQUEST['message'].");[/color]
$res = mysql_query($mysql, $sql);
?>
Did I do that right? Now, I get a different error.
jcrensha627
Forum Newbie
Posts: 15 Joined: Fri Feb 27, 2009 11:34 pm
Post
by jcrensha627 » Sun Mar 15, 2009 12:59 pm
you could also use this...i use cookies instead of session, i believe there is a small difference.
before insert define $username----
$username = $_COOKIE['loggedin'];
if (!isset($_COOKIE['loggedin'])) die("You are not logged in, <a href=../login.html>click here</a> to login.");
then in your insert, insert -----'$username'
hope this works. im new and have made ALOT of tiny mistakes like this ... forgetting ; or } /{ get used to it.
Benjamin
Site Administrator
Posts: 6935 Joined: Sun May 19, 2002 10:24 pm
Post
by Benjamin » Sun Mar 15, 2009 3:15 pm
You were missing braces around every array variable and a closing double quote.
Code: Select all
<?php
include ('config.php');
//sets date and time variables
$last = gmdate("Y-m-d");
$time = gmdate("H:i", time() + $zone);
//make the connection to the database
$connection = @mysql_connect($server, $dbusername, $dbpassword) or die(mysql_error());
$db = @mysql_select_db($db_name,$connection)or die(mysql_error());
//build and issue the query
$sql = "INSERT INTO messages VALUES ('{$_SESSION[user_name]}', '$time', '$date', '{$_REQUEST['toemail']}', '{$_REQUEST['fromemail']}', '{$_REQUEST['subject']}', '{$_REQUEST['message']}')";
$res = mysql_query($mysql, $sql);