PHP - Database Connect Script Helppp
Hey...
I was going through this sample that was given in the class, but got confused at the first point "//change this to include your own database connect script. include "../../dbconnect.php";" and the database connection code is "<?php if ($_POST['submit']) { // connect to your database $connection = pg_connect("port=5432 dbname=rr_ds user=nobody"); if (!$connection) { die("Connection has failed: " . pg_last_error()); }?> " the database connection code is from a previous assignment which i did, but that was for a login page. The current assignment is to connect to the database and have data on it. Similar Tutorialshey I need this to connect to my database on my sybase sql server, but no matter what i try, it won't populate the plunum field. Any help would be appreciated. Here is my HTML code: Code: [Select] <html> <head> <title>helloscan</title> <meta http-equiv="refresh" content="18"> <meta http-equiv="scanner" content="javascript:doScan('%s');"/> <meta http-equiv="scanner" content="start"/> <META HTTP-Equiv="scanner" Content="enabled" /> <META HTTP-Equiv="scanner" Content="AutoEnter:Enabled"/> <meta http-equiv="keycapture" content="accelerate:all" /> <meta http-equiv="keycapture" content="keyvalue:0x0D; dispatch=true; keyevent:url('javascript:mykeypressed();')" /> <meta http-equiv="quitbutton" content="visibility: visible;"/> <script language="javascript" type="text/javascript"> function doScan(data){ var divEl = ("%s"); } function enablescanner(enable){ Generic.InvokeMetaFunction('scanner', 'start'); Generic.InvokeMetaFunction('scanner', 'enabled'); Generic.InvokeMetaFunction('scanner', 'autoenter:enabled'); } </script> <script> function get_plunum(){ xmlhttp=ajaxfunction(); if (xmlhttp==null) { alert ("no ajax support"); return; } var ae_xrefnum = document.getelementbyid('ae_xrefnum').value; var ae_plunum = document.getelementbyid('ae_plunum').value; var querystring = "?ae_xrefnum=" + xrefnum + "&ae_plunum="+ plunum"; xmlhttp.onreadystatechange = function (){ if (xmlhttp.readystate == 4 || xmlhttp.readystate=="comlete"){ document.myform.ae_plunum.value = xmlHttp.responseText; } } xmlhttp.open("GET", "helloscan2.php"+querystring, true); xmlhttp.send(null); } function ajaxfunction(){ var xmlhttp=null; try {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } catch (err) {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } return xmlhttp; } </script> </head> <body onload="enablescanner(true)"> <h3 align="center"><center><img src="ac moore" /></center>Please scan a barcode...</h3> <form name="myform"> ItemBarcode: <input type="text" id="ae_xrefnum" name="ae_xrefnum" itembarcode="divE1" oninput="get_plunum()" /> plunum: <input type="text" id="ae_plunum" name"ae_plunum" oninput="get_price()"/> </form> <script language=javascript> { document.myform.ae_xrefnum.focus(); } </script> </body> </html> And Here is my PHP code: Code: [Select] <?php //================================================================ // Configure connection parameters $db_host = "97.0.40.244, 1498"; $db_server_name = "ACMSQL036A"; $db_name = "backoff.db"; $db_file = 'd:\trvbkup\DB'; $db_conn_name = "php_script"; $db_user = "dba"; $db_pass = "sql"; //================================================================ $connect_string = "Driver={Adaptive Server Anywhere 8.0};". "CommLinks=tcpip(Host=$db_host);". "ServerName=$db_server_name;". "DatabaseName=$db_name;". "DatabaseFile=$db_file;". "ConnectionName=$db_conn_name;". "uid=$db_user;pwd=$db_pass"; // Connect to DB $conn = odbc_connect($connect_string,'',''); // Query $qry = "SELECT xrefnum, plunum FROM DBA.PLU_Cross_Ref where xrefnum = '$xrefnum'"; // Get Result $result = odbc_exec($conn,$qry); // Get Data From Result while ($row[] = odbc_fetch_array($result)); // Free Result odbc_free_result($result); // Close Connection odbc_close($conn); // Show data print_r($row[plunum]); //================================================================ ?> for some reason my database will not connect, here's the code: Code: [Select] <?php require("mstr_ref2.php"); function parseToXML($htmlStr) { $xmlStr=str_replace('<','<',$htmlStr); $xmlStr=str_replace('>','>',$xmlStr); $xmlStr=str_replace('"','"',$xmlStr); $xmlStr=str_replace("'",'&#39;',$xmlStr); $xmlStr=str_replace("&",'&',$xmlStr); return $xmlStr; } // Opens a connection to a MySQL server $connection=mysql_connect (localhost, $username, $password); if (!$connection) { die('Not connected : ' . mysql_error()); } // Set the active MySQL database $db_selected = mysql_select_db($database, $connection); if (!$db_selected) { die ('Can\'t use db : ' . mysql_error()); } // Select all the rows in the markers table $query = "SELECT * FROM markers WHERE 1"; $result = mysql_query($query); if (!$result) { die('Invalid query: ' . mysql_error()); } header("Content-type: text/xml"); // Start XML file, echo parent node echo '<markers>'; // Iterate through the rows, printing XML nodes for each while ($row = @mysql_fetch_assoc($result)){ // ADD TO XML DOCUMENT NODE echo '<marker '; echo 'name="' . parseToXML($row['name']) . '" '; echo 'address="' . parseToXML($row['address']) . '" '; echo 'lat="' . $row['lat'] . '" '; echo 'lng="' . $row['lng'] . '" '; echo 'type="' . $row['type'] . '" '; echo '/>'; } // End XML file echo '</markers>'; ?> I think there is something wrong with this line of code. Where it says 'locat host' im not too sure about that because im not connecting to a local host, so what can i put in there instead?i think that is the problem. Code: [Select] $connection=mysql_connect (localhost, $username, $password); This is the error I get: Code: [Select] Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'a2221438'@'localhost' (using password: NO) in /home/a2221438/public_html/map.php on line 44 hi i m new to php and i m working on a project in which i m configuring a mail server using Mdeamon 9.5....... In Mdeamon 9.5 users are create by hand but i want to create user online as they sign up and their account will create as abc@mycompany.com and thier inbox created. So i want when user is sign up online and new entries will added to SQL database which trigger the Mdeamon to create a new user is it possible????? If YES then how can i do it..................... Thnx in advance for help.................. Hi, I cant connect to my Mysql database. I get this problem: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'esolarch_databas'@'localhost' (using password: YES) in /home7/esolarch/public_html/new/storescripts/connect_to_mysql.php on line 21 could not connect to mysql Code: [Select] <?php /* 1: "die()" will exit the script and show an error statement if something goes wrong with the "connect" or "select" functions. 2: A "mysql_connect()" error usually means your username/password are wrong 3: A "mysql_select_db()" error usually means the database does not exist. */ // Place db host name. Sometimes "localhost" but // sometimes looks like this: >> ???mysql??.someserver.net $db_host = "localhost"; // Place the username for the MySQL database here $db_username = "esolarch_database"; // Place the password for the MySQL database here $db_pass = "Password"; // Place the name for the MySQL database here $db_name = "esolarch_admin2"; // Run the actual connection here mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql"); mysql_select_db("$db_name") or die ("no database"); ?> This is my first post so please correct me if somethings wrong Basically im creating a shopping cart with the help of a guide but there is no database written in the guide so i'm not sure how to proceed. My database wont work... Guide: https://jameshamilto...g-cart-tutorial Error message http://gyazo.com/a20...b096b7727410dfd Index: <?php session_start(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="description" content="PHP Shopping Cart Using Sessions" /> <meta name="keywords" content="shopping cart tutorial, shopping cart, php, sessions" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" media="all" href="/style/style.css" type="text/css" /> <title>Cart</title> <?php //connect to your database here $sql = 'SELECT * FROM books ORDER BY id'; $output[] = '<ul>'; $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': £'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; //connect mysql mysql_connect($server, $user, $pass) or die ("Sorry, can't conect to mysql."); //select db mysql_select_db($db) or die ("Sorry cant select the db."); ?> </head> <body> <?php $product_id = $_GET[id]; //the product id from the URL $action = $_GET[action]; //the action from the URL //if there is an product_id and that product_id doesn't exist display an error message if($product_id && !productExists($product_id)) { die("Error. Product Doesn't Exist"); } switch($action) { //decide what to do case "add": $_SESSION['cart'][$product_id]++; //add one to the quantity of the product with id $product_id break; case "remove": $_SESSION['cart'][$product_id]--; //remove one from the quantity of the product with id $product_id if($_SESSION['cart'][$product_id] == 0) unset($_SESSION['cart'][$product_id]); //if the quantity is zero, remove it completely (using the 'unset' function) - otherwise is will show zero, then -1, -2 etc when the user keeps removing items. break; case "empty": unset($_SESSION['cart']); //unset the whole cart, i.e. empty the cart. break; } ?> <?php if($_SESSION['cart']) { //if the cart isn't empty //show the cart echo "<table border=\"1\" padding=\"3\" width=\"40%\">"; //format the cart using a HTML table //iterate through the cart, the $product_id is the key and $quantity is the value foreach($_SESSION['cart'] as $product_id => $quantity) { //get the name, description and price from the database - this will depend on your database implementation. //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection $sql = sprintf("SELECT name, description, price FROM php_shop_products WHERE id = %d;", $product_id); $result = mysql_query($sql); //Only display the row if there is a product (though there should always be as we have already checked) if(mysql_num_rows($result) > 0) { list($name, $description, $price) = mysql_fetch_row($result); $line_cost = $price * $quantity; //work out the line cost $total = $total + $line_cost; //add to the total cost echo "<tr>"; //show this information in table cells echo "<td align=\"center\">$name</td>"; //along with a 'remove' link next to the quantity - which links to this page, but with an action of remove, and the id of the current product echo "<td align=\"center\">$quantity <a href=\"$_SERVER[PHP_SELF]?action=remove&id=$product_id\">X</a></td>"; echo "<td align=\"center\">$line_cost</td>"; echo "</tr>"; } } //show the total echo "<tr>"; echo "<td colspan=\"2\" align=\"right\">Total</td>"; echo "<td align=\"right\">$total</td>"; echo "</tr>"; //show the empty cart link - which links to this page, but with an action of empty. A simple bit of javascript in the onlick event of the link asks the user for confirmation echo "<tr>"; echo "<td colspan=\"3\" align=\"right\"><a href=\"$_SERVER[PHP_SELF]?action=empty\" onclick=\"return confirm('Are you sure?');\">Empty Cart</a></td>"; echo "</tr>"; echo "</table>"; }else{ //otherwise tell the user they have no items in their cart echo "You have no items in your shopping cart."; } //function to check if a product exists function productExists($product_id) { //use sprintf to make sure that $product_id is inserted into the query as a number - to prevent SQL injection $sql = sprintf("SELECT * FROM php_shop_products WHERE id = %d;", $product_id); return mysql_num_rows(mysql_query($sql)) > 0; } ?> <a href="products.php">Continue Shopping</a> <?php /* products table: CREATE TABLE `products` ( `id` INT NOT NULL AUTO_INCREMENT , `name` VARCHAR( 255 ) NOT NULL , `description` TEXT, `price` DOUBLE DEFAULT '0.00' NOT NULL , PRIMARY KEY ( `id` ) ); */ ?> </body> </html>products.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="description" content="PHP Shopping Cart Using Sessions" /> <meta name="keywords" content="shopping cart tutorial, shopping cart, php, sessions" /> <link rel="stylesheet" media="all" href="/style/style.css" type="text/css" /> <title>Products</title> <?php //connect to your database here //connect to your database here $sql = 'SELECT * FROM books ORDER BY id'; $output[] = '<ul>'; $output[] = '<li>"'.$row['title'].'" by '.$row['author'].': £'.$row['price'].'<br /><a href="cart.php?action=add&id='.$row['id'].'">Add to cart</a></li>'; //connect mysql mysql_connect($server, $user, $pass) or die ("Sorry, can't conect to mysql."); //select db mysql_select_db($db) or die ("Sorry cant select the db."); ?> </head> <body> <table border="1"> <?php $sql = "SELECT id, name, description, price FROM php_shop_products;"; $result = mysql_query($sql); while(list($id, $name, $description, $price) = mysql_fetch_row($result)) { echo "<tr>"; echo "<td>$name</td>"; echo "<td>$description</td>"; echo "<td>$price</td>"; echo "<td><a href=\"cart.php?action=add&id=$id\">Add To Cart</a></td>"; echo "</tr>"; } ?> </table> <a href="cart.php">View Cart</a> </body> </html> Hello, I've been having trouble connecting to a MySQL database, I can't find the problem in the code, what am I doing wrong? Getting the database file in the config file : require_once("db_connect.php"); db_connect.php : <?php $db = mysql_connect('83.172.155.14:3306', 'username', 'password') or die(mysql_error()); mysql_select_db('databasename', $db) or die(mysql_error()); ?> I need to connect to a PhpMyAdmin database. I need this fixed asap since I'm doing this for someone and he wants the site done as quickly as possible. P.S: The database used to work in php4 and now I need it to work on php5 Thanks in advance, I know the regular database connection, but this time i am provided with the SSH details. This guy game me the IP address of the database server to connect and 2 login details. SSH: Username and Password DB: Username and Password And i am using XAMPP for trying out the code. Is there any plugin i need to download for SSH connections? Could you please give me the connection snippet for SSH because i don't really know how to do that, i am also searching elsewhere on internet. Thanks in advance for help... Hey all, I'm sure this is a really basic question but I'd like a definite answer. I've been watching a tutorial and seeing some site references regarding connecting to a sql database using php. Since it contains a password to the database, my question is, how secure is this page on a webserver, or does it not even matter since the code is so specific to the website and the database it is connecting to.
Thank you in advance. hello there.. i have a problem with my php coding where i want to keep date choose by user in the database. this is the drop down date Code: [Select] <select name="Date_Day"> <option> - Day - </option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select name="Date_Month"> <option> - Month - </option> <option value="01">January</option> <option value="02">Febuary</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> <option value="06">June</option> <option value="07">July</option> <option value="08">August</option> <option value="09">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select name="Date_Year"> <option> - Year - </option> <option value="2010">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> <option value="2013">2013</option> <option value="2014">2014</option> <option value="2015">2015</option> <option value="2016">2016</option> <option value="2017">2017</option> <option value="2018">2018</option> <option value="2019">2019</option> <option value="2020">2020</option> <option value="2021">2021</option> <option value="2022">2022</option> <option value="2023">2023</option> <option value="2024">2024</option> <option value="2025">2025</option> <option value="2026">2026</option> </select> the code to connect to the database Code: [Select] $date_year= ($_POST['Date_Year']); $date_month=($_POST['Date_Month']); $date_day=($_POST['Date_Day']); $date=$date_year."-".$date_month."-".$date_day; $query="INSERT INTO aduan (date) VALUES ('date($date)')"; $result=mysql_query($query); if($result){ echo 'Registration success.'; ?><script>window.location ='thanks.php'</script> <?php } else echo 'Registration failed';} when enter a value of date, the database will just show '0000-00-00'.. really hope for your help.. Hi, When i am trying to run one script on my web server, i get following error Cannot connect to the database using the info you provided Access denied for user 'My_Username'@'localhost' (using password: NO) I filled all info like Host(localhost) Database name(created in cpanel) Username(created in cpanel) Password(i kept blank dont know where to find this) You help will highly appreciate Thanks, Ravindra Hi there, I have this connect script I have made. I was wondering if it's secure or not, if not... What would be a good way to do so... Code: [Select] <?php class connect{ public $host = "localhost"; public $dbuser = ""; public $dbpass = ""; public $db = ""; } $connect = new connect(); mysql_connect($connect->host,$connect->dbuser,$connect->dbpass) or die("Could not connect!"); mysql_select_db($connect->db); ?> Here is my code in admin_common.php. This is a website I had over at yahoo that I moved to Godaddy. define("EZSQL_DB_USER", "larryadmin"); // <-- mysql db user define("EZSQL_DB_PASSWORD", "mypassword"); // <-- mysql db password define("EZSQL_DB_NAME", "larryadmin"); // <-- mysql db pname define("EZSQL_DB_HOST", "mysql"); // <-- mysql server host I keep getting this error SQL/DB Error -- [ Error establishing a database connection! Are you sure you have the correct user/password? Are you sure that you have typed the correct hostname? Are you sure that the database server is running? ] SQL/DB Error -- [ Error selecting database larryadmin! Are you sure it exists? Are you sure there is a valid database connection? ] Please help thanks. Hello I am creating a simple Discussion Forum, and I cant get past my IF Statement to verify topics exist? Please help? <?php //check for required info from the query string if (!$_GET[topic_id]) { header("Location: topiclist.php"); exit; } //connect to server and select database $link = mysql_connect('votpservicescom.ipagemysql.com', 'mantest', 'testman') or die(mysql_error()); mysql_select_db("learn2db",$link) or die(mysql_error()); Okay guys I have finished my db and I want to upload it to a live server but don't know exactly what to change in the code to get the ODBC_connect to open the path at the new server location please help. my database is located in a subfolder called Databases i.e. "www.mydomain.com/Databases/myEvents.mdb" what do i change in the connection string below to get it to open the file on the live server? Thanks in advance. $conn = odbc_connect('myEvents','',''); This topic has been moved to Microsoft SQL - MSSQL. http://www.phpfreaks.com/forums/index.php?topic=319147.0 I'm curious to know if anyone knows if this is possible. Let's say we have a script that's echoing out something to the user. For example: <?PHP $i = 0; while ($i <= 100){ ob_flush(); flush(); $i++; echo $i; } ?> If the internet connection is dropped from the user, is there any way to auto-reconnect as a means of continuing from where the script left off? Warning: mysql_connect() [function.mysql-connect]: Too many connections in /home/website/public_html/scripts/connect.php on line 7 Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'website'@'localhost' (using password: NO) in /home/website/public_html/scripts/connect.php on line 8 Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in /home/website/public_html/scripts/connect.php on line 8 Warning: mysql_query() [function.mysql-query]: Access denied for user 'website'@'localhost' (using password: NO) in /home/website/public_html/header.php on line 10 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/website/public_html/header.php on line 10 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/website/public_html/header.php on line 12 what should i do it keeps happening My first real attempt to mess with MySql. Keep getting a syntax error and I am quite confused. Error: Code: [Select] Parse error: syntax error, unexpected '}' in /home/a8152576/public_html/MemberSystem/install1.php on line 68 Here is my php code: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action=""> <h2><center>Fill in the following info properly to install required databases.</center></h2> <p> <label>Host: <input type="text" name="host" id="host" /> </label> </p> <p> <label>Database User: <input type="text" name="dbUser" id="dbUser" /> </label> </p> <p> <label>Database Password: <input type="text" name="dbPass" id="dbPass" /> </label> </p> <p> <label>Desired Admin Username: <input type="text" name="adminName" id="adminName" /> </label> </p> <p> <label>Desired Admin Password: <input type="text" name="adminPass" id="adminPass" /> </label> </p> <p> <label>Email: <input type="text" name="adminEmail" id="adminEmail" /> </label> </p> <p> <input type="submit" name="submitBtn" id="submitBtn" value="Submit" /> </p> </form> <?php if(isset($_POST['submit'])){ $hostName = $_POST['host']; $dbUserName = $_POST['dbUser']; $dbPassword = $_POST['dbPass']; $adminUserName = $_POST['adminName']; $adminPassword = $_POST['adminPass']; $email = $_POST['adminEmail']; $sqlLink = mysql_connect('$hostName','$dbUserName','$dbPassword'); if(!$sqlLink){ die('Could not connect: ' .mysql_error()); mysql_close(); } else { $queryCreate = 'CREATE DATABASE member_db'; echo 'Connected successfully!'; if(mysql_query($queryCreate,$link)){ echo 'Created database!'; mysql_select_db('member_db'); $createAdminTable = "CREATE TABLE " .$adminUserName. " (`secLvl` tinyint(1) default NOT NULL,`rank` tinyint(2) default NOT NULL,`username` varChar(32) NOT NULL UNIQUE,`password` varChar(32) NOT NULL,`email` varChar(32) NOT NULL UNIQUE"; $insertAdminInfoQuery = "UPDATE " .$adminUserName. " SET `secLvl` = '5', `rank` = '10', `username` = '$adminUserName', `password` = '$adminPassword', `email` = '$email' WHERE '$adminUserName' LIMIT 1"; mysql_query($createAdminTable) or die("ERROR: " .mysql_error()); mysql_query($insertAdminInfoQuery) or die("ERROR: " .mysql_error()) } else { echo 'Error: '.mysql_error(); } } } ?> </body> </html> You can even see the error on this web page directly: http://www.ptcptc.info/MemberSystem/install1.php Thanks, Brandon i'm just having a little bit of a play around making a browser-based text RPG with PHP and mySQL. But when it comes to creating a system where a player can view their inventory, and for that matter -have- items. i just don't know where to begin. Would i make a seperate database for inventories and have each column in the database be a different inventory slot and then have the value in that field be in reference to an item? like 1 = potion, 2= ether, etc? with a large amount of items and inventory space for each player i don't want to get started down a long road on the wrong path. To reiterate, I'm not asking for the code specifically i'm just asking what way I would go about it. What would be the simplest, least headachey method of such a system? Hi, i'm basically having problems with this code, its for a newsletter script which added the email address into a file, i'm trying to convert it to work with mysql but having a few problems; I've edited the last bit, the code just basically doesn't add it to the database even though i thought i had done it right... any help is very much appreciated! If email is not valid the script is letting me know; if email is valid it says "already added to the list" no matter what. old script <?php /** BY WebResourcesDepot - http://www.webresourcesdepot.com*/ /** YOU CAN EDIT HERE*/ $newsletterFileName = "file.txt"; /** IMPORTANT: EDIT BELOW UNLESS YOU KNOW WHAT YOU ARE DOING*/ function GetField($input) { $input=strip_tags($input); $input=str_replace("<","<",$input); $input=str_replace(">",">",$input); $input=str_replace("#","%23",$input); $input=str_replace("'","`",$input); $input=str_replace(";","%3B",$input); $input=str_replace("script","",$input); $input=str_replace("%3c","",$input); $input=str_replace("%3e","",$input); $input=trim($input); return $input; } /**Validate an email address. Provide email address (raw input) Returns true if the email address has the email address format and the domain exists. */ function validEmail($email) { $isValid = true; $atIndex = strrpos($email, "@"); if (is_bool($atIndex) && !$atIndex) { $isValid = false; } else { $domain = substr($email, $atIndex+1); $local = substr($email, 0, $atIndex); $localLen = strlen($local); $domainLen = strlen($domain); if ($localLen < 1 || $localLen > 64) { // local part length exceeded $isValid = false; } else if ($domainLen < 1 || $domainLen > 255) { // domain part length exceeded $isValid = false; } else if ($local[0] == '.' || $local[$localLen-1] == '.') { // local part starts or ends with '.' $isValid = false; } else if (preg_match('/\\.\\./', $local)) { // local part has two consecutive dots $isValid = false; } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { // character not valid in domain part $isValid = false; } else if (preg_match('/\\.\\./', $domain)) { // domain part has two consecutive dots $isValid = false; } else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) { // character not valid in local part unless // local part is quoted if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) { $isValid = false; } } } return $isValid; } $email = GetField($_GET['email']); $pass = validEmail($email); if ($pass) { $f = fopen($newsletterFileName, 'a+'); $read = fread($f,filesize($newsletterFileName)); If (strstr($read,"@")) { $delimiter = ";"; } if (strstr($read,$email)) { echo 3; } else { fwrite($f, $delimiter . $email); echo 1; } fclose($f); } else { echo 2; } ?> edited script <?php /** BY WebResourcesDepot - http://www.webresourcesdepot.com*/ /** YOU CAN EDIT HERE*/ $newsletterFileName = "file.txt"; /** IMPORTANT: EDIT BELOW UNLESS YOU KNOW WHAT YOU ARE DOING*/ function GetField($input) { $input=strip_tags($input); $input=str_replace("<","<",$input); $input=str_replace(">",">",$input); $input=str_replace("#","%23",$input); $input=str_replace("'","`",$input); $input=str_replace(";","%3B",$input); $input=str_replace("script","",$input); $input=str_replace("%3c","",$input); $input=str_replace("%3e","",$input); $input=trim($input); return $input; } /**Validate an email address. Provide email address (raw input) Returns true if the email address has the email address format and the domain exists. */ function validEmail($email) { $isValid = true; $atIndex = strrpos($email, "@"); if (is_bool($atIndex) && !$atIndex) { $isValid = false; } else { $domain = substr($email, $atIndex+1); $local = substr($email, 0, $atIndex); $localLen = strlen($local); $domainLen = strlen($domain); if ($localLen < 1 || $localLen > 64) { // local part length exceeded $isValid = false; } else if ($domainLen < 1 || $domainLen > 255) { // domain part length exceeded $isValid = false; } else if ($local[0] == '.' || $local[$localLen-1] == '.') { // local part starts or ends with '.' $isValid = false; } else if (preg_match('/\\.\\./', $local)) { // local part has two consecutive dots $isValid = false; } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { // character not valid in domain part $isValid = false; } else if (preg_match('/\\.\\./', $domain)) { // domain part has two consecutive dots $isValid = false; } else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) { // character not valid in local part unless // local part is quoted if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) { $isValid = false; } } } return $isValid; } $email = GetField($_GET['email']); $pass = validEmail($email); if ($pass) { $user_name = "_db"; $password = ""; $database = "_db"; $server = "localhost"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL2 = "SELECT * FROM newsletter WHERE email = '$_GET[email]'"; $result = mysql_query($SQL2); mysql_close($db_handle); } if (strstr($SQL2,$email)) { echo 3; } else { $user_name = "_db"; $password = ""; $database = "_db"; $server = "localhost"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL = "INSERT INTO newsletter (email,subscribed) VALUES ('$_GET[email]',1)"; $result = mysql_query($SQL); mysql_close($db_handle);} echo 1; } } else { echo 2; } ?> |