Page 1 of 1
Php/MySql error
Posted: Sun Mar 15, 2009 11:36 am
by aalbright
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.
Re: Php/MySql error
Posted: Sun Mar 15, 2009 11:42 am
by jh_1981
$_SESSION[user_name] etc. need concat like this "".$_SESSION[user_name].""
Re: Php/MySql error
Posted: Sun Mar 15, 2009 11:48 am
by aalbright
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.
Re: Php/MySql error
Posted: Sun Mar 15, 2009 12:59 pm
by jcrensha627
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.
Re: Php/MySql error
Posted: Sun Mar 15, 2009 3:15 pm
by Benjamin
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);