PHP - Mysql Query Error
Here is the error I get
ERROR: Could not execute query: INSERT INTO items (quickti, longti, desc, maincat, subcat1, subcat2, colour, size, style, price, stock, pic1, pic2, pic3, pic4, pic5, pic6, sold, saledate) VALUES ('quick', 'main title', 'description', 'Jewelry', 'Gemstones', 'Cubic Zirconia', 'Black', '50m', 'red', '1.50', '100', 'quick1', 'quick2', 'quick3', 'quick4', 'quick5', 'quick6', '0', '0'). 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 'desc, maincat, subcat1, subcat2, colour, size, style, price, stock, pic1, pic2, ' at line 1 Here is the relevant code $sql = "INSERT INTO items (quickti, longti, desc, maincat, subcat1, subcat2, colour, size, style, price, stock, pic1, pic2, pic3, pic4, pic5, pic6, sold, saledate) VALUES ('$quickheading', '$heading', '$content', '$cat1', '$cat2', '$cat3', '$colour', '$size', '$style', '$total', '$stock', '$quick1', '$quick2', '$quick3', '$quick4', '$quick5', '$quick6', '0', '0')"; if I remove desc and $content from the query, then it works. desc is a text field. Similar TutorialsHere is my code: // Start MySQL Query for Records $query = "SELECT codes_update_no_join_1b" . "SET orig_code_1 = new_code_1, orig_code_2 = new_code_2" . "WHERE concat(orig_code_1, orig_code_2) = concat(old_code_1, old_code_2)"; $results = mysql_query($query) or die(mysql_error()); // End MySQL Query for Records This query runs perfectly fine when run direct as SQL in phpMyAdmin, but throws this error when running in my script??? Why is this??? 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 '= new_code_1, orig_code_2 = new_code_2WHERE concat(orig_code_1, orig_c' at line 1 when i run the below code i get an error...
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in...
but when i take out the h>0 then there is no errors in the code. in table users, i need all columns in the array. How to get h>0 working?
$query = "SELECT * FROM users WHERE h>0 ORDER BY id"; $result = mysqli_query($link, $query); $data = array(); while($row1 = mysqli_fetch_array($result)) { $data[] = $row1; } print_r($data); Edited by kalster, 27 October 2014 - 07:38 PM. Can anyone tell me whats wrong with this code? The mysql error I get is generic and says
"Could not enter data: 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 'Tickets (Name,Tech,Node,Address,Tap,Ped,Lash,Hardline,Other,Comments) VALUES ('C' at line 1"
<?php $name=$_POST['name']; $id=$_POST['id']; $node=$_POST['node']; $ped=$_POST['ped']; $tap=$_POST['tap']; $lash=$_POST['lash']; $hardline=$_POST['hardline']; $other=$_POST['other']; $address=$_POST['address']; $city=$_POST['city']; $comments=$_POST['comments']; $dbhost = 'xxxx'; $dbuser = 'xxxx'; $dbpass = 'xxxx'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $sql = "INSERT INTO Damage Tickets (Name,Tech,Node,Address,Tap,Ped,Lash,Hardline,Other,Comments) VALUES ('$name','$id','$node','$address','$city','$tap','$ped','$lash','$hardline','$other','$comments')"; mysql_select_db('xxxxx'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not enter data: ' . mysql_error()); } echo "Your Damage has been Submitted! <a href=\"damage.php\">Go Back</a>"; mysql_close($conn); ?>No idea whats wrong with it? Thanks for any help The page that I'm currently working on has a form which allows, through a series of check boxes and text entry fields, a dynamic mysql query to be created. The php code constructs the query based on which fields the user updated in order to find a specific user in the database. Everything was working fine until I started to only display part of the result set. In order to display a message similar to "Displaying 12-25 of 65 results." I ran the query twice. Once to get the total number of results, and once to only get the specified set. The code for the section producing the error is included below. The elseif statement works as desired, as does the initial query of the if statement. if (isset($sql) && $sql !=""){ $sql = "SELECT DISTINCT users.StudentID FROM users lEFT JOIN events ON users.StudentID=events.StudentID WHERE" . $sql; $stmt = $mysqli->prepare($sql); call_user_func_array(array(&$stmt, 'bind_param'), $array_of_params); $stmt->execute(); $stmt->store_result(); $total= $stmt->num_rows; $stmt->close(); $sql = "SELECT DISTINCT users.StudentID,users.FirstName,users.LastName,users.Email,users.Phone,users.Texting,users.Admin,users.HDHS,users.Sex,users.Confirmation FROM users lEFT JOIN events ON users.StudentID=events.StudentID WHERE" . $sql . " ORDER BY LastName,FirstName LIMIT " . $_GET['start'] . ",12"; $stmt = $mysqli->prepare($sql); call_user_func_array(array(&$stmt, 'bind_param'), $array_of_params); $stmt->bind_result($row['StudentID'],$row['FirstName'],$row['LastName'],$row['Email'],$row['Phone'],$row['Texting'],$row['Admin'],$row['HDHS'],$row['Gender'],$row['Confirmation']); } elseif(isset($_GET['submit']) || isset($_GET['earlier']) || isset($_GET['later'])){ $stmt = $mysqli->prepare("SELECT StudentID,FirstName,LastName,Email,Phone,Texting,Admin,HDHS,Sex,Confirmation FROM users ORDER BY LastName,FirstName"); $stmt->bind_result($row['StudentID'],$row['FirstName'],$row['LastName'],$row['Email'],$row['Phone'],$row['Texting'],$row['Admin'],$row['HDHS'],$row['Gender'],$row['Confirmation']); $stmt->execute(); $stmt->store_result(); $total= $stmt->num_rows; $stmt = $mysqli->prepare("SELECT StudentID,FirstName,LastName,Email,Phone,Texting,Admin,HDHS,Sex,Confirmation FROM users ORDER BY LastName,FirstName LIMIT " . $_GET['start'] . ",12"); $stmt->bind_result($row['StudentID'],$row['FirstName'],$row['LastName'],$row['Email'],$row['Phone'],$row['Texting'],$row['Admin'],$row['HDHS'],$row['Gender'],$row['Confirmation']); $stmt->execute(); } If anyone would be willing to help me out here it would be greatly appreciated. If you need more information let me know. Thank you! If you also have any feedback on my code, please do tell me. I wish to improve my coding base. Basically when you fill out the register form, it will check for data, then execute the insert query. But for some reason, the query will NOT insert into the database. In the following code below, I left out the field ID. Doesn't work with it anyways, and I'm not sure it makes a difference. Code: Code: [Select] mysql_query("INSERT INTO servers (username, password, name, type, description, ip, votes, beta) VALUES ($username, $password, $name, $server_type, $description, $ip, 0, 1)"); Full code: Code: [Select] <?php include_once("includes/config.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><? $title; ?></title> <meta http-equiv="Content-Language" content="English" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="style.css" media="screen" /> </head> <body> <div id="wrap"> <div id="header"> <h1><? $title; ?></h1> <h2><? $description; ?></h2> </div> <? include_once("includes/navigation.php"); ?> <div id="content"> <div id="right"> <h2>Create</h2> <div id="artlicles"> <?php if(!$_SESSION['user']) { $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $name = mysql_real_escape_string($_POST['name']); $server_type = mysql_real_escape_string($_POST['type']); $description = mysql_real_escape_string($_POST['description']); if(!$username || !$password || !$server_type || !$description || !$name) { echo "Note: Descriptions allow HTML. Any abuse of this will result in an IP and account ban. No warnings!<br/>All forms are required to be filled out.<br><form action='create.php' method='POST'><table><tr><td>Username</td><td><input type='text' name='username'></td></tr><tr><td>Password</td><td><input type='password' name='password'></td></tr>"; echo "<tr><td>Sever Name</td><td><input type='text' name='name' maxlength='35'></td></tr><tr><td>Type of Server</td><td><select name='type'> <option value='Any'>Any</option> <option value='PvP'>PvP</option> <option value='Creative'>Creative</option> <option value='Survival'>Survival</option> <option value='Roleplay'>RolePlay</option> </select></td></tr> <tr><td>Description</td><td><textarea maxlength='1500' rows='18' cols='40' name='description'></textarea></td></tr>"; echo "<tr><td>Submit</td><td><input type='submit'></td></tr></table></form>"; } elseif(strlen($password) < 8) { echo "Password needs to be higher than 8 characters!"; } elseif(strlen($username) > 13) { echo "Username can't be greater than 13 characters!"; } else { $check1 = mysql_query("SELECT username,name FROM servers WHERE username = '$username' OR name = '$name' LIMIT 1"); if(mysql_num_rows($check1) < 0) { echo "Sorry, there is already an account with this username and/or server name!"; } else { $ip = $_SERVER['REMOTE_ADDR']; mysql_query("INSERT INTO servers (username, password, name, type, description, ip, votes, beta) VALUES ($username, $password, $name, $server_type, $description, $ip, 0, 1)"); echo "Server has been succesfully created!"; } } } else { echo "You are currently logged in!"; } ?> </div> </div> <div style="clear: both;"> </div> </div> <div id="footer"> <a href="http://www.templatesold.com/" target="_blank">Website Templates</a> by <a href="http://www.free-css-templates.com/" target="_blank">Free CSS Templates</a> - Site Copyright MCTop </div> </div> </body> </html> I'm restarting this under a new subject b/c I learned some things after I initially posted and the subject heading is no longer accurate. What would cause this behavior - when I populate session vars from a MYSQL query, they stick, if I populate them from an MSSQL query, they drop. It doesn't matter if I get to the next page using a header redirect or a form submit. I have two session vars I'm loading from a MYSQL query and they remain, the two loaded from MSSQL disappear. I have confirmed that all four session vars are loading ok initially and I can echo them out to the page, but when the application moves to next page via redirect or form submit, the two vars loaded from MSSQL are empty. Any ideas? A friend of mine must of changed something on the site while I was asleep last night and now all the site says when you go to it is: Error Database query error Warning: mail() [function.mail]: SMTP server response: 530 SMTP authentication is required. in C:\xampp\htdocs\inc\utils.inc.php on line 449 I'm not exactly sure what he did since I can't contact him. Can anyone help me fix this? 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' Hi all, having a strange problem with my query Its only returning some of my data, and in the format User 1 <br /> <br /> User 2 <br /> <br /> <br /> <br /> Code: [Select] $newmembers = "SELECT * FROM users WHERE linked_user IS NOT NULL ORDER BY datejoined LIMIT 6"; $nmresult = mysql_query($newmembers); while($row = mysql_fetch_array($nmresult)){ echo $row['linked_user']; echo "<br />";} ?>  Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/omerbsh/hallofblogs.com/autoTwit/Library/database.php on line 13 Warning: mysqli_error() expects exactly 1 parameter, 0 given in /home/omerbsh/hallofblogs.com/autoTwit/Library/database.php on line 13 Error: The Query:INSERT INTO twitter_profiles VALUES('dfggffg','dgfgfdg','1') Hello, i have one little problem and can't pass it. Problem is i need to call new sql query inside another query. Am trying to make accordion which will put result of first query($sql) like title and result of second query($sql2) like list of current item. All time am getting error : Quote Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt, SQL state S1000 in SQLExecDirect in ..... I know reasone is because i use query inside query so am trying to figure is there any way to bypass it or make it work. Example: Code: [Select] $sql="EXECUTE _PROCEDURE1 '".$date."',''.$code."; $rs=odbc_exec($conn,$sql); if (!$rs){exit("Error in SQL");} while (odbc_fetch_row($rs)){ $id_number=odbc_result($rs,"ID"); $name=odbc_result($rs,"NAME"); echo $id_number.' - '.$name; $sql2="EXECUTE _PROCEDURE2 '".$id_number."',''.$name."; $name=odbc_exec($conn,$sql2); while(odbc_fetch_row($popust)){ $detail = odbc_result($sql2,"DETAILS"); $detail2 = odbc_result($sql2,"DETAILS2"); $detail3 = odbc_result($sql2,"DETAILS3"); echo $detail.' - '.$detail2.' - '.$detail3; } } I hope i explained it well. Thanks. Code: [Select] mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean i get that error with this code: $online_query = $link->simple_query('u_username', 'users', 'u_online=1 AND u_hidden != 1', '0u_username'); while($online_info = $link->fetch_array($online_query)) //THIS LINE THROWS THE ERROR the simple_query function is: function simple_query($fields, $table, $clause, $order) { global $link, $config; if(!empty($clause)) { $clause = "WHERE $clause"; } else { $clause = ''; } if(!empty($order)) { $direction = $order[0]; switch($direction) { case '0': $direction = 'ASC"'; break; case '1': $direction = 'DESC'; break; } $order = substr($order, 1, strlen($order)); $order = "ORDER BY $order $direction"; } $query = mysqli_query($this->link, "SELECT $fields FROM ".TBL_PREFIX."$table $clause $order"); return $query; } when i use a normal query instead of my simple_query function it works fine. it also worked fine before i made the database class. Where am i going wrong? Hi, i'm currently coding a new inbox for my website, but ive got an error which says: 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 'to='NoName' ORDER BY id DESC' at line 1 Im not sure why ive got that as everything seems to be fine :S My Code: $user=$_SESSION['username']; $get_messages = mysql_query("SELECT `id` FROM `inbox` WHERE to='$user' ORDER BY `id` DESC") or die("Error on line 9 - " . mysql_error()); Thanks for any help/advise given. Hello! First post. I am trying to code out a news website (kinda) I can't seem to fetch the news articles out of SQL. What am I doing wrong? (start is fetched by $_REQUEST. Assume it is 1) $end=$start+5; $stories = mysql_query("SELECT * FROM 'stories' DESC ORDER BY id LIMIT $start, $end"); $num = mysql_num_rows($stories); print $num; Hi all, I have a database with 2 tables, 'users' and 'battles'. The site pulls 2 random peoples pictures and lets the user choose who they think would win the battle. So if user1 is using the site it might show pictures for user5 and user3. If the user1 chooses that user5 wins then an entry is made into the 'battles' table like this : voter win lose user1 user5 user3 Any ideas what query I can use so it only shows 2 people that the user hasnt compared before ? As if its doing this : choose 2 id's from 'users' that user1 hasnt compared before Hope that makes sense. Many thanks, Scott I am creating a site that has to display 36 images on the screen. The image name is stored in the database. My problem is if I have less than 36 images stored I need to display a default image. here is my current query $sql="SELECT col_image, col_url from tbl_images WHERE col_active='1' and col_bigimage='0' ORDER BY RAND() limit 36"; so If I only have 20 active images. I need to display 16 default images. I hope this makes sense. Bill $loc="SELECT * FROM table WHERE username='a', id='1' AND uin='123'"; $get=myspl_query($loc) or die(mysql_error()); Please somone tell me the right command as how to use multiple AND in mysql query. Thanks Hello! Please help... I am trying to use the script below to get results from a mysql database based on a query of the form fields (the names of which are displayed near the top of the script as POST items) When a location or age etc. is entered into the form, I want the script to search for records which meet those criteria. At the moment the script works but only does so if all the values are entered to match what is in the database. e.g. if the location england and the age 22 was entered into the form, and that matched the value in the database, then at the moment, the script will display the result, but if only the location is entered in the form without any value for age/genre etc. then no results are displayed. Any help would be very welcome as I have search high and low for a solution on google... which doesn't seem to exist... I'm not that experienced with php/mysql but am learning on the job so any helpful prompts as to terms etc. would help! Thanks! Lewis <?php if($_POST) { $searchage = $_POST['searchage']; $searchlocation = $_POST['searchlocation']; $searchgenre = $_POST['searchgenre']; $searchinstrument = $_POST['searchinstrument']; $searchexperience = $_POST['searchexperience']; // Connects to your Database mysql_connect("localhost", "user", "pass") or die(mysql_error()); mysql_select_db("DB") or die(mysql_error()); $query = mysql_query("SELECT * FROM table_user WHERE userage = '".$searchage."' AND userlocation = '".$searchlocation."' AND usergenre = '".$searchgenre."' AND userinstrument = '".$searchinstrument."' AND userexperience = '".$searchexperience."'") or die(mysql_error()); $num = mysql_num_rows($query); echo "$num results found!<br>"; while($result = mysql_fetch_assoc($query)) { $username = $result['username']; $useremail = $result['useremail']; $userage = $result['userage']; $userlocation = $result['userlocation']; $usergenre = $result['usergenre']; $userinstrument = $result['userinstrument']; $userexperience = $result['userexperience']; $userbiography = $result['userbiography']; echo " Name: $username<br> Email: $useremail<br> Age: $userage<br> Location: $userlocation<br> Gen $usergenre<br> Instrument: $userinstrument<br> Experience: $userexperience<br> Biography: $userbiography<br><br> "; } } ?> |