PHP - Mysql Php Error
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. Similar TutorialsI 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' 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 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. 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()); 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. 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! 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 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 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? 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 Hello, can anybody tell me whats wrong with my code: function check_login($uname, $pwd){ $sql = "SELECT * FROM users WHERE uname=$uname"; $result = mysql_query($sql) or die('Error, Load query failed: ' . mysql_error()); $data = array(); while($row=mysql_fetch_assoc($result)){ $data[] = $row; } return $data; } $chk = check_login("test", "test1"); foreach($chk as $row){ echo $row['uname']; echo " = "; echo $row['pass']; echo "<BR>"; } when i run this i get: Quote Error, Load query failed: Unknown column 'test' in 'where clause' 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 'Number LIKE '%TEST%' OR Name LIKE '%TEST%'' at line 1 Is the error message i get... Here is my code... <?php $search=$_POST['searchform']; if(!$search) die('Please enter a search'); //connect to the database $db=mysql_connect ("xxxxxx", "xxxx", "xxxx") or die ('I cannot connect to the database because: ' . mysql_error()); //-select the database to use $mydb=mysql_select_db("wadkin"); //-query the database table $sql="SELECT ID, Stock Number, Name FROM Contacts WHERE Stock Number LIKE '%" . $search . "%' OR Name LIKE '%" . $search ."%'"; //-run the query against the mysql query function $result=mysql_query($sql) or die (mysql_error()); //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $Stock =$row['Stock Number']; $Name=$row['Name']; $ID=$row['ID']; //-display the result of the array echo "<ul>\n"; echo "<li>" . "<a href=\"search.php?id=$ID\">" .$Stock . " " . $Name . "</a></li>\n"; echo "</ul>"; } ?> Can someone correct for me please????!!!!! 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 I have created a PHP & MySql login but its not working. If I put the right email/password still its showing "Wrong Username or Password" everytime. Bacause I'm beginner to this I don't really know how to solve this issue. Thanks in advance. Here is my coding <?php // Start PHP session at the beginning session_start(); // Create database connection using config file include_once("connection.php"); // If form submitted, collect email and password from form if (isset($_POST['login'])) { $email = $_POST['email']; $password = $_POST['password']; // Check if a user exists with given username & password $result = mysqli_query($conn, "select 'Email', 'Password' from tblstudent where Email='$email' and Password='$password'"); // Count the number of user/rows returned by query $user_matched = mysqli_num_rows($result); // Check If user matched/exist, store user email in session and redirect to sample page-1 if ($user_matched > 0) { $_SESSION["email"] = $email; header("location: welcome.php"); } else { echo "User email or password is not matched <br/><br/>"; } } ?> Edited May 4 by Barand code tags added Can you guys tell me where is the error please...
$sql2= ('CREATE TABLE `'.$pub_unik.'` (ID SERIAL,ID_Use CHAR(30),Comment TEXT,Like INT,Score CHAR(30))');I can't find... Thank you guys Is there any visible error in my code? Code: [Select] if (isset($_POST['country'], $_POST['state'], $_POST['city'])) { if ($_POST['state'] = '') { $details = $_POST['city'].', '.$_POST['country']; update_user_location($details); } else { $details = $_POST['city'].', '.$_POST['state']; update_user_location($details); } } Code: [Select] function update_user_location($details) { global $user_info; $details = mres($details); mysql_query("INSERT INTO `user_actions` (`user_id`, `action_id`, `time`, `details`) VALUES (${user_info['uid']}, 1, NOW(), {$details})"); } Hi guys I am doinga login form for an organization, this form has email, password and pin If user fills all the fields it will execute the query fine but if user doesnt enter the pin it will come up with an error, the issue is that this pin is not included anywhere in mysql_query I have. Query tries to get the company id from db and echo it out, so if I dont enter the pin I get the error I have echoes out and another system error which is Quote Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ..../Dashboard/index.php on line 35 and my line 35 is while($row=mysql_fetch_array($getpin)){ here is my code Code: [Select] <?php include ('includes/db/db.php'); ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>Login | Careers Inbox Dashboard Admin</title> <link rel="stylesheet" href="./css/reset.css" type="text/css" media="screen" title="no title" /> <link rel="stylesheet" href="./css/text.css" type="text/css" media="screen" title="no title" /> <link rel="stylesheet" href="./css/form.css" type="text/css" media="screen" title="no title" /> <link rel="stylesheet" href="./css/buttons.css" type="text/css" media="screen" title="no title" /> <link rel="stylesheet" href="./css/login.css" type="text/css" media="screen" title="no title" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head> <body> <div id="login"> <h1>Dashboard</h1> <?php if (isset($_POST['login']) && $_POST['login']){ $email=addslashes(strip_tags($_POST['email'])); $in_password=addslashes(strip_tags($_POST['password'])); $pin=addslashes(strip_tags($_POST['pin'])); $password=md5($in_password); if (!$email || !$in_password || !$pin) echo "<div class='error'>Please fill all required fields</div>"; else $getpin=mysql_query("SELECT * FROM users WHERE UserEmail='$email' AND UserPassword='$password'"); while($row=mysql_fetch_array($getpin)){ $pin_email=$row['UserEmail ']; $pin_id=$row['UserId']; $pin_company_id=$row['company_id']; } echo "$pin_company_id"; } ?> <div id="login_panel"> <form action="" method="post" accept-charset="utf-8" /> <div class="login_fields"> <div class="field"> <label for="email">Email</label> <input type="text" name="email" value="" id="email" tabindex="1" placeholder="email@example.com" /> </div> <div class="field"> <label for="password">Password <small><a href="forgotpassword.php">Forgot Password?</a></small></label> <input type="password" name="password" value="" id="password" tabindex="2" placeholder="password" /> <div class="field"> <label for="pin">Pin Number</small></label><input type="password" name="pin" value="" id="password" tabindex="2" placeholder="pin"/> </div> </div> </div> <!-- .login_fields --> <div class="login_actions"> <input type="submit" name="login" value="Login" class="btn btn-grey"/> </div> </form> </div> <!-- #login_panel --> </div> <!-- #login --> </body> </html> thank you in advance. Hey guys, this is my first post here(not going to be the last one, Im sure), im trying to insert in mysql from session array, i don't know where is my error, I leave the code below, if someone can help me please . |