PHP - Mysql_query() Failure
I've got a very simple script that records IP address of every page view. Here is the script:
$ip = $_SERVER['REMOTE_ADDR']; $query = "INSERT INTO tracking VALUES ('', '1', '$ip')"; echo $query; echo ("<hr>"); if (mysql_query($query)) { echo ("INSERT OK"); } else { echo ("INSERT failed"); } FYI: the 1st value is "auto_increment" in the DB, therefore blank ('') in the query string, and the 2nd value "1" is just for the page number 1, as this script will be on other pages, with different numbers. Now, when I go to this page, it outputs the query, and hr, and then "INSERT failed" and sure enough, no record gets added to the DB. The strangest thing is, is that when I copy the query that the page shows, and paste it into mysqlPHPadmin's "SQL" section and run it, it executes fine, and a record gets added to the DB, however the page is unable to do that. Any ideas? PS: the connection (which I didn't paste in here) is fine, that's definitely not the problem. Similar TutorialsI'm not sure what I am doing wrong but I am attempting to create a hook system that I can use with modules... Could someone please take a look at the code and point me in the right direction? I've never really dealt with OOP so please be detailed in your response. There are no errors, it's just not working as expected. <?php new System(); class System { public function __construct() { $this->admin = new Admin( &$this ); } public function add_hook( $tag, $method, $class ) { $this->hooks_added[$tag][] = array( 'method' => $method, 'class' => $class ); } public function do_hook( $tag, $msg ) { if( !isset( $this->hooks_registered[$tag] ) ) $this->hooks_registered[$tag] = $msg; else $this->fatal_error( "1002." . __LINE__, "Duplicate hook tags defined." ); if( isset( $this->hooks_added[$tag] ) && is_array( $this->hooks_added[$tag] ) ) { foreach( $this->hooks_added[$tag] as $hook ) { $hook['class']->$hook['method'](); } } } public function fatal_error( $num = "Undefined", $title = "Undefined", $msg = "Undefined" ) { $html = 'Error ' . $num . ': ' . $title; echo $html; } } class Admin { public $_system; public $admin_menu = array( 0 => array( "name" => "Link 1", "params" => "a=link1" ), 5 => array( "name" => "Link 2", "params" => "a=link2" ) ); public function __construct( $_system ) { $this->_system = $_system; $this->dashboard = new Dashboard( &$_system ); $this->build_menu(); } private function build_menu() { $this->_system->do_hook( "admin_menu", "Modify the administrative menu." ); ksort( $this->admin_menu ); $html = '<ul>'; foreach( $this->admin_menu as $link ) { $html .= '<li>' . $link['name'] . '</li>'; } $html .= '</ul>'; echo $html; } public function add_menu_item( $name, $params, $sort ) { if( isset( $this->admin_menu[$sort] ) ) { $this->add_menu_item( $name, $params, (int) $sort + 1 ); } else { $this->admin_menu[$sort] = array( "name" => $name, "params" => $params ); } } } class Dashboard extends Admin { public $_system; public function __construct( $_system ) { $this->_system = $_system; $this->_system->add_hook( "admin_menu", "custom", &$this ); } public function custom() { $this->add_menu_item( "Dashboard", "a=dashboard", 0 ); } } ?> Thanks I am working on an e banking web app. So i was stuck on the transferring to the same bank page.. I have spent a lot of time to check where the errors are to no avail. The issue is the code doesnt work it gives a blank page... This is 12.php for the post action
<?php
if(!isset($_SESSION['login'])) f (isset($_POST['transfer'])) {
$db['db_host'] = "localhost";
foreach($db as $key => $value){ $connection = mysqli_connect(DB_HOST, DB_USER,DB_PASS,DB_NAME);
$query = "SET NAMES utf8";
if(!$connection) {
send query
//check query
$lastname = $_POST['lastname'];
if($rfirstname !== $firstname && $rlastname !== $lastname && $rmiddlename !== $middlename && $raccountNumber !== $account_number)
echo'<script>swal.fire("FAILED!!", " The Account Number doesnt match the Account Name. Check Well", "error");</script>';
if($totalTrans > $row5['balance']) }
}//while balance $transLimit = $row6['transLimit']; $acctype = $row6['acctype'];
}// end of while transLimit
$sqla = "SELECT * FROM customer WHERE username = '".$SESSION['login']."'";
if($otp !== $rowa['otp'])
$sqlc = "SELECT * FROM customer WHERE username = {$username}";
$time_now = strtotime($otpTime);
if($rfirstname == $firstname && $rlastname == $lastname && $rmiddlename == $middlename && $raccountNumber == $account_number && $totalTrans < $transLimit && $totalTrans <= $row['balance'] && $otp == $row['otp'] && (time() - $time_now < 3 * 60))
$sql10 = "update customer set balance = $balance + $transAmount
$db_username = $rowf['username'];
$msg = " <!DOCTYPE html><body>Dear <h1> $db_username, </h1>
$headers = "";
$status1 = '<button class="button">CREDIT</button>'; $status2 = '<button class="button2">DEDIT</button>';
$sqlm = "SELECT * FROM customer WHERE username = {$username}";
$sql11 = "insert into transactions where account_number = '$raccountNumber'
// $result11 = $connection->query($sql11);
$sql12 = "insert into transactions where username = '$username'
$result12 = mysqli_query($connection, $sql12);
}//end of ehile
$firstname = $row15['firstname'];
$sql16 = "SELECT * FROM customer WHERE account_numberr = $raccountNumber ";
$msg = " <!DOCTYPE html><body>Dear <h1> $rfirstname $rlastname $rmiddlename </h1>
$headers = "";
}//end while 1 }
}//while
Then my html form in transfer.php is <form method="POST" class="form-horizontal mt-4" action="">
<div class="form-group">
<div class="form-group">
<div class="form-group">
<div class="form-group">
<div class="form-group row">
<div class="form-group mt-2 mb-0 row">
</form> </div> I will be glad if u can help me. Thanks in advance
My code is a total failure. Any ideas? <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"] ["size"] < 4000000)) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />That means your picture is not right somehow...<br />"; } else { $i=1; while($i<=5000) { if (file_exists("./photos/" $POST['lname'] . "_" . $i . "_" . $_FILES["file"]["name"]])) { $i++; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "photos/" $POST['lname'] . "_" . $i . "_" . $_FILES["file"]["name"]); $i=5000; } } } else { echo "Invalid file... Only 4MB and jpeg/gifs allowed."; } $con = mysql_connect( 'localhost', 'root', 'password') if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("submition", $con) $sql = "INSERT INTO 'submition' ('fname','lname','address1','address2','city','stat_prov_reg','postal_zip','country','email','newsletter') VALUES ('"$POST['element_1_1']."' , '"$POST['element_1_2']."' , '"$POST['element_2_1']."' , '"$POST['element_2_2']."' , '"$POST['element_2_3']."' , '"$POST['element_2_4']."' , '"$POST['element_2_5']."' , '"$POST['element_2_6']."' , '"$POST['element_3']."' , '"$POST['element_7']."')"; mysql_query($sql) or die('Bad Query'); mysql_close($con); ?> <div align="center"> - <a href="http://apps.facebook.com/fourxfourexperience/'>Go Back</a> - </div> Upon testing my PayPal IPN script, the paypal payment was recieved from payer to buyer, however the IPN script did not go any further than line 17... and therefore did not log any of the payment info into the designated mysql table, nor did it update anything else. The following error was logged in the "error_log": Quote PHP Warning: fsockopen() [<a href='function.fsockopen'>function.fsockopen</a>]: unable to connect to ssl://www.paypal.com:443 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in /home/mysite/public_html/paypal_listener.php on line 17 This is the line in question on my IPN script: $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); Completely new ground to me, but do i need to be getting the admins who host my site to enable this? I read somewhere that: Quote The PHP function fsockopen() may not work because of firewall restrictions on the outgoing connections. Any light on the issue would be brilliant here, bit lost. I'm writing a Dynamic image, that display's a user's Name, but for some reason, the kills stat won't print. I made a .php file using the same parsing method, but using echo, and it worked fine. I also know it's not an issue with X,Y, Size, float, anything like that because I tried replacing "$kill" with "Test," and it printed fine. Here is the actual image: And here is the code for it: <?php Header ('Content-type: image/jpeg'); Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); Header('Expires: Thu, 19 Nov 1981 08:52:00 GMT'); Header('Pragma: no-cache'); // get CMID variable from the url $cmid = $_GET['cmid']; // create the image using your own background $image = imagecreatefromjpeg("background.jpg"); // dimensions of the image used $img_width = 600; $img_height = 9; // set the colours $cool = imagecolorallocate($image, 81, 86, 96); $black = imagecolorallocate($image, 0, 0, 0); $white = imagecolorallocate($image, 255, 255, 255); $red = imagecolorallocate($image, 255, 0, 0); $grey = imagecolorallocate($image, 204, 204, 204); $green = imagecolorallocate($image, 206, 129, 18); $blue = imagecolorallocate($image, 0, 0, 255); $yellow = imagecolorallocate($image, 225, 225, 0); // set the font and print text $font = 'Verdana.ttf'; /* // counter - CHMOD your counter file to 777 $viewss = file("views.txt"); $views = $viewss[0]; $views++; $fp = fopen("views.txt", "w"); fwrite($fp, $views); fclose($fp); $counter = "$views"; // View Output imagettftext($image, 7, 0, 16, 117, $yellow, $font, "Views:$counter"); */ // Attempt to make web content grabber. function get_url_contents($url){ $crl = curl_init(); $timeout = 5; curl_setopt ($crl, CURLOPT_URL,$url); curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); $ret = curl_exec($crl); curl_close($crl); return $ret; } // Web content grabber execution. $returned_content = get_url_contents('http://uberstrike.cmune.com/Profile?cmid=' . $cmid); // Parsing the returned content for Clan Tag. $namestart = strpos($returned_content, '<span style="color: #FEC42C; font-size: 20px; font-weight: bold;">'); $nameend = strpos($returned_content, '</span>', $namestart); $name = substr($returned_content, $namestart, $nameend-$namestart); // Stripping the parsed Clan Tag of HTML elements. $name = html_entity_decode(strip_tags($name)); // Clan and name output. imagettftext($image, 7, 0, 53, 7, $yellow, $font, "$name"); // Parsing the returned content for Global Rank. $rankstart = strpos($returned_content, '<h2 style="font-size:14px; font-weight:bold; text-indent:0px; margin-left:25px;">'); $rankend = strpos($returned_content, '<br />', $rankstart); $rank = substr($returned_content, $rankstart, $rankend-$rankstart); // Stripping the parsed Global Rank of HTML. $rank = html_entity_decode(strip_tags($rank)); // Filtering Rank to only show the value number, not text or formatting in between. $rank = str_replace ("G", "", $rank); $rank = str_replace ("l", "", $rank); $rank = str_replace ("o", "", $rank); $rank = str_replace ("b", "", $rank); $rank = str_replace ("a", "", $rank); $rank = str_replace ("R", "", $rank); $rank = str_replace ("n", "", $rank); $rank = str_replace ("k", "", $rank); $rank = str_replace (":", "", $rank); $rank = str_replace (" ", "", $rank); // Rank Output. imagettftext($image, 7, 0, 220, 7, $yellow, $font, "$rank"); $killstart = strpos($returned_content, '<h3 style="color: #FEC42C;">All time record</h3>'); $killend = strpos($returned_content, '</tr>', $killstart); $kill = substr($returned_content, $killstart, $killend-$killstart); // Stripping the parsed kill of HTML. $kill = html_entity_decode(strip_tags($kill)); // Filtering kill to only show the value number, not text or formatting in between. $kill = str_replace ("K", "", $kill); $kill = str_replace ("i", "", $kill); $kill = str_replace ("l", "", $kill); $kill = str_replace ("A", "", $kill); $kill = str_replace ("t", "", $kill); $kill = str_replace ("m", "", $kill); $kill = str_replace ("e", "", $kill); $kill = str_replace ("r", "", $kill); $kill = str_replace ("o", "", $kill); $kill = str_replace ("d", "", $kill); $kill = str_replace ("c", "", $kill); $kill = str_replace ("s", "", $kill); $kill = str_replace (" ", "", $kill); // Kill Stats output. imagettftext($image, 7, 0, 410, 7, $yellow, $font, "$kill"); // IP Logger $logfile= 'iplog.html'; $IPlog = $_SERVER['REMOTE_ADDR']; $logdetails= date("F j, Y, g:i a") . ': ' . '<a href=http://www.ip2location.com/demo.aspx?ip='.$_SERVER['REMOTE_ADDR'].'>'.$_SERVER['REMOTE_ADDR'].'</a>'; $fplog = fopen($logfile, "a"); fwrite($fplog, $logdetails); fwrite($fplog, "<br>"); fclose($fplog); // output and destroy imagepng($image); imagedestroy($image); ?> I tried using the same parsing code for the $kill stat, and it works fine: http://dynfosig.com/Phoenix_uploads/clangadget/Test.php?cmid=563853 <?php // get CMID variable from the url $cmid = $_GET['cmid']; function get_url_contents($url){ $crl = curl_init(); $timeout = 5; curl_setopt ($crl, CURLOPT_URL,$url); curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); $ret = curl_exec($crl); curl_close($crl); return $ret; } $returned_content = get_url_contents('http://uberstrike.cmune.com/Profile?cmid=' . $cmid); $killstart = strpos($returned_content, '<h3 style="color: #FEC42C;">All time record</h3>'); $killend = strpos($returned_content, '</tr>', $killstart); $kill = substr($returned_content, $killstart, $killend-$killstart); // Stripping the parsed kill of HTML. $kill = html_entity_decode(strip_tags($kill)); // Filtering kill to only show the value number, not text or formatting in between. $kill = str_replace ("K", "", $kill); $kill = str_replace ("i", "", $kill); $kill = str_replace ("l", "", $kill); $kill = str_replace ("A", "", $kill); $kill = str_replace ("t", "", $kill); $kill = str_replace ("m", "", $kill); $kill = str_replace ("e", "", $kill); $kill = str_replace ("r", "", $kill); $kill = str_replace ("o", "", $kill); $kill = str_replace ("d", "", $kill); $kill = str_replace ("c", "", $kill); $kill = str_replace ("s", "", $kill); $kill = str_replace (" ", "", $kill); // Kill Stats output. echo $kill; ?> * Moderator Note: Please do not remove code snippets from the question. echo(" <form method = \"get\" action = \"DeleteApp.php?pname=\" . $Applications['Name'] . \"> <input value='Delete' type='submit' /> </form> "); Why is this redirecting to: DeleteApp.php?. Instead of what you can obviously see what it's supposed to redirect to. After working with the sample imagecreatefromjpeg provided in the PHP manual, I successfully got a result (after clearing my cache) from Quoteimagecreatefromjpeg($im, $file); I've gotten a good education after navigating this function over the past week, and loaded it with ECHO messages to give me insight. Everything was going fine. And then, this ONE test image came along. Apparently, the image (which is as good aj peg as I can find) FAILS the if(!im) test. When I used echo $im; i discovered that when images pass through the function, they receive a "Resource" name. Images that FAIL are NOT named. This image gets a Resource name, yet FAILS. Is there a problem with my logic? A problem with the image? What would cause this? How can I verify? I will provide the code. Im working on my script which updates a row of data in a mysql DB, the update command doesnt have all of the fields.(I don't know if this is failing it or not?) The code for the form is. <?php include("../scripts/dbconnect.php"); mysql_select_db("rdb")or die("cannot select DB"); $sql="SELECT * FROM wo WHERE won='1'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <form name="form1" method="post" action="updatewo1.php"> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"> </td> <td align="center"><strong>WON</strong></td> <td align="center"><strong>CName</strong></td> <td align="center"><strong>CEmail</strong></td> </tr> <tr> <td> </td> <td align="center"><input name="name" type="text" id="name" value="<?php echo $rows['won']; ?>"></td> <td align="center"><input name="lastname" type="text" id="lastname" value="<?php echo $rows['cname']; ?>" size="15"></td> <td><input name="email" type="text" id="email" value="<?php echo $rows['cemail']; ?>" size="15"></td> </tr> <tr> <td> </td> <td><input name="id" type="hidden" id="id" value="<?php echo $rows['won']; ?>"></td> <td align="center"><input type="submit" name="Submit" value="Submit"></td> <td> </td> </tr> </table> </td> </form> </tr> </table> <?php mysql_close(); ?> The page the action goes to is below. <?php include("../scripts/dbconnect.php"); mysql_select_db("rdb")or die("cannot select DB"); $sql="UPDATE wo SET won='$_POST[won]', cname='$_POST[cname]', cemail='$_POST[cemail]' WHERE won = '$_POST[won]'"; $result = mysql_query($sql); if($result){ echo "Successful"; } else { echo "ERROR"; } ?> I am fairly new to PHP, any help would be greatly appreciated. I will list all of the Mysql table's fields below. won,wopword,status,dws,problem,dfin,cost,service,coupon,lmao1,lmao2,cname,caddy,cemail,cphone,compinfo,techname,comments,storeloc,clerk,solution OK so I'm having a pull my hair out moment. I have spent all day trying to figure this out. I have a select box for a list of customers where one customer is unique and I want that account to appear twice in the list. That part was easy and when selected the appropriate info populates the page. The problem I am having is that no matter which one of those two options I click it only selects the second option . So in other words if these are the two options in the list: Some Business Week 1 Some Business Week 2 when I click either, Some Business Week 2 is always the one selected even though the page populates correctly. Any thoughts on what I need to change? Code: [Select] <?php do { mysql_select_db($database_customers, $customers); $query_multiple = "SELECT accnt, week, alt FROM schedule WHERE accnt = " . $customer['accnt']; $multiple_sel = mysql_query($query_multiple, $customers) or die(mysql_error()); $multiple = mysql_fetch_assoc($multiple_sel); $multiple_run = $multiple['alt']; if($multiple_run > 1) { for ($i = 1; $i <= $multiple_run; $i++) { mysql_select_db($database_customers, $customers); $query_get_week = "SELECT week, alt FROM schedule WHERE accnt = " . $customer['accnt'] . " AND alt = " . $i; $get_week_sel = mysql_query($query_get_week, $customers) or die(mysql_error()); $get_week = mysql_fetch_assoc($get_week_sel); $version1 = $inv_title . " Week " . $get_week['week']; $version2 = $customer['name'] . " Week " . $get_week['week']; ?> <option value="report.php?accnt=<?php echo $customer['accnt']; ?>&alt=<?php echo $get_week['alt'];?>"<?php if (!(strcmp($version1, $version2))) {echo "selected=\"selected\"";} ?>><?php echo $version2; ?></option> <?php } } else { $version1 = $inv_title; $version2 = $customer['name']; ?> <option value="report.php?accnt=<?php echo $customer['accnt']; ?>&alt=<?php echo $multiple['alt'];?>"<?php if (!(strcmp($version1, $version2))) {echo "selected=\"selected\"";} ?>><?php echo $version2; ?></option> <?php } ?> <?php } while ($customer = mysql_fetch_assoc($customer_sel)); ?> This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=352833.0 Hi all, I have a session problem on my development site. Whenever I go to my login screen at www.mydomain.com/my/path/index.php, i get the following error messages: Quote Warning: session_start() [function.session-start]: open(/tmp/sess_f89c3850adf5a752b13f5c6b9022d8c4, O_RDWR) failed: Permission denied (13) in /home/account/public_html/shop_lite/admin/index.php on line 2 Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/account/public_html/shop_lite/admin/index.php:2) in /home/account/public_html/shop_lite/admin/index.php on line 2 However, when I go to mydomain.com/my/path/index.php, the error messages aren't there. I am very confused. We don't have an SSL (which google suggested it could be) or any whitespace between the opening php tag. I have chmoded the /tmp directory to 777 but to no avail. Any ideas? My opening code is below: Code: [Select] <?php session_start(); require_once("includes/db_connector.php"); include("includes/cms_class.php"); include("includes/login_class.php"); loginForwarder(); $issue = checkLoginIssue(); if (isset($_POST["login"])) { loginUser($_POST["email"], $_POST["password"]); } ?> <!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"><!-- InstanceBegin template="/Templates/my_template.dwt.php" codeOutsideHTMLIsLocked="false" --> The script in question works perfectly on my WAMP installation. It is designed to help a computer-challenged historian publish to the web using text CSV files without her having to use FTP or edit html files. The largest data set is about 400KB. The script is using TEXTAREA form input and uploading via POST. Smaller files upload okay. The larger ones fail with a blank screen (empty html) and usually only a few hundred bytes missing. Example: 380KB data POST fails with 367KB stored on remote host. No error message is saved to the remote host directory. I suspected suhosin.post.max_value_length as it is set to 64K, but more than four times that amount is being stored on the remote host. Can suhosin.post.max_value_length still be the problem? The remote host is running: PHP 5.2.5 Apache 2.2.11 Linux O/S PHPINFO(): max_execution_time - 30 max_input_time - 60 memory_limit - 64M post_max_size - 16M upload_max_filesize - 16M suhosin.post.max_value_length - 65384 Any suggestions much appreciated. With the following code
<?php ?> There is still an error output of syntax error on line 11, please help, what's wrong with my code Hi and thank you for reading my topic.
I'm building a search engine from a tutorial and I'm getting the famous "Warning: mysql_num_rows() expects parameter 1" boolean etc..
I know mysql_num_rows() is depricated and I promise not to use it in the future but for now I'm using it in other projects on the same server and all's ok.
I'm quite sure it's a problem with the SQL syntax because when I paste SELECT * FROM searchengine WHERE keywords LIKE 'any_keyword_from_the_column' -into Phpmyadmin it won't return results, however a simple SELECT * FROM searchengine returns results.
So, without using mysql_error() I get: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\research2\search.php on line 42
But after I applyin mysql_error() to everything I narrowed it down to this: $query = mysql_query($query) or die (mysql_error());:
I get the error msg:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OR keywords LIKE 'search' OR keywords LIKE 'term'' at line 1
I've checked multiple times to see if I've left out any columns in the db or mismatched them in while loop.
Below I have included the code which you can paste into a file called search.php along with the mysql dump file to pase into phpmyadmin query box. I'm using xampp.
In the code the WHERE clause is extended into the if statement and concatenated into the $query variable. This is done to break the words in the text box so they can be searched as an array.
As I said, I really think it is the SQL syntax and not the mysql_* functions but I could be wrong.
I'd really like to get this code working and mess with it. It looks like it could be very useful as a private website search engine.
Thanks for your time and mental energy.
<html> <head> <title></title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> </head> <body> <h2>Search Engine</h2> <form action = './search.php ' method = 'get'> <input type = 'text' name = 'k' size = '50' value = '<?php echo $_GET['k']; ?>' /> <input type = 'submit' value = 'Search'> </form> <hr /> results <br> <?php $k = $_GET['k']; $terms = explode(" ", $k); $query = "SELECT * FROM searchengine WHERE "; foreach ($terms as $each) { $i = 0; if ($i == 1) $query .= "keywords LIKE '$each' "; else $query .= "OR keywords LIKE '$each' "; } mysql_connect("localhost", "root", "") or die (mysql_error()); mysql_select_db("search2") or die (mysql_error()); $query = mysql_query($query) or die (mysql_error()); $numrows = mysql_num_rows($query) ; if ($numrows > 0) { while ($row = mysql_fetch_assoc($query)) { $id = $row['id']; $title = $row['title']; $description = $row['description']; $keywords = $row['keywords']; $link = $row['link']; echo "<h2><a href='$link'>$title</a></h2> $description<br /><br />"; } } else echo $k ; ?> </body> </html>and here is the SQL dump (I called my db search2 and my table searchengine -- phpMyAdmin SQL Dump -- version 4.2.7.1 -- http://www.phpmyadmin.net -- -- Host: 127.0.0.1 -- Generation Time: Nov 27, 2014 at 11:54 AM -- Server version: 5.6.20 -- PHP Version: 5.5.15 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8 */; -- -- Database: `search2` -- CREATE DATABASE IF NOT EXISTS `search2` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci; USE `search2`; -- -------------------------------------------------------- -- -- Table structure for table `searchengine` -- CREATE TABLE IF NOT EXISTS `searchengine` ( `id` int(11) NOT NULL, `title` varchar(250) NOT NULL, `description` varchar(250) NOT NULL, `keywords` text NOT NULL, `link` varchar(250) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; -- -- Dumping data for table `searchengine` -- INSERT INTO `searchengine` (`id`, `title`, `description`, `keywords`, `link`) VALUES (1, 'Nick Frosty''s Official Web Site', 'Welcome to Nick''s', 'Nickfrosty Website tutorials videos web design', 'http://www.nickfrosty.com'), (2, 'Google search engine', 'The best search engine', 'google web site search ', 'http://www.google.oom'), (3, 'The Yahoo Search Engine', 'Not as good as Google', 'Yahoo search engine website', 'http://www.google.com'), (4, 'This is a test', 'This is a test website', 'Google', 'http://www.google.com'); -- -- Indexes for dumped tables -- -- -- Indexes for table `searchengine` -- ALTER TABLE `searchengine` ADD PRIMARY KEY (`id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `searchengine` -- ALTER TABLE `searchengine` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=5; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;If you have any questions about any details of this code please ask me. Thanks for your time from the customer so that I can record the transaction into my database seeing as the pay button is on paypal and not on my any of my site. I am getting a "mysqli_query() expects parameter 1 to be mysqli, null given" error. the code I am using is below but simplified. connect() does connect to the database without throwing any errors but when I get down to query() I get the above error. public function connect() { mysqli_connect(self::DBHOST, self::DBUSER, self::DBPASS, self::DBNAME); } public function query($query) { mysqli_query(self::connect(), $query); } below is what I am using to call the function. I am not sure if I have to pass the $link in the query function too. I have tried but it didn't seem to do any better. $link = db::connect(); $query = "SELECT name FROM plugins"; db::query($query); I am sure this is something simple that I have overlooked but I am new to this and still learning. Thank you for any help you can provide. OK So I have a quick question... how would I go about making a query like: mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND key='$key' "); You see, theres an error: Quote You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' key='1234' LIMIT 1' at line 1 I know this is a simple issue, and I know you cant keep creating AND's inside the query, but how would I do it? I've never attempted to use more than one AND before, so its new to me even though I'm a experienced PHP Developer. Thanks in advance! Hey Guys, Im having problems with my code. What im trying to do is run a mysql query and show the results, but if the query returns no data, echo out "No incoming requests!" Here is my code: <? $check = "SELECT * FROM requests WHERE club='" . $_SESSION['club'] . "' AND team='" . $_SESSION['team'] . "' AND accepted='0'"; $result=mysql_query($check); if (mysql_num_rows($result) == 0) { while ($getinfo = mysql_fetch_array($result)) { $time = $getinfo["time"]; $who = $getinfo["player_name"]; $whofor = $getinfo["toplayfor"]; $from = $getinfo["team"]; $idp = $getinfo["player_id"]; echo "<a href='profile.php?id=".$idp."&team=".$from."'>".$who." </a><div style='float:right;'>(".$from.")</div><br />"; echo "<div style='margin-top: 2px;'></div>"; echo date('l, F jS, g:ia',$time); echo "<br /><div style='margin-top: 2px;'></div><a href='accept.php?playerid=".$idp."&toplayfor=".$whofor."'>Accept</a> | Decline"; echo "<div id='newsline'></div>"; } } else { echo 'No incoming requests'; } ?> Could someone help me out here? Thanks Heaps! Hey guys, I've been playing around with this open source php game, I'm having problems with the registration system. For some reason the script is echoing back that there is no password in the password fields. When in fact there is: Add_player.php: Code: [Select] <?php session_start(); session_register("pid"); include("common.inc"); include("date.inc"); include("header.inc"); dbConnect(); $res = mysql_query("select id from $dbName.pdm_players where name=\"$name\"") or die(mysql_error()); if ($name == "" || $password1 == "") { echo "<center><div class=\"sheader\">Oh dear me!</div> You have to actually enter a name and password!"; $name = ""; include("character_form.inc"); echo "</center>"; include("footer.inc"); return 0; } if ($name == $password1) { echo "<center><div class=\"sheader\">Oh dear me!</div> You can't make the password the same as the name. People will guess your password!"; include("character_form.inc"); echo "</center>"; include("footer.inc"); return 0; } if (strlen($password1) < 6) { echo "<center><div class=\"sheader\">Oh dear me!</div> Passwords must be at least 6 characters, otherwise they are easy to guess!"; include("character_form.inc"); echo "</center>"; include("footer.inc"); return 0; } if (mysql_fetch_row($res)) { echo "<center><div class=\"sheader\">Oh dear me!</div> Player $name already exists, try a different name."; $name = ""; include("character_form.inc"); echo "</center>"; include("footer.inc"); return 0; } if ($password1 != $password2) { echo "<center><div class=\"sheader\">Oh dear me!</div>"; echo "The two passwords didn't match - type carefully now!."; include("character_form.inc"); echo "</center>"; include("footer.inc"); return 0; } echo "<div class=\"sheader\">Registration for $name successful</div>"; $cp = crypt($password1); $dateArray = getdate(time()); $likeNowScoob = $dateArray["year"] . "-" . $dateArray["mon"] . "-" . $dateArray["mday"]; if ($character < 1 || $character > 9) { die("you are an idiot"); } pdm_characters(); $res = mysql_query("select type from $dbName.pdm_characters where cid = $character") or die(mysql_error()); $t = mysql_fetch_row($res); pdm_stuff(); $specRes = mysql_query("select sid from $dbName.pdm_stuff where sid >= 28 and sid <= 33 and type like \"%$t[0]%\"") or die(mysql_error()); $res = mysql_query("BEGIN") or die(mysql_error()); $res = mysql_query("insert into $dbName.pdm_players (name, used, dob, cpass, char_id, roundswon, evo, aWeapon, dWeapon) VALUES (\"$name\", 1, \"$likeNowScoob\", \"$cp\", $character, 0,0,0,0)") or die(mysql_error()); $res = mysql_query("select id from $dbName.pdm_players where name=\"$name\" for update") or die(mysql_error()); $row = mysql_fetch_row($res); $pid = $row[0]; $res = mysql_query("insert into $dbName.pdm_league (id, highest, days_no_1, yesterday, longPoints) VALUES ($pid, 16777215, 0, 16777215, 0)") or die(mysql_error()); $res = mysql_query("insert into $dbName.pdm_stats (id, level, attack, defence, health, speed, exp, ko, healthpercent, fights) VALUES ($pid, 1, 100, 100, 100, 100, 0, 0, 10, 0)") or die(mysql_error()); $res = mysql_query("insert into $dbName.pdm_clanmembers2 (id, clanTag, applyTag, utype) VALUES ($pid, NULL, NULL, '')") or die(mysql_error()); $res = mysql_query("insert into $dbName.pdm_money (id, bank, wallet, bankdate) VALUES ($pid, 0,0, '0000-00-00')") or die(mysql_error()); while ($row = mysql_fetch_row($specRes)) { $res = mysql_query("insert into $dbName.pdm_specials (id, sid, qty, switch) values ($pid, $row[0], 0, 1)") or die(mysql_error()); } $res = mysql_query("COMMIT") or die(mysql_error()); session_register("playerName"); $playerName = stripper($name); echo "<P><diV>Welcome $playerName, click the Fight link down the left to fight your first opponent.</div>"; include("main_screen.inc"); include("footer.inc"); ?> Character_form.inc: Code: [Select] <center> <form method="post" action="add_player.php"> <P> <table cellpadding="0" cellspacing="0"><tr><td align="center"> <?php dbConnect(); pdm_characters();#check HEAP table exists $res = mysql_query("select cid, name, type from $dbName.pdm_characters order by type") or die(mysql_error()); $marker = "X"; $firstOne = 1; $cTypes["A"] = "Alien"; $cTypes["M"] = "Magic"; $cTypes["S"] = "Spirit"; while ($row = mysql_fetch_row($res)) { if ($marker != $row[2]) #new type (alien/magic etc) { if ($marker != "X") { echo "</table>\n"; } $cn = $cTypes[$row[2]]; echo "\n<table cellpadding=\"0\" cellspacing=\"0\" border=1> <tr><td colspan=\"3\" align=\"center\"><div class=\"sheader\"> $cn characters</div></td></tr><tr bgcolor=\"#efefef\">"; $marker = $row[2]; } echo "\n<td><table><tr><td align=center>$row[1]</td></tr><tr><td align=center> <img alt=\"Pick me!\" src=\"images/$row[0]0.gif\"></td></tr><tr> <td align=center><input type=\"radio\" name=\"character\" value=\"$row[0]\""; if ($firstOne and $character == "") { $firstOne = 0; echo " CHECKED "; } if ($character == $row[0]) { echo " CHECKED "; } echo "></td></tr></table></td>"; } echo "</tr></table> <table width=\"551\" cellpadding=0 cellspacing=0><tr><td colspan=\"3\"><div class=\"sheader\">character details</div></td></tr> <tr><td align=\"center\">Name<br><input size=20 maxlength=20 type=text name=\"name\" value = \"$name\"></td>"; ?> <td align="center">Password<br><input type="password" name="password1" size=20 maxlength=20></td> <td align="center">Password again<br><input type="password" name="password2" size=20 maxlength=20></td></tr> <tr><td colspan="3" align="center"><input type="submit" value="Register my character"></td></tr></table> </td></tr></table> <hr> </form> </centER> Anyone able to offer up any advice or where its going wrong, If I remove the validation stuff, it still doesn't insert the user into the database. Cheers |