PHP - Cant Figure Out Php/mysql Error
I am getting Fatal error: Uncaught Error: Call to a member function real_query() on null with this code: public final function Retrieve($TABLE, $CRIT){ $_query = "SELECT * FROM `{$TABLE}` WHERE "; foreach($CRIT as $_field => $info){ $_query .= " `{$_field}` = `{$info}` &&"; } if($this->LINK->real_query(rtrim($_query, ' &'))){ return $this->LINK->store_result(); } else{ return json_encode(array("Error"=>$this->LINK->errno(), "Description"=>$this->LINK->error())); } } (LINK is my mysql_connect() result.) I have tried everything i can think of, ->query, going to mysqli_query, breaking it sown and using a $result variable, but nothing seems to work... Edited March 29, 2019 by KaraethonSimilar TutorialsHi im still learning php and have been running through the tutorials on making a user authentication system but im getting an error on one line but ive got the same code else where and its fine... Code: [Select] // Must have at least one character if (strspn($_POST['user_name'],$span_str) == 0) { return false; } Im getting the error on the if statment but no matter what i try it still tells me theres an error... Heres the full function code: Code: [Select] function account_namevalid() { // parameter for use with strspan $span_str = "abcdefghijklmnopqrstuvwxyz" . "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-"; // Must have at least one character if (strspn($_POST['user_name'],$span_str) == 0) { return false; } // Must contain all legal characters if (strspn($_POST['user_name'],$span_str) != srnlen($name)) { return false; } // Min and Max length if ($strlen($_POST['user_name']) < 5) { return false; } if strlen($_POST['user_name']) > 25 { return false; } // Illegal names if (eregi("^((root)|(bin)|(deamon)|(adm)|(lp)|(sync)|(shutdown)|(halt)|(mail)|(news)|(uucp)|(operator)|(games)|(mysql)| (httpd)|(nobody)|(dummy)|(www)|(cvs)|(shell)|(ftp)|(irc)|(debian)|(ns)|(download)))$", $_POST['user_name'])) { return false; } if (eregi("^(anoncvs_)", $_POST['user_name'])) { return false; } return true; } Any help or info would be greatfull... Cheers Chris Can someone please give me some guidance on how to deal with the following warning Quote
Warning: move_uploaded_file(../usernet/img/60ff59c9f0a830.45733158.jpg): Failed to open stream: Permission denied in /opt/lampp/htdocs/site/admin/add_post.php on line 23 All directories and files in the path have full owner permissions and I've made myself the owner of them all (I'm on a linux system). I've also done the same with the /tmp folder. I can't even think of anything else to change and haven't found anything online that solves the issue. in case it's needed, the php is as follows: <?php require("assets/initializations.php"); if(isset($_POST['add_post']) && !empty($_FILES['post_image'])) { $filename = $_FILES['post_image']['name']; $file_tmp_name = $_FILES['post_image']['tmp_name']; $filesize = $_FILES['post_image']['size']; $file_ext = explode('.', $filename); $file_act_ext = strtolower(end($file_ext)); $allowed = array('jpeg', 'jpg', 'png', 'gif'); if(!in_array($file_act_ext, $allowed)) { header("Location: add_post.php?message=file_type_not_allowed"); } else { if($filesize > 10000000) { header("Location: add_post.php?message=file_too_large"); } else { $file_new_name = uniqid('', true) . "." . $file_act_ext; $dir = "../usernet/img/"; $target_file = $dir . basename($file_new_name); move_uploaded_file($file_tmp_name, $target_file); echo "<script>alert('Image uploaded successfully');</script>"; } } } I do get the javascript alert that's it's been successfully uploaded, but the image doesn't make it into the specified directory and I get the warnings at the top. I'm also, probably obviously from the path, using XAMPP server for development. TIA Fatal error: Cannot redeclare class MySQLDB in /home/xservers/public_html/skylar/VIP/include/database.php on line 14 Here is the code: Code: [Select] <?php if (!defined('INCLUDE_GUARD')) { header("Location: /errors/forbidden"); return; } include_once("incs/cls/DatabaseManager.class.php"); include_once("incs/cls/VariantTemplate.class.php"); class Core { private $_logger; private $_self_test_results; private $_config; private $_dbmgr; private $_vtemp; public __construct() // this is line 19 { $this->setupLogger(); $this->_self_test_results = array(); $this->_self_test_results['missing'] = array(); $this->_self_test_results['failed'] = array(); $this->_config = array(); $this->_dbmgr = null; $this->_vtemp = null; $this->selfTest(); } Here is the error I've been receiving. Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in /home/ditecha1/public_html/slick/incs/cls/SlickCMSCore.class.php on line 19 I am finding this error extremely weird, my host uses PHP 5.2.14. I was setting the private variables directly (without the assistance of the constructor), but I removed this and had the constructor set basic values to start with to see if this was the issue, but it wasn't. I've tried commenting out the include_once lines, since they are also in development I thought maybe an error was being carried over in to this file as the includes were happening, but still no change in the error message at all. Any help would be greatly appreciated! I hate header errors... I can never figure them out, im getting this error; Warning: Cannot modify header information - headers already sent by (output started at /home/damnpeti/public_html/restrict2.php:6) in /home/damnpeti/public_html/restrict2.php on line 62 Code: <?php $testDB = mysql_connect('localhost', $db_user, $db_pwd); mysql_select_db ($db_name); if (!$testDB) { die('Could not connect: ' . mysql_error()); } $surfer_ip = $_SERVER["REMOTE_ADDR"]; $str_sql = "select * from ".$db_table." where ipaddress='".$surfer_ip."'"; $result = mysql_query($str_sql); if ($row = mysql_fetch_assoc($result)) { $blocked_time = strtotime($row['blocked_time']); if($blocked_time != 0) { $current_time = time(); if($current_time - $blocked_time > 3600*24) //24 hours past { $str_sql = "delete from ".$db_table." where ipaddress='".$surfer_ip."'"; mysql_query($str_sql); $str_sql = "insert into ".$db_table." (ipaddress, surf_index) values('".$surfer_ip."', 1)"; mysql_query($str_sql); } else { die ("<center><div class='errors'>You have accessed this page too many times. To regain access, purchase a license or wait 24 hours.</div></center>"); } } else { if($row['surf_index'] < 2) { $str_sql = "update ".$db_table." set surf_index=surf_index+1 where ipaddress='".$surfer_ip."'"; mysql_query($str_sql); } else { $str_sql = "update ".$db_table." set blocked_time='".date ("Y-m-d H:i:s")."' where ipaddress='".$surfer_ip."'"; mysql_query($str_sql); die ("<center><div class='errors'>You have accessed this page too many times. To regain access, purchase a license or wait 24 hours.</div></center>"); } } } else { $str_sql = "insert into ".$db_table." (ipaddress, surf_index) values('".$surfer_ip."', 1)"; mysql_query($str_sql); } if(!isset($_COOKIE['surf_no'])) setCookie('surf_no', '1'); else setCookie('surf_no', $_COOKIE['surf_no']+1); if ($_COOKIE['surf_no'] > 2) die("<center><div class='errors'>You have accessed this page too many times. To regain access, purchase a license or wait 24 hours.</div></center>"); include 'http://damnitpetitions.com/cut/index3.php'; ?> Line 62 is if ($_COOKIE['surf_no'] > 2) I know it has something to do with the cookie... but Idk? I need the include there. If there include isnt where its at, the script is worthless. This is the code: <?php $Fname = $_POST["Fname"]; if (!isset($_POST['SUBMIT'])) { // if page is not submitted to itself echo the form ?> <html> <body> <head> <title>Personal INFO</title> </head> <body bgcolor="#008080"> <h1><blink><font color="#FF0000"><strong>Naruto Biography Creation</strong></font></blink></h1> <h3><font size="1" color="#0000FF">Please note, info with a (*) must be filled in!</h> </font> <form method="post" action="<?php echo $PHP_SELF;?>"> <p><font size="2"><b>*First Name:</b></font><input type="text" size="30" maxlength="12" name="Fname"><br /> <br /> <font size="2"><b>*Last Name:</b></font><input type="text" size="30" maxlength="36" name="Lname"><br /> <br /> <b><font size="2">*Gender:</font></b><br /> <input type="radio" value="Male" name="Gender" style="font-weight: 700"><b><font size="2">Male</font> </b><input type="radio" value="Female" name="Gender" style="font-weight: 700"><b><font size="2">Female</font></b></p> <p><b><font size="2">Background Info:</font></p> <textarea rows="3" cols="33" name="Background INFO" wrap="hard">Enter your Character's History</textarea><p><font size="2">Appearance:</font></p> <p> <textarea rows="3" cols="33" name="*Appearance" wrap="hard">State how your character look</textarea></p> <p><font size="2">Personality:</font><br/><span> <textarea rows="3" cols="33" name="*Personality" wrap="hard">Explain your Character's qualities, attitude, etc.</textarea></span></p> <p><span><br /></span> <font size="2">*Affiliation:</font><br /> <select name="Affiliation" size="3" width="8"> <option value="None" selected>Select one</option> <option value="Leaf">Leaf</option> <option value="Sand">Sand</option> <option value="Cloud">Cloud</option> <option value="Rogue">Rogue</option> </select><br /> <font size="2">*Rank:</font><br /> <select name="Rank" size="3" width="8"> <option value="none" selected>Select one</option> <option value="Gennin">Genin</option> <option value="Chuunin">Chuunin</option> <option value="Jounin">Jounin</option> <option value="S class">S class</option> </select> </p> <p> <input type="submit" value="submit" name="submit"></p> </form> </body> </html> <? } esle { echo "Hello,".$Fname." ".Lname.".<br />"; } ?> I get this all the time Quote Parse error: syntax error, unexpected $end in F:\wamp\www\index.php on line 78 I work on Wamp, and I am a beginner so I am totally lost could anyone help please I have been pulling my hair out for the lasy 3 hours i am trying to update a MySql table but i cant get it too work, i just keep getting MySql error #1064 - You have an error in your SQL syntax; if i just update 1 field it works fine but if i try to update more than 1 field it dosent work, Help Please! <?php $root = $_SERVER['DOCUMENT_ROOT']; require("$root/include/mysqldb.php"); require("$root/include/incpost.php"); $con = mysql_connect("$dbhost","$dbuser","$dbpass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("$dbame", $con); mysql_query("UPDATE Reg_Profile_p SET build='$build' col='$col' size='$size' WHERE uin = '$uinco'"); ?> does anyone know who to resolve this issue of importing a CSV file from excel into sql? I get this error when I do. LOAD DATA LOCAL INFILE '/tmp/phpq2aAbU' INTO TABLE `Events` FIELDS TERMINATED BY ',' ENCLOSED BY '\\"' ESCAPED BY '\\\\' LINES TERMINATED BY '\r\n' Error: Code: [Select] 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 '=1' at line 1 Code: Code: [Select] <?php session_start(); include "includes/connect.php"; include "includes/config.php"; if(isset($_SESSION['admin2'])){ include 'includes/getuserinfo.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" /> <title>Dashboard | Modern Admin</title> <link rel="stylesheet" type="text/css" href="css/960.css" webstripperwas="css/960.css" /> <link rel="stylesheet" type="text/css" href="css/reset.css" webstripperwas="css/reset.css" /> <link rel="stylesheet" type="text/css" href="css/text.css" webstripperwas="css/text.css" /> <?php if($acptheme == '') { echo '<meta http-equiv=Refresh content=0;url="nocss.php">'; } else { echo '<link rel="stylesheet" type="text/css" href="css/'.$acptheme.'.css" webstripperwas="css/<?php echo $acptheme ?>.css" />'; } ?> <link type="text/css" href="css/smoothness/ui.css" webstripperwas="css/smoothness/ui.css" rel="stylesheet" /> <script type="text/javascript" src="ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" webstripperwas="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script> <script type="text/javascript" src="js/blend/jquery.blend.js" webstripperwas="js/blend/jquery.blend.js" ></script> <script type="text/javascript" src="js/ui.core.js" webstripperwas="js/ui.core.js" ></script> <script type="text/javascript" src="js/ui.sortable.js" webstripperwas="js/ui.sortable.js" ></script> <script type="text/javascript" src="js/ui.dialog.js" webstripperwas="js/ui.dialog.js" ></script> <script type="text/javascript" src="js/ui.datepicker.js" webstripperwas="js/ui.datepicker.js" ></script> <script type="text/javascript" src="js/effects.js" webstripperwas="js/effects.js" ></script> <script type="text/javascript" src="js/flot/jquery.flot.pack.js" webstripperwas="js/flot/jquery.flot.pack.js" ></script> <![if IE]> <script language="javascript" type="text/javascript" src="js/flot/excanvas.pack.js" webstripperwas="js/flot/excanvas.pack.js" ></script> <![endif]> <![if IE 6]> <link rel="stylesheet" type="text/css" href="css/iefix.css" webstripperwas="css/iefix.css" /> <script src="js/pngfix.js" webstripperwas="js/pngfix.js" ></script> <script> DD_belatedPNG.fix('#menu ul li a span span'); </script> <![endif]> <script id="source" language="javascript" type="text/javascript" src="js/graphs.js" webstripperwas="js/graphs.js" ></script> </head> <body> <!-- WRAPPER START --> <div class="container_16" id="wrapper"> <!-- HIDDEN COLOR CHANGER --> <div style="position:relative;"> </div> <?php include 'inc/inc/logo.php'; include 'inc/inc/user.php'; ?> <!-- USER TOOLS END --> <div class="grid_16" id="header"> <!-- MENU START --> <div id="menu"> <ul class="group" id="menu_group_main"> <li class="item first" id="one"><a href="dashboard.php" class="main current"><span class="outer"><span class="inner dashboard">Dashboard</span></span></a></li> <li class="item middle" id="two"><a href="page.php" class="main"><span class="outer"><span class="inner content">Pages</span></span></a></li> <li class="item middle" id="three"><a href="#" class="main"><span class="outer"><span class="inner users">Users</span></span></a></li> <li class="item middle" id="four"><a href="#" class="main"><span class="outer"><span class="inner event_manager">Event Manager</span></span></a></li> <li class="item middle" id="five"><a href="#" class="main"><span class="outer"><span class="inner newsletter">Newsletter</span></span></a></li> <li class="item last" id="six"><a href="#" class="main"><span class="outer"><span class="inner settings">Settings</span></span></a></li> </ul> </div> <!-- MENU END --> </div> <div class="grid_16"> <!-- TABS START --> <div id="tabs"> <div class="container"> <ul> <li><a href="dashboard.html" class="current"><span>Dashboard elements</span></a></li> <li><a href="dash/news.php"><span>News</span></a></li> <li><a href="dash/topnews.php"><span>Top News</span></a></li> </ul> </div> </div> <!-- TABS END --> </div> <!-- CONTENT START --> <div class="grid_16" id="content"> <!-- TITLE START --> <div class="grid_9"> <h1 class="dashboard">Dashboard</h1> </div> <!--RIGHT TEXT/CALENDAR--> <div class="grid_6" id="eventbox"><a href="#" class="inline_calendar">You don't have any events for today! Yay!</a> <div class="hidden_calendar"></div> </div> <!--RIGHT TEXT/CALENDAR END--> <div class="clear"> </div> <!-- TITLE END --> <!-- #PORTLETS START --> <div id="portlets"> <!-- FIRST SORTABLE COLUMN START --> <div class="column" id="left"> <div class="portlet"> <div class="portlet-header">Insert News</div> <div class="portlet-content"> <p> </p> </div> </div> </div> <!-- FIRST SORTABLE COLUMN END --> <!-- SECOND SORTABLE COLUMN START --> <div class="column"> <!--THIS IS A PORTLET--> <div class="portlet"> <div class="portlet-header"><img src="images/icons/comments.gif" webstripperwas="images/icons/comments.gif" width="16" height="16" alt="Comments" />Change Theme</div> <div class="portlet-content"> <p class="info" id="success"><span class="info_inner">Change Theme To GEEN</span></p> <p class="info" id="error"><span class="info_inner">Change Theme To RED</span></p> <p class="info" id="info"><span class="info_inner">Change Theme To BLUE</span></p> </div> </div> <!--THIS IS A PORTLET--> <div class="portlet"> <div class="portlet-header"><img src="images/icons/feed.gif" webstripperwas="images/icons/feed.gif" width="16" height="16" alt="Feeds" />Current News </div> <div class="portlet-content"> <ul class="news_items"> <li>NEWS</li> <li>NEWS</li> <li>NEWS</li> <li>NEWS</li> <li>NEWS</li> </ul> <a href="#">» View all news items</a> </div> </div> </div> <!-- SECOND SORTABLE COLUMN END --> <div class="clear"></div> <!--THIS IS A WIDE PORTLET--> <div class="portlet"> <div class="portlet-header fixed"><img src="images/icons/user.gif" webstripperwas="images/icons/user.gif" width="16" height="16" alt="Latest Registered Users" /> Last Registered users Table Example</div> <div class="portlet-content nopadding"> <form action="" webstripperwas method="post"> <table width="100%" cellpadding="0" cellspacing="0" id="box-table-a" summary="Employee Pay Sheet"> <thead> <tr> <th width="34" scope="col"><input type="checkbox" name="allbox" id="allbox" onclick="checkAll()" /></th> <th width="136" scope="col">Name</th> <th width="102" scope="col">Username</th> <th width="109" scope="col">Date</th> <th width="129" scope="col">Location</th> <th width="171" scope="col">E-mail</th> <th width="123" scope="col">Phone</th> <th width="90" scope="col">Actions</th> </tr> </thead> <tbody> <tr class="footer"> <td colspan="4"><a href="#" class="edit_inline">Edit all</a><a href="#" class="delete_inline">Delete all</a><a href="#" class="approve_inline">Approve all</a><a href="#" class="reject_inline">Reject all</a></td> <td align="right"> </td> <td colspan="3" align="right"> </td> </tr> </tbody> </table> </form> </div> </div> <!-- END #PORTLETS --> </div> <div class="clear"> </div> <!-- END CONTENT--> </div> <div class="clear"> </div> <!-- This contains the hidden content for modal box calls --> <div class='hidden'> <div id="inline_example1" title="This is a modal box" style='padding:10px; background:#fff;'> <p><strong>This content comes from a hidden element on this page.</strong></p> <p><strong>Try testing yourself!</strong></p> <p>You can call as many dialogs you want with jQuery UI.</p> </div> </div> </div> <!-- WRAPPER END --> <!-- FOOTER START --> <div class="container_16" id="footer"> Website Administration by <a href="http://www.webgurus.biz" >WebGurus</a></div> <!-- FOOTER END --> </body> </html> <?php } else { echo 'You are not logged in as an administrator.'; } ?> Whats in Connect: Code: [Select] <?php include 'config.php'; DEFINE ('DB_HOST', DB_HOST); // This will most likely stay the same. DEFINE ('DB_USER', DB_USER); // Insert your database username into the quotes. DEFINE ('DB_PASSWORD', DB_PASSWORD); // Insert your database password into the quotes. DEFINE ('DB_NAME', DB_NAME);// Insert your actual database name in the quotes. $con = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); //$con = mysql_connect(':/tmp/mysql', $dbuser, $dbpass); mysql_select_db(DB_NAME ,$con); include 'functions.php'; if (isset($_SESSION['user'])) { if($result = mysql_query("SELECT username, rights FROM users WHERE username='{$_SESSION['user']}'")); $n = mysql_fetch_assoc($result); if($n['banned'] == 1) { header("Location: logout.php"); } else { if($n['rights'] == 2) { $_SESSION['admin'] = $n['username']; $_SESSION['user'] = $n['username']; } elseif($n['rights'] == 1) { $_SESSION['mod'] = $n['username']; $_SESSION['user'] = $n['username']; } elseif($n['rights'] == 0) { $_SESSION['user'] = $n['username']; } } } Whats in Config.php: Code: [Select] <?php DEFINE ('DB_HOST', 'localhost'); // This will most likely stay the same. DEFINE ('DB_USER', 'root'); // Insert your database username into the quotes. DEFINE ('DB_PASSWORD', ''); // Insert your database password into the quotes. DEFINE ('DB_NAME', 'school');// Insert your actual database name in the quotes. $dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error()); mysql_select_db (DB_NAME) OR die('Could not select the database: ' . mysql_error() ); ?> whats in Functions.php: Code: [Select] <?php function ___($_) { return base64_decode($_); } function realEscape($string) { if(get_magic_quotes_gpc()) { return mysql_real_escape_string(stripslashes($string)); } else { return mysql_real_escape_string($string); } } function capitalize($value) { $capitalize = preg_replace('/[a-z]/ie', 'strtoupper($0);', $value, 1); return htmlspecialchars($capitalize); } function encrypt($value) { return md5(md5(base64_encode($value))); } $w = 1; function smileys($value) { global $ln; $codes = array( ':)', ':angel:', ':@', ':shy:', ':s', ':dodgy:', ':!:', ':heart:', ':confused:', ':idea:', ':tired:', ':-/', ';)', ':cool:', ':D', ':P', ':rolleyes:', ':('); $img = array( '<IMG alt="Smile" title="Smile" src="http://runelegend.com/images/smilies/smile.gif">', '<IMG alt="Angel" title="Angle" src="http://runelegend.com/images/smilies/angel.gif">', '<IMG alt="Angry" title="Angry" src="http://runelegend.com/images/smilies/angry.gif">', '<IMG alt="Shy" title="Shy" src="http://runelegend.com/images/smilies/blush.gif">', '<IMG alt="Confused" title="Confused" src="http://runelegend.com/images/smilies/confused.gif">', '<IMG alt="Dodgy" title="Dodgy" src="http://runelegend.com/images/smilies/dodgy.gif">', '<IMG alt="Exclamation" title="Exclamation" src="http://runelegend.com/images/smilies/exclamation.gif">', '<IMG alt="Heart" title="Heart" src="http://runelegend.com/images/smilies/heart.gif">', '<IMG alt="Confused" title="Confused" src="http://runelegend.com/images/smilies/huh.gif">', '<IMG alt="Idea" title="Idea" src="http://runelegend.com/images/smilies/lightbulb.gif">', '<IMG alt="Sleepy" title="Sleepy" src="http://runelegend.com/images/smilies/sleepy.gif">', '<IMG alt="Undecided" title="Undecided" src="http://runelegend.com/images/smilies/undecided.gif">', '<IMG alt="Wink" title="Wink" src="http://runelegend.com/images/smilies/wink.gif">', '<IMG alt="Cool" title="Cool" src="http://runelegend.com/images/smilies/cool.gif">', '<IMG alt="Biggrin" title="Biggrin" src="http://runelegend.com/images/smilies/biggrin.gif">', '<IMG alt="Tongue" title="Tongue" src="http://runelegend.com/images/smilies/tongue.gif">', '<IMG alt="Rolleyes" title="Rolleyes" src="http://runelegend.com/images/smilies/rolleyes.gif">', '<IMG alt="Sad" title="Sad" src="http://runelegend.com/images/smilies/sad.gif">'); return str_ireplace($codes, $img, $value); } function bbcodes($value) { $value1 = htmlspecialchars($value); $bbcodes = array( '/\[url=(.*)\](.*)\[\/url\]/isU', '/\[b\](.*)\[\/b\]/isU', '/\[img\](.*)\[\/img\]/isU', '/\[u\](.*)\[\/u\]/isU', '/\[i\](.*)\[\/i\]/isU', '/\[url\](.*)\[\/url\]/isU', '/\[s\](.*)\[\/s\]/isU', '/\[color=(#?[a-z0-9]+)\](.*)\[\/color\]/isU', '/\[center\](.*)\[\/center\]/isU', '/\[big\](.*)\[\/big\]/isU', '/\[small\](.*)\[\/small\]/isU', ); $html = array( '<a class="hrefblack" href="$1">$2</a>', '<b>$1</b>', '<img src="$1">', '<u>$1</u>', '<i>$1</i>', '<a href="$1">$1</a>', '<s>$1</s>', '<div style="color: $1">$2</div>', '<div style="text-align: center">$1</div>', '<div style="font-size: 3em">$1</div>', '<div style="font-size: 0.8em">$1</div>', ); $result = preg_replace($bbcodes, $html, $value1); return $result; } /* if(isset($_SESSION['admin']) || isset($_SESSION['user'])) { if($news1 = mysql_query("SELECT * FROM ".$prefix."users WHERE uname='". $_SESSION['user'] ."'")) { if(mysql_num_rows($news1) > 0) { while($n = mysql_fetch_array($news1)) { if($n['banned'] == 1) { header("Location: logout.php"); } } } } } if($checkipban = mysql_query("SELECT * FROM ". $prefix ."ipban WHERE ip='". $_SERVER['REMOTE_ADDR'] ."'")) { if(mysql_num_rows($checkipban) > 0) { header("Location: ipbanned.php"); } }*/ ?> <?php function capitalizeFirstCharacter($value) { $capitalize = preg_replace('/[a-z]/ie', 'strtoupper($0);', $value, 1); return $capitalize; } ?> Whats in getuserinfo.php: Code: [Select] <?php $result = mysql_query("SELECT * FROM main id=". $_SESSION['id']) or die(mysql_error()); $row = mysql_fetch_assoc($result); $acptheme = $row["acptheme"]; ?> Please Help. Hi guys, I have two tables where users can update their informations tables 1 is user which includes (users) id username password branch1 branch2 and next table is (branch) id branchname branchpostcode so far i have two branches with postcodes and I have been able to add the branches via drop down list from mysql in user table as below: id username password branch1 branch2 1 me dfdsfds 1 2 the branches store the branch id in the field, what i need to do is to join the tables to echo relevant postcode information for entered for users, so if i have branch1 value set to 1 then I need to connect this to my branch table and retrieve the postcode information, I came up with the code below but it gives me error $findpostcode1=mysql_query("SELECT users.branch1, branch.id, FROM users, branch WHERE users.branch1=branch.id"); while($row = mysql_fetch_array($findpostcode1)) { $findpostcode1 = $row['postcode']; echo "your postcode: $findpostcode1"; } } but i recieve this error "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource" can you help me with this please? I have googled every possible thing but as im a newbie maybe there are some techniques which i dont know. thank you in advance Hi guys, I'm having a really frustrating problem with some PHP and MySQL. I've tested the MySQL in PHPMyAdmin and it runs fine, which is why I've posted this in PHP problems. All I want to do is copy one table to another (dropping the other first) as a backup, then recreate the original table but blank. I've tried running the functions in PHPMyAdmin, which works. Then I used its "Create PHP Code" function to make the PHP, which I edited to remove line breaks etc. Even if I used the unedited PHP made by PHPMyAdmin, it still doesn't work! The error is always a syntax one: "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 'CREATE TABLE mobackup (campaign_id varchar(20) NOT NULL, number varchar(13) NOT ' at line 1" Here's the code: Code: [Select] <?php $connection = mysql_connect(connection details hidden for security purposes, but they definitely work); mysql_select_db("betfredpiri", $connection); $sql = "DROP TABLE IF EXISTS mobackup; CREATE TABLE mobackup (campaign_id varchar(20) NOT NULL, number varchar(13) NOT NULL, message varchar(160) NOT NULL, mo_id int(15) NOT NULL, shortcode int(7) NOT NULL, received_time varchar(20) NOT NULL, network varchar(15) NOT NULL, retry tinyint(1) NOT NULL, FULLTEXT KEY message (message)) ENGINE = MyISAM DEFAULT CHARSET = latin1; INSERT INTO mobackup SELECT * FROM mo; DROP TABLE IF EXISTS mo; CREATE TABLE mo (campaign_id varchar(20) NOT NULL, number varchar(13) NOT NULL, message varchar(160) NOT NULL, mo_id int(15) NOT NULL, shortcode int(7) NOT NULL, received_time varchar(20) NOT NULL, network varchar(15) NOT NULL, retry tinyint(1) NOT NULL, FULLTEXT KEY message (message)) ENGINE = MyISAM DEFAULT CHARSET = latin1;"; mysql_query(mysql_real_escape_string($sql)); ?> I've also tried it with the following statements: Code: [Select] <?php $sql2 = "DROP TABLE IF EXISTS mobackup;" ."CREATE TABLE mobackup (campaign_id varchar(20) NOT NULL, " ."number varchar(13) NOT NULL, " ."message varchar(160) NOT NULL, " ."mo_id int( 15 ) NOT NULL, " ."shortcode int(7) NOT NULL, " ."received_time varchar(20) NOT NULL, " ."network varchar(15) NOT NULL, " ."retry tinyint(1) NOT NULL, " ."FULLTEXT KEY message (message) ) ENGINE = MyISAM DEFAULT CHARSET = latin1;" ."INSERT INTO mobackup SELECT * FROM mo;" ."DROP TABLE IF EXISTS mo;" ."CREATE TABLE mo (campaign_id varchar(20) NOT NULL, " ."number varchar(13) NOT NULL, " ."message varchar(160) NOT NULL, " ."mo_id int(15) NOT NULL, " ."shortcode int(7) NOT NULL, " ."received_time varchar(20) NOT NULL, " ."network varchar(15) NOT NULL, " ."retry tinyint(1) NOT NULL, " ."FULLTEXT KEY message (message)) ENGINE = MyISAM DEFAULT CHARSET = latin1;"; ?>and Code: [Select] <?php $sql3 = "\n" . "DROP TABLE IF EXISTS `betfredpiri`.`mobackup`;\n" . " CREATE TABLE `betfredpiri`.`mobackup` ( `campaign_id` varchar( 20 ) NOT NULL ,\n" . " `number` varchar( 13 ) NOT NULL ,\n" . " `message` varchar( 160 ) NOT NULL ,\n" . " `mo_id` int( 15 ) NOT NULL ,\n" . " `shortcode` int( 7 ) NOT NULL ,\n" . " `received_time` varchar( 20 ) NOT NULL ,\n" . " `network` varchar( 15 ) NOT NULL ,\n" . " `retry` tinyint( 1 ) NOT NULL ,\n" . " FULLTEXT KEY `message` ( `message` ) ) ENGINE = MyISAM DEFAULT CHARSET = latin1;\n" . "\n" . "INSERT INTO `betfredpiri`.`mobackup` SELECT * FROM `betfredpiri`.`mo`;" . "DROP TABLE IF EXISTS `betfredpiri`.`mo`;\n" . " CREATE TABLE `betfredpiri`.`mo` ( `campaign_id` varchar( 20 ) NOT NULL ,\n" . " `number` varchar( 13 ) NOT NULL ,\n" . " `message` varchar( 160 ) NOT NULL ,\n" . " `mo_id` int( 15 ) NOT NULL ,\n" . " `shortcode` int( 7 ) NOT NULL ,\n" . " `received_time` varchar( 20 ) NOT NULL ,\n" . " `network` varchar( 15 ) NOT NULL ,\n" . " `retry` tinyint( 1 ) NOT NULL ,\n" . " FULLTEXT KEY `message` ( `message` ) ) ENGINE = MyISAM DEFAULT CHARSET = latin1;\n"; ?> Both adaptations of PHPMyAdmin's export to a PHP statement. Any ideas would be most welcome! I'm tearing my hair out over this. Jamie Hi I am trying to figure out with this example i saw online does not work...I am building a database to store user and password and i keep getting an error "undefined index username" i need it to pull the username from mysql database so how do i do this??? mysql_connect("host", "username", "pw") or die (mysql_error()); mysql_select_db('username') or die (mysql_error()); if(mysql_num_rows(mysql_query("SELECT * from users WHERE username='" . $_POST['username'] . "'")) == 1) ( this is the error line) now I have the actual host username and pw in my file i just took it off for my security lol. I am getting this error: Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/content/20/8917120/html/goldenfruit/test.php on line 11 for this code: <?php $connect = mysql_connect('DB credentials removed'); if (!$connect) { die('Could not connect: ' .mysql_error()); } $data = mysql_query("SELECT * FROM fruits"); $row = mysql_fetch_row($data); echo $row[0]; echo hello; ?> I cannot seem to find the error in this. Can anyone help? Code: [Select] $con=mysql_connect("****","****","****"); mysql_select_db("****"); $queryuser=mysql_query("SELECT * FROM users WHERE name='$name'"); $checkuser=mysql_num_rows($queryuser); if($checkuser != 0) { $error = $name." is already in the database. <br /> <a href='****'>Return</a>"; $errortype = "1";} else { /* Now we will write a query to insert user details into database */ $insert = mysql_query("INSERT INTO users (name, group, sex, grouprank) VALUES ('$name', '$group', '$sex', '$grouprank')"); if($insert) { $error = $name. "Was successfully added to the database. <br /> <a href='****'>Return</a>"; $errortype = "0";} else { $error = "Error in registration: ".mysql_error(); $errortype = "1";} /* closing the if else statements */ } echo $error; ?>Error: Code: [Select] Error in registration: 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 'group, sex, grouprank) VALUES ('ljkh', 'lnkb', 'female', 'lkjh')' at line 1 Please help. THanks I dont know whats wrong Error: Code: [Select] 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 '::1, 3, , now())' at line 1 Error Line: mysql_query('INSERT INTO `'. $db .'`.`votes` (`ip`, `serverId`, `ownerId`, `date`) VALUES ('. $ip .', '. $serverId .', '. $ownerId .', now())') or die(mysql_error()); Hey everyone, So i was following a tutorial on youtube, it is a simple search and display program using mysql and php. i have completed 4 of 5 tutorials and when i enter a keyword in the textfield search and subit, it displays all the results in my database instead of the one. here is my code, any help would be very helpful thanks. $button = $_GET['submit']; $search = $_GET['search']; if(strlen($search)<2) echo "Search term too short"; else { echo "You searched for <b>$search</b><hr size='1'>"; mysql_connect("localhost", "root", "supersham"); mysql_select_db("carbreaker"); $keywords = $getrow['keywords']; //explode our search term $search_exploded = explode(" ", $search); $search_each = 0; while ($search_each < count($search_exploded)) { if ($search_each == 0) { $construct = "keywords LIKE '%" . $search_each . "%'"; } else { $construct .= " AND keywords LIKE '%" . $search_each . "%'"; } $search_each++; } //echo out construct $construct = "SELECT * FROM stock WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if($foundnum==0) echo "No Stock Found"; else{ echo "$foundnum results found<br>"; while($runrows = mysql_fetch_assoc($run)) { $make = $runrows['make']; $model = $runrows['model']; $year = $runrows['year']; $cc= $runrows['cc']; $fuel = $runrows['fuel']; $doors = $runrows['doors']; $body = $runrows['body']; $date = $runrows['date']; echo "<b>$make</b> $model $year $cc $fuel $doors $body $date<br>"; } } } ?> I have a newUser function in a class (database) that attempts to input all the post data from a registration (after it validates it all of course). Here is my function: Code: [Select] public function newUser($properties, $validated, $userLevel, $validationCode) { $qualityControl = new QualityControl; $properties = $this->escapeString($_POST); $properties['password'] = $qualityControl->encryptData($properties['password']); $time = gmmktime(); $query = "INSERT INTO 'TABLE_NAME' (handle, email, userLevel, password, banned, dateJoined, validated, validtionCode) VALUES ('$properties[username]','$properties[email]','$userLevel','$properties[password]',0,'$time','$validated','$validationCode')"; return mysql_query($query, $this->connection); } I am getting an error in that my query is not inserting, no errors come up with mysql_error if I toss that in after the query and this function appears to run fine as it returns and the rest of the script is run. I have a feeling it has to do with either my sql syntax or the escapeString function. Escape string is a function that is "supposed" to escape a string passed to it or iterate through an entire array it is passed, here is the code for it: Code: [Select] private function escapeString($data) { if (is_array($data)) { foreach ($data as &$value) $value = mysql_real_escape_string($value); return $data; } return mysql_real_escape_string($data); } If there error isn't in either of these two areas, it might be the encryptData function? All it is doing is md5ing + salting the password and returning the result. Here is that function if you need it: Code: [Select] return md5(SALT.$data); Very simple, I don't think the error is there. The globals I'm using are all defined correctly so that shouldn't be a problem either. I've been looking at it for the past hour and can't figure out why my stuff won't get into the database. Oh, here's the beginning of the database class that opens the database and such, I'm not getting any errors from it. Code: [Select] class Database { var $connection; public function __construct() { $qualityControl = new QualityControl; $this->connection = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD) or die(mysql_error()); mysql_select_db(DB_NAME, $this->connection) or die(mysql_error()); } Thank you for any help! Also, please excuse some of the sloppiness like the error handling not being graceful, etc, I usually pretty that stuff up after I'm done with the script. -Adam My code: Code: [Select] $extract = mysql_query("SELECT id,title,message FROM blog ORDER BY id DESC LIMIT 1"); while ($row = mysql_fetch_assoc($extract)) { echo "<div class='right'><h2>".$row['title']."</h2><div class='articles'>".nl2br(stripslashes($row['message']))."</div></div>"; } Error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/stonedms/public_html/justin/Toplist/index.php on line 29 I've double checked my database, and it seems like I've have everything correct. hey guys; Another problem with sql. Code: [Select] { echo "Welcome " . $row['username']; echo "<br />"; echo "<br />"; echo "<br />"; $msgquery = "SELECT * FROM spotty_messages WHERE (id_receiver = '" . $userid . "') AND message_read = '0'"; $messageres = mysql_query($msgquery); $messrow = mysql_fetch_array($messageres); $messagenum = mysql_num_rows($messageres); } $i = 0; while ($i < $messagenum) { $f1 = "From:" . mysql_result($messrow,$i,"sender"); echo " <tr> <td>" . $f1 ."</font></td> " ; $i++; } This is returning the error : Warning: mysql_result() expects parameter 1 to be resource, null given in /customers/klueless.net/klueless.net/httpd.www/daisysite/messages.php on line 106 Please help, thanks! |