Parse error: parse error, unexpected T_VARIABLE in /home2/cpanelu/public_html/dci125/assets/library/global/insert.php on line 32psyr33n said:a) mysql_query("SELECT * FROM newsLetter);
Spot what's wrong.
b) $to = "$email";
Not an error, but no interpolation means no need for quotation.
As for "not working", can you elaborate?
Aye I had already tried it without the quotation marks and got this error:psyr33n said:Did you read my post, by any chance?
<?php
$email = mysql_query("SELECT * FROM newsLetter);
$to = $email;
$subject = "Welcome!";
$txt = "Dear User, this is just a quick email to thank you for signing up to the OCV newsletter!We look forward to sending you many exciting newsletters in the future! Thanks again the OCV Team!";
$headers = "From: OverclockersVortex.co.uk" . "\r\n" .
"CC: [email protected]";
mail($to,$subject,$txt,$headers);
?>
<?php
<?php
$sel = mysql_connect("localhost","cpanelu_dci125","Manypeop");
if (!$sel)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("cpanelu_dci125", $sel);
$comment = mysql_query("SELECT * FROM newsLetter");
$line = mysql_fetch_array($comment);
$to = $line['email'];
$subject = "Welcome!";
$txt = "Dear User, this is just a quick email to thank you for signing up to the OCV newsletter!We look forward to sending you many exciting newsletters in the future! Thanks again the OCV Team!";
$headers = "From: OverclockersVortex.co.uk" . "\r\n" .
"CC: Overclockersvortex.co.uk";
mail($to,$subject,$txt,$headers);
mysql_error();
mysql_close($sel);
?>
Ok, I think I have it working, would people mind testing it and letting me know if they get an email? Thanks
http://cpanel.lincoln.ac.uk/dci125/index.shtml
<?php
// Declare and initialize variables
$database = "Your database name";
$hostName = "localhost";
$loginName = "Your username";
$passwdName = "You Password";
// Formulate the create table query - Obviously chnage the sql for your table
$query1 = "CREATE TABLE IF NOT EXISTS tblLinks (
`ID` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`URL` VARCHAR(255) UNIQUE NOT NULL,
`Title` VARCHAR(255),
`Description` VARCHAR(255)) TYPE=MyISAM";
// Formulate the insert row query
$query2 = "INSERT IGNORE INTO tblLinks (`URL`,`Title`,`Description`) VALUES
('URL Here,' Page Title Here','Descrition Goes here')";
//Repeat format above to add more entries
// Connect to the server
$link = mysql_connect($hostName,$loginName,$passwdName);
// Check result
if (!$link) {
echo "Could not connect to mysql<br>";
echo 'MySQL Error: ' . mysql_error();
exit;
}
// Select the database
$result = mysql_select_db($database, $link);
// Check result
if (!$result) {
echo "Could not select database<br>";
echo 'MySQL Error: ' . mysql_error();
exit;
}
// Send the create table query to the database and execute it
$result = mysql_query($query1, $link);
// Check result
if (!$result) {
echo "DB Error, could not query the database<br>";
echo 'MySQL Error: ' . mysql_error();
exit;
}
// Send the insert row query to the database and execute it
$result = mysql_query($query2, $link);
// Check result
if (!$result) {
echo "DB Error, could not query the database<br>";
echo 'MySQL Error: ' . mysql_error();
exit;
}
// Get the number of rows affected by the last query
$affected_rows = mysql_affected_rows($link);
echo "Your data has been successfully exported<br>";
echo "Added $affected_rows record(s)";
// Close the link to the database
mysql_close($link);
?>
arrond said:Ok, I think I have it working, would people mind testing it and letting me know if they get an email? Thanks
http://cpanel.lincoln.ac.uk/dci125/index.shtml
<?php
// Declare and initialize variables
$database = "Your database name";
$hostName = "localhost";
$loginName = "Your username";
$passwdName = "You Password";
// Formulate the create table query - Obviously chnage the sql for your table
$query1 = "CREATE TABLE IF NOT EXISTS tblLinks (
`ID` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`URL` VARCHAR(255) UNIQUE NOT NULL,
`Title` VARCHAR(255),
`Description` VARCHAR(255)) TYPE=MyISAM";
// Formulate the insert row query
$query2 = "INSERT IGNORE INTO tblLinks (`URL`,`Title`,`Description`) VALUES
('URL Here,' Page Title Here','Descrition Goes here')";
//Repeat format above to add more entries
// Connect to the server
$link = mysql_connect($hostName,$loginName,$passwdName);
// Check result
if (!$link) {
echo "Could not connect to mysql<br>";
echo 'MySQL Error: ' . mysql_error();
exit;
}
// Select the database
$result = mysql_select_db($database, $link);
// Check result
if (!$result) {
echo "Could not select database<br>";
echo 'MySQL Error: ' . mysql_error();
exit;
}
// Send the create table query to the database and execute it
$result = mysql_query($query1, $link);
// Check result
if (!$result) {
echo "DB Error, could not query the database<br>";
echo 'MySQL Error: ' . mysql_error();
exit;
}
// Send the insert row query to the database and execute it
$result = mysql_query($query2, $link);
// Check result
if (!$result) {
echo "DB Error, could not query the database<br>";
echo 'MySQL Error: ' . mysql_error();
exit;
}
// Get the number of rows affected by the last query
$affected_rows = mysql_affected_rows($link);
echo "Your data has been successfully exported<br>";
echo "Added $affected_rows record(s)";
// Close the link to the database
mysql_close($link);
?>
<script type="text/javascript">
alert('Sanitise all user input!');
alert('Otherwise people will inject code into your site');
alert('Like this');
</script>
thanks, I didn't know that, useful informationAugmented said:Requires MySQL >=5.0.3. Below 5.0.3, the limitation is 255 characters.
jcb33 said:Just wondering how can I validate my forms so people cant insert code like < and > because so far had someone insert my entire site into my guestbook twice, and some java script :/
<?php
// Connect
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
OR die(mysql_error());
// Query
$query = sprintf("SELECT * FROM users WHERE user='%s' AND password='%s'",
mysql_real_escape_string($user),
mysql_real_escape_string($password));
?>
Code:<script type="text/javascript"> alert('Sanitise all user input!'); alert('Otherwise people will inject code into your site'); alert('Like this'); </script>
Ah, the problem is not to do with passwords, its just people breaking my guestbook by inserting code into it, instead of leaving a nice comment, so I need to:arrond said:Its called sql injection. Its very common. Heres a simply script you need to apply to your code
Code:<?php // Connect $link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password') OR die(mysql_error()); // Query $query = sprintf("SELECT * FROM users WHERE user='%s' AND password='%s'", mysql_real_escape_string($user), mysql_real_escape_string($password)); ?>
This is very simple, i would recommend looking into it further but it can get complicated. Basically your goal is to validate input to stop people gaining access by bypassing your password such as using "' OR ''='" which changes the sql query to ignore password entry.
Hope this helps![]()
Yes I amarrond said:Your guessbook is taking in user input, that is how they are able to inject code. You should validate Name, email and comment input. Your using php and a database to store the comments, yes?
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO tblcom (Name, Comment, `Date`) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['Name'], "text"),
GetSQLValueString($_POST['Comment'], "text"),
GetSQLValueString($_POST['Date'], "date"));
mysql_select_db($database_blog, $blog);
$Result1 = mysql_query($insertSQL, $blog) or die(mysql_error());
$insertGoTo = "comments.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
Aye is a bit complicated, cant work out where it stops certain characters being entered evenarrond said:Ok its a bit hard to explain everyting if you dont know but on my site you can also post comments, very similar to yours except you can only enter a name and comment. This is my code:
Code:<?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO tblcom (Name, Comment, `Date`) VALUES (%s, %s, %s, %s)", GetSQLValueString($_POST['Name'], "text"), GetSQLValueString($_POST['Comment'], "text"), GetSQLValueString($_POST['Date'], "date")); mysql_select_db($database_blog, $blog); $Result1 = mysql_query($insertSQL, $blog) or die(mysql_error()); $insertGoTo = "comments.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } ?>
Its a bit complicated i know, most of this was generated for me.
jcb33 said:Search Comment, if HTML Tags then replace with " "
$comment = strip_tags($comment);
$comment = htmlspecialchars($comment);
Search comment, If word > 20 characters then replace with " "
$comment = substr($comment, 0, 20);
Before you insert, clean it with mysql_real_escape_string().Submit to database
$comment = mysql_real_escape_string($comment);