PHP - Connect Error
Ok this code doesn't look wrong but i cant figure out whats going on?
Code: (connect.php) [Select] <?php //connect.php $server = 'localhost'; $username = 'admin'; $password = 'pass'; $database = 'gms'; if(!mysql_connect($server, $username, $password)) { exit('Error: could not establish database connection'); } if(!mysql_select_db($database) { exit('Error: could not select the database'); } ?> ERROR Code: [Select] Parse error: syntax error, unexpected '{' in /home/adee67/public_html/forum/connect.php on line 13 Similar TutorialsI am using WAMP server for my PHP Server and am trying to connect to an Access Database with the extension of accdb, but I keep getting the error "could not find driver". Here is the code I'm trying to run:
$dbName = $_SERVER["DOCUMENT_ROOT"]."/Ridley/RLCompRepair.accdb";
if (!file_exists($dbName)) {
die("Could not find database file.");
}
try {
$db = new PDO("odbc:Driver={MS Access Database (*.mdb, *.accdb)};Dbq=$dbName");
} catch (PDOException $e) {
echo "Error: ".$e->getMessage();
}
I have enabled the php_pdo_odbc extension, so I'm pretty sure this is not the problem. Could someone please let me know what is wrong?
Chris
Edited by chrscote, 15 November 2014 - 02:45 PM. Have actually tried this mailer on localhost and it worked perfectly. Now am trying to use it on online but it's giving this error
SMTP-> ERROR: Failed to connect to server: Connection timed out (110)
SMTP -> ERROR: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP Host.
please how do i fix this?
include "classes/class.phpmailer.php"; // include the class name $mail = new PHPMailer(); // create a new object $mail->IsSMTP(); // enable SMTP $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only $mail->SMTPAuth = true; // authentication enabled $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail $mail->Host = "smtp.gmail.com"; $mail->Port = 465; // or 587 $mail->IsHTML(true); $mail->Username = "hypropsict@gmail.com"; $mail->Password = "hyprops123"; $mail->SetFrom("hypropsict@gmail.com"); $mail->Subject = "Requisition Processed"; $mail->Body = "<b>Hello $firstname, your requisition has been processed and Approved.. <br/><br/>Come to the Account department to recieve your $text . <br/> Thank You </b>"; $mail->AddAddress($email); if(!$mail->Send()){ echo "Mailer Error: " . $mail->ErrorInfo; }
According to I have a project need to use PHP 5.6.40 connect to mysql version 5.7.34
when I try to connect it by below coding $servername = "localhost"; $username = "user"; $password = "pass"; $db_database = 'db_unelr'; $db_port = '3306'; // Create connection $conn = mysqli_connect($servername, $username, $password,$db_database,$db_port); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully";
it's show 500 internal error.
Firstly I'd like to say a hello to everyone. OK, I'm having a problem with my PHPMailer setup. My aim is to have a registration email sent to a user upon sign up from (admin@mydomain.com). I have set up my mail servers set up correctly. so I can send/recieve mail from (admin@mydomain.com). I am using PHPMailer_v5.1, and am using the following code Code: [Select] <?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once('../class.phpmailer.php'); $mail = new PHPMailer(); $body = file_get_contents('contents.html'); $body = eregi_replace("[\]",'',$body); $mail->IsSMTP(); $mail->Host = "admin@mydomain.com"; $mail->SMTPDebug = 1; $mail->SMTPAuth = true; $mail->SMTPSecure = "ssl"; $mail->Host = "admin@mydomain.com"; $mail->Port = 25; $mail->Username = "admin@mydomain.com"; $mail->Password = "*****"; $mail->SetFrom('admin@mydomain.com","My Domain'); $mail->AddReplyTo("admin@mydomain.com","My Domain"); $mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; $mail->MsgHTML($body); $address = "test@test.com"; $mail->AddAddress($address, "Test"); if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } ?> I set up a PHP document to test this mail feature, but every time I load it, it displays this SMTP -> ERROR: Failed to connect to server: (0) SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host. The PHPMailer is running on Elastiks (CentOS Linux 5.6). I cross checked the php.ini file and the OpenSSL is enabled. openssl OpenSSL support enabled OpenSSL Version OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008 Please help me out from these issue. Thanks for your time guys, hope someone can get back to me soon! Hi I am trying to send email through following php code to may gmail account but it givrs me SMTP Error: Could not connect to SMTP host.
*******************************************************************************************************************************************************
<?phpif(isset($_POST['submit'])){ $message='Full Name: '.$_POST['fullname'].'<br />Subject: '.$_POST['subject'].'<br />Phone: '.$_POST['phone'].'<br />Email: '.$_POST['emailid'].'<br />Comments: '.$_POST['comments'].''; require "phpmailer/class.phpmailer.php"; //include phpmailer class // Instantiate Class $mail = new PHPMailer(); // Set up SMTP $mail->IsSMTP(); // Sets up a SMTP connection $mail->SMTPAuth = true; // Connection with the SMTP does require authorization $mail->SMTPSecure = "ssl"; // Connect using a TLS connection $mail->Host = "smtp.gmail.com"; //Gmail SMTP server address $mail->Port = 465; //Gmail SMTP port $mail->Encoding = '7bit'; // Authentication $mail->Username = "myemail@gmail.com"; // Your full Gmail address $mail->Password = "mypassword"; // Your Gmail password // Compose $mail->SetFrom($_POST['emailid'], $_POST['fullname']); $mail->AddReplyTo($_POST['emailid'], $_POST['fullname']); $mail->Subject = "New Contact Form Enquiry"; // Subject (which isn't required) $mail->MsgHTML($message); // Send To $mail->AddAddress("myemail@gmail.com", "Recipient Name"); // Where to send it - Recipient $result = $mail->Send(); // Send! $message = $result ? 'Successfully Sent!' : 'Sending Failed!'; unset($mail); }?><html><head> <title>Contact Form</title></head><body> <div style="margin: 100px auto 0;width: 300px;"> <h3>Contact Form</h3> <form name="form1" id="form1" action="" method="post"> <fieldset> <input type="text" name="fullname" placeholder="Full Name" /> <br /> <input type="text" name="subject" placeholder="Subject" /> <br /> <input type="text" name="phone" placeholder="Phone" /> <br /> <input type="text" name="emailid" placeholder="Email" /> <br /> <textarea rows="4" cols="20" name="comments" placeholder="Comments"></textarea> <br /> <input type="submit" name="submit" value="Send" /> </fieldset> </form> <p><?php if(!empty($message)) echo $message; ?></p> </div> </body></html> define("DB_HOST", "localhost"); hello, if i have an entry in a table called company on database cc, would the following be the propper code? im getting a blank page. Code: [Select] <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'mike'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'cc'; mysql_select_db($dbname); $query = "SELECT * FROM company"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "Name :{$row['compant']} <br>" . "Subject : {$row['address']} <br>" . } ?> hey 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]); //================================================================ ?> Hey, I've had this problem for a couple days now, and haven't been able to work it out. I'm trying to connect to the Gamesurge IRC using PHP - though the code I am using times out and can't connect. I thought it was my code, however I have searched the web for working codes and they all *seem* to do the same basic thing as mine. So if anyone has any ideas as to why I am getting a timeout, I would appreciate it. The code I'm using. <?php error_reporting(E_ERROR); $cfg = array( "server" => "irc.gamesurge.net", "channel" => "#wiremod", "port" => 6667, "name" => "thetree PHP" ); echo "Connecting to " . $cfg["server"] . " on port " . $cfg["port"] . "<br/>"; $socket = fsockopen($cfg["server"], $cfg["port"], $errno, $errstr, 5); if (!$socket) { echo("Error[$errno]: $errstr...<br/>"); } else { echo "Socket connection successful..<br/>"; } fclose($socket); ?> Hosted file: http://joethetree.lil.org.uk/socket.php Thanks thetree 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 I'm trying to add Facebook connect to my new app, but I'm not sure where to really start. I looked through a lot of the facebook documentation, but I haven't been able to find any really good implementation suggestions. I just want basic functionality. HI, I'm running the next script from my local host and the production server, and Im getting different outputs. Anyone knows why am I getting that error from my localhost? <?php $host = 'ssl://mail.companyname.org'; $port = 993; $error = 0; $errorString = ""; var_dump(fsockopen($host, $port, $error, $errorString, 30)); var_dump($errorString); var_dump($error);
> PHP Warning: fsockopen(): SSL operation failed with code 1. OpenSSL Production server output: resource(4) of type (stream)
Edited November 26, 2020 by tirengarfio I'm trying to connect to two databases and I'm having problems with the following code. I googled to come up with this but can't figure out the errors I'm getting. Code: [Select] $connection="localhost"; $username="user"; $password="password"; $database1="dbone"; $database2="dbtwo"; $db1 = mysql_connect($connection,$username,$password) or die(mysql_error()); $sel1 = mysql_select_db($database1, $db1); $query1 = "SELECT * FROM TBLUSERS"; $result1 = mysql_query($query1, $db1); while($nt1 = mysql_fetch_array($result1, $db1)) { } $db2 = mysql_connect($connection,$username,$password) or die(mysql_error()); $sel2 = mysql_select_db($database2, $db2); $query2 = "SELECT * FROM TBLPD20101101"; $result2 = mysql_query($query2, $db2) or die(mysql_error()); while($nt2 = mysql_fetch_array($result2, $db2)) { } The error I get is Quote Warning: mysql_fetch_array() expects parameter 2 to be long, resource given in C:\xampp\htdocs\HighVisibility\DashBoard2.php on line 13 Warning: mysql_fetch_array() expects parameter 2 to be long, resource given in C:\xampp\htdocs\HighVisibility\DashBoard2.php on line 22 Hi People. Thanks to everyone that helped me yesterday with my file that finally connected to the database. However, I have added a new field to my DB and now get further problems. Here is the error message I am getting after I added the "ppr" stuff to both files. Please could someone look at my code and tell me where I'm going wrong. 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> <?php include "config01.php"?> <form name = 'form1' method = 'post' action='config01.php'> <table width="700" border="1" cellspacing="5" cellpadding="5"> <caption> Submit Your Airfield Details </caption> <tr> <td width="100"> </td> <td width="200">Your Name</td> <td width="200"><input type='text' name='username' maxlength='30'></td> <td width="100"> </td> </tr> <tr> <td> </td> <td>Height Above MSL</td> <td><input type='text' name='height_above'maxlength= '30'></td> <td> </td> </tr> <tr> <td> </td> <td>Mb Difference</td> <td><input type='text' name='mb_diff'maxlength='40'></td> <td> </td> </tr> <tr> <td> </td> <td>Alternative Airfield</td> <td><input type='text' name='alternative' maxlength='30'></td> <td> </td> </tr> <tr> <td> </td> <td>PPR</td> <td><input type='radio' name='ppr' value="Y"/> Yes <input type='radio' name='ppr' value="N" /> No</td> <td> </td> </tr> <tr> <td><input type='submit' name='submit' value='post' /></td> <td> </td> <td> </td> <td> </td> </tr> </table> </form> </body> </html> Then the code from config01.php Code: [Select] <?php $host = 'localhost'; $usr = "VinnyG"; $password = 'thepassword'; $db_name = 'sitename'; $username = $_POST["username"]; $height_above = $_POST["height_above"]; $mb_diff = $_POST["mb_diff"]; $alternative = $_POST["alternative"]; $ppr = $_POST["ppr"]; //connect to database mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error()); mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error()); /* $sql01 = "INSERT INTO users SET username = '$username',height_above = '$height_above', mb_diff = $mb_diff, alternative = $alternative"; $result=mysql_query($sql01); */ //mysql_query("INSERT INTO users VALUES ('$username','$height_above','$mb_diff','$alternative')"); //mysql_query("INSERT INTO users (username, height_above, mb_diff, alternative) VALUES ('$username', '$height_above', '$mb_diff', '$alternative'"); //$insert_query = "INSERT INTO users (username, height_above, mb_diff, alternative) VALUES ('$username', '$height_above', '$mb_diff', '$alternative')"; //$insert_action = mysql_query($insert_query) or die ('Error Dring Insert :<br>'.mysql_error().'<br><br>Error occured running the following code :<br>'.$insert_query); //mysql_query("INSERT INTO users VALUES ('$username','$height_above','$mb_diff','$alternative')"); CHANGES FOLLOW THIS LINE . . $query = "INSERT INTO users (username, height_above, mb_diff, alternative, ppr) VALUES ('$username', '$height_above', '$mb_diff', '$alternative', '$ppr'"; if( !$result = mysql_query($query) ) { echo "<br>Query: $query<br>Produced error: " . mysql_error() .'<br>'; } else { echo "Query ran and inserted " . mysql_affected_rows() . "row(s)."; } ?> I only added the one thing and I've gone and broken it already. It was working last night too.. :-( Hello there, I'm using a Mac (10.5. and installed MAMP for PHP and MYSQL I trying to build a blog. I just setup a database in phpmyadmin. I created a php and start coding, everything works just fine, but when I tried to connect to the mysql it gives me a blank page I inserted this code Code: [Select] <?php session_start(); $connect = mysql_connect('localhost','root', 'root'); or die(mysql_error()); $db = mysql_select_db('blog',$connect); $session_name = $_SESSION['uid']; ?> but then the whole page turns to be blank page , but when I excluded this, it works just fine. I don't get it cause my database/phpmyadmin connected just fine. Any help is much appreciated. Been trying to figure this out for hours. Hello all, This is my first post in here, so go easy. I recently transferred my account from my local ISP to GoDaddy. And now my search criteria is not working. I am getting the follow error message on the page of my search box, instead of the graphics itself: Could not connect to MySQL:Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) I thought maybe this would be a simple error when I found out that GoDaddy does not use the "localhost" connect string. So I switched it to the local IP for GoDaddy still to no avail. I am lost after that. My PHP skills are limited. I was taught by a very advanced user who uses shortcuts and different strings self made for his ease. So looking online for solutions for the script was very hard(to me at least), because the lines of code do not match common scripts online. Is this a simple solution? Does the: global $dbc; @dbConnect(); function work with GoDaddy? Because I have seen maybe different ways to connect to a DB with PHP. Here's the script I am using to connect and extract results from the DB. Any and all help will be greatly appreciated. Thanks in advance. Using MySQL Version 4: <? @require("searchheader.php"); ?> <table cellpadding=10 cellspacing=0 border=0> <tr> <td align=left valign=top> <? displayMenu(); ?> </td> <td align=right valign=bottom> <? if($_GET["f_catid"]){ $num_cats = 5; for($i=1;$i<=$num_cats;$i++){ $where .= " or c".$i." = ".$_GET["f_catid"]; } $where = substr($where,4,strlen($where)); $sql = "select * from product where ".$where." order by product_name ASC LIMIT 0,20"; dbConnect(); $result = mysql_query($sql,$dbc); ?> <div class="search_results_menu"> <form action="[url=http://www.nexpart.com/extpart.php?part=]http://www.nexpart.com/extpart.php?part=[/url]<?=$r["part_number"]?>&linecode=<?=$row[" manufacturer"] ?>" method="GET"><input type="text" name="quantity" size="2" value="0" style="text-align: center;"><input type="button" name="submit_top" value="Check Out"> </form> <table class="search_results_found" bgcolor="#efefef" cellpadding=3 cellspacing=0 border=1 bordercolor="#000000" style="border:1px solid #000000;"> <tr bgcolor="#efefef"> <td class="search_results_title"><b>Manufacturer</b></td> <td class="search_results_title"><b>Part Number</b></td> <td class="search_results_title"><b>Part Name</b></td> <td class="search_results_title"><b>Price</b></td> <td class="search_results_title"><b>Image</b></td> <td class="search_results_title"><b>Add to Cart</b></td> </tr> <? if(mysql_num_rows($result) > 0){ while($row = mysql_fetch_assoc($result)){ ?> <tr bgcolor="#efefef"> <td><?=$row["manufacturer"]?></td> <td><a href="[url=http://www.nexpart.com/extpart.php?part=]http://www.nexpart.com/extpart.php?part=[/url]<?=$row["part_number"]?>&linecode=<?=$row["manufacturer"]?>"><?=$row["part_number"]?></a></td> <td><?=$row["product_name"]?></td> <td>$<?=$row["price"]?></td> <td><a href="[url=http://www.wlpsr.com/images/]http://www.wlpsr.com/images/[/url]"<?=$row["part_number"]?>".jpg " onClick="window.open('/images/<?=$row["part_number"]?>.jpg', '<?=$row["part_number"]?>', 'toolbar=yes, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=yes, height=300, width=400'); return false">View</a></td> <td><form action="[url=http://www.nexpart.com/extpart.php?part=]http://www.nexpart.com/extpart.php?part=[/url]<?=$r["part_number"]?>&linecode=<?=$row["manufacturer"] ?>" method="GET"><input type="text" name="quantity" size="2" value="0" style="text-align:center;"> </form> </td> </tr> <? } } else{ ?> <tr> <td colspan=100 align="center"><b>No products in this category.</b></td> </tr> </table> <form action="[url=http://www.nexpart.com/extpart.php?part=]http://www.nexpart.com/extpart.php?part=[/url]<?=$r["part_number"]?>&linecode=<?=$row[" manufacturer"] ?>" method="GET"><input type="text" name="quantity" size="2" value="0" style="text-align: center;"><input type="button" name="submit_top" value="Check Out"> </form> </td> </tr> <? } ?> </td> </tr> </table> </div> <? } ?> <div class="form"> <form name="search" action="<? echo $_SERVER['PHP_SELF']; ?>" method="GET"> <input type="text" name="f_keywords" size="17" value="" maxlength="100"> <input type="image" src="gobutton.gif"> </form> </select> <br><br><br> <? $trimmed = trim(strip_tags($_GET["f_keywords"])); //Set the database access information as constants. if(strlen($trimmed) > 0){ define ('DB_USER', 'USERNAME'); define ('DB_PASSWORD', 'THEPASSWORD'); define ('DB_HOST', 'LOCALIP'); define ('DB_NAME', 'DBNAME'); define ('DB_TABLE', 'TABLE'); //Make the connection to the DB global $dbc; @dbConnect(); $query = "SELECT * FROM product WHERE manufacturer LIKE '%$trimmed%' OR part_number LIKE '%$trimmed%' OR price LIKE '%$trimmed%' OR product_name LIKE '%$trimmed%' order by manufacturer"; $result = mysql_query($query); $count = mysql_numrows($result); if ($trimmed == "") { echo "Please enter a search criteria..."; exit; } // check for a search parameter if (!isset($result)) { echo "<p>Please enter a search parameter!</p>"; exit; } $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>We are sorry <b>$trimmed</b> has returned zero results.</p></font>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $result = mysql_query($query,$dbc); if($numrows < 1){ $return= "results";} else{ $return = "result"; } if($numrows > 1){ $return = "results";} else{ $return = "result"; } // display what the person searched for echo "Your search for ", " <b>$trimmed</b> ", " found <br><b>$numrows $return.</b>"; // begin to show results set $count = 1 + $s ; } if(strlen($trimmed) > 0){ ?> </div> <div class="search_results"> <table cellpadding=0 cellspacing=0 border=0> <tr> <td align="right"> <form action="[url=http://www.nexpart.com/extpart.php?part=]http://www.nexpart.com/extpart.php?part=[/url]<?=$r["part_number"]?>&linecode=<?=$row[" manufacturer"] ?>" method="GET"><input type="text" name="quantity" size="2" value="0" style="text-align: center;"><input type="button" name="submit_top" value="Check Out"> </td> </tr> <tr> <td> <table class="search_results_found" bgcolor="#efefef" cellpadding=3 cellspacing=0 border=1 bordercolor="#000000" style="border:1px solid #000000;"> <tr> <td width="100" class="search_results_title" align="center"> Manufacturer </td><td width="70" class="search_results_title" align="center"> Part Num. </td><td width="115" class=" search_results_title" align="center"> Description </td><td width="60" class="search_results_title" align="center">Price</td><td width="45" class=" search_results_title" align="center"> Image </td><td width="105" align="center"><b>Add to Cart</b> </td> </tr> </td> </tr> <? while ($r= mysql_fetch_array($result)) { $manufacturer = $r["manufacturer"]; $part_number = $r["part_number"]; $product_name = $r["product_name"]; $price = $r["price"]; $count++; echo "<tr><td>$manufacturer</td><td>"; echo "<a href=\"[url=http://www.nexpart.com/extpart.php?part=]http://www.nexpart.com/extpart.php?part=[/url]".$r["part_number"]."&linecode=".$r["manufacturer"]."\">".$r["part_number"]."</a></td><td>"; echo "$product_name</td><td>"; echo "$ $price</td><td>"; echo "<a href=\"[url=http://www.wlpsr.com/images/]http://www.wlpsr.com/images/[/url]".$r["part_number"].".jpg \" onClick=\"window.open('/images/".$r["part_number"].".jpg', '".$r["part_number"]."', 'toolbar=yes, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=yes, height=300, width=400'); return false \">View</a></td><td>"; echo "<form action=\"[url=http://www.nexpart.com/extpart.php?part=]http://www.nexpart.com/extpart.php?part=[/url]".$r["part_number"]."&linecode=".$r["manufacturer"]."\" method=\"GET\"><input type=\"text\" name=\"quantity\" size=\"2\" value=\"0\" style=\"text-align:center;\"></td></tr>"; } ?> </table> <tr> <td align="right"> <form action="[url=http://www.nexpart.com/extpart.php?part=]http://www.nexpart.com/extpart.php?part=[/url]<?=$r["part_number"]?>&linecode=<?=$row[" manufacturer"] ?>" method="GET"><input type="text" name="quantity" size="2" value="0" style="text-align: center;"><input type="button" name="submit_bottom" value="Check Out"> </td> </tr> <? } ?> </table> <br><br> </div> <? @require("footer3.php"); ?> Mod edit: [code] . . . [/code] tags added. Hi, I have a script which uses a connect file but I am struggling to get files in other folders to read and for the "$loggedIn = checkLogin();" code to work. If I connect to the database within the same script it works straight away. If I change my password then I have to change every file but otherwise I cannot include the connect file as I have to link to it locally. So if the connect file is in: www.domain.co.uk/php/login/connect.php then www.domain.co.uk/php/login/index.php -- this works www.domain.co.uk/php/logout.php -- this doesn't regardless of how I link to the connect file. hi all First of all My client have dot net server on windows OS. They want to display some pages which are created by php. Is there any possibility to display like this. And How can i connect sql server using php on remote to retrieve data. Can any one tell me how can i do this. Thanks in advance I have a simple form and I run my script without any errors. I click my btn and I would like to see my echo errors but no errors show up when I have no value in textboxes. I have tried if(isset($_Post["submit"])) and if($_SERVER["REQUEST_METHOD"] == "post") What I think is nether of there ifs are becoming valid on my btn click. <?php $nameerror = $twoerror = $errormsg = ""; // PHP Procedural MYSQLi // connect to mysql database with phpmyadmin $servername = "localhost"; $username = "root"; $password = "password"; $dbname = "test"; $connection = new mysqli($servername, $username, $password, $dbname); //if(isset($_Post["submit"])) if($_SERVER["REQUEST_METHOD"] == "post") { if(empty(trim($_Post["name"]))) { $nameerror = "Name is required"; } else { $namesafe = mysqli_real_escape_string($connection, $_Post["name"]); } if(empty(trim($_Post["two"]))) { $twoerror = "Two is required"; } else { $twosafe = mysqli_real_escape_string($connection, $_Post["two"]); } if($namesafe != "" && $twosafe != "") { $sqlInsert = "INSERT INTO tester(name, two) " . "VALUES('". $namesafe ."','". $twosafe ."')"; if(mysqli_query($connection, $sqlInsert)) { echo "Successfully entered."; } else { echo "NOT successful error: " . $sqlInsert . "<br>" . mysqli_error($connection); } } } mysqli_close($connection); ?> <?php if(!$connection) { die("Connection Failed! " . mysqli_connect_error()); } echo "Connected Successfully@!"; ?> <section class="text-align" id="section-content"> <div id="alertMessages" class="container rounded"></div> <div id="contentdiv" class="container rounded"> <form id="formtest" class="rounded" method="post" > <!-- action="" --> <h3>PHP Create</h3> <?php if(isset($errormsg)) { // echo "<div><span>"; echo $errormsg; // echo "</span></div>"; } ?> <div> <div class="form-group"> <input type="text" class="form-control" id="txtName" name="name" /> <label for="txtName">Name </label> <?php if(isset($nameerror)) { echo '<span class="error">' . $nameerror . '</span>'; } ?> <!-- ? php//if(isset($_Post["name"])) echo htmlspecialchars($_Post["name"]); ? >" /> ---> <!-- <span class="error"><?php //echo $nameerror; ?></span> --> </div> <div> <input type="text" class="form-control" id="txttwo" name="two" /> <label for="txttwo">Text Two </label> <?php if(isset($twoerror)) { echo '<span class="error">' . $twoerror . '</span>'; } ?> </div> </div> <button type="submit" class="btn btn-lg btn-primary btn-block" name="submit">Click</button> </form> </div> </section>
|