PHP - Query Nightmare
OK, I have been having issues with this query for some time now, I (finaly) have the query working absoloutly fine when run directly in the database, however, when I try and run it through a PHP page I just get a completly empty result set back. I have done a print_r($row) and there is nothing, absoloutly nothing. I have ran the SQL that comes from print_r($sql) in the database and it's completly fine as well. I was getting an error previously because I had missed the "IS" out before NOT NULL for the PadPrefix, so it is parsing the SQL to some level (I now have no errors showing either).
I am wondering if there is something I am missing that is needed for when the SQL is creating cached tables and/or using a counter? Here's the code, any and all suggestions welcome, Cheers <?php @SESSION_START(); require_once 'connect.php'; $bp = $_SESSION['bp']; if ($_SESSION['id'] < 99){ $tbl_top = '<table><tr><th>SheetID</th></tr>'; $WHERE = " = '$bp'"; } else{ $tbl_top = '<table><tr><th>SheetID</th><th>Prefix</th></tr>'; $WHERE = "IS NOT NULL"; } $sql = "DECLARE @badSheets TABLE (ID int, batchMax int) ". "DECLARE @list TABLE (maxsheet int, lastsheet int) ". "DECLARE @sheet int ". "DECLARE @batch int ". "DECLARE @endBatch int ". "declare @batchIndex int ". "INSERT INTO @list (maxsheet, lastsheet) ". "SELECT sheetList.maxsheet, padlist.lastSheet ". " FROM( ". " SELECT sheet.padID, MAX(sheet.SheetID) as maxsheet FROM jim.dbo.sheet as sheet ". " INNER JOIN jim.dbo.files as files on sheet.sheetID = files.sheetid ". " where sheet.sheetid > 100000 ". " group by sheet.padID) ". "AS sheetList ". "INNER JOIN( ". "SELECT pads.padID, pads.padID+(count(pads.padID)-1) as lastSheet ". "From jim.dbo.sheet as pads ". "Group By pads.PadID) ". "AS padList ". "ON (sheetList.padID = padList.padID) ". "WHERE maxsheet != lastSheet ". "DECLARE bad_batch CURSOR FOR ". "SELECT DISTINCT maxsheet FROM @list ORDER BY MaxSheet ". "OPEN bad_batch ". "FETCH NEXT FROM bad_batch ". "INTO @batchIndex ". "WHILE @@FETCH_STATUS = 0 ". "BEGIN ". "SELECT @batch = lastSheet FROM @List where maxsheet= @batchIndex ". "SELECT @sheet = maxSheet FROM @List where maxsheet= @batchIndex ". "WHILE (@sheet <= @batch) ". "BEGIN ". "INSERT INTO @badsheets(ID, batchMax) VALUES (@sheet, @batch) ". "SET @sheet = (@sheet + 1) ". "END ". "Fetch Next FROM bad_batch INTO @batchIndex ". "END ". "close bad_batch ". "deallocate bad_batch ". "SELECT sheetID, padprefix ". "FROM JIM.dbo.sheet AS sheet LEFT OUTER JOIN jim.dbo.pad AS pads ". "ON sheet.padID = pads.padID ". "WHERE ( ". "(padprefix $WHERE) ". "AND (sheet.sheetID > 100000) ". "AND (sheet.SheetID NOT IN (SELECT SheetID FROM jim.dbo.files)) ". "AND (sheet.sheetID NOT IN (SELECT ID FROM @badSheets)) ". ")"; $result = sqlsrv_query($sqlConnect, $sql) or die("error running : $sql <br><br>".print_r( sqlsrv_errors(), true)); echo "<table border=\"1\">"; echo $tbl_top; WHILE ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){ if ($_SESSION['id'] < 99){ $tbl_content = "<tr><td>{$row['sheetID']}</td></tr>"; echo $tbl_content; } else{ $tbl_content = "<tr><td>{$row['sheetID']}</td><td>{$row['padPrefix']}</td></tr>"; echo $tbl_content; } echo $tbl_content; } echo "</table>"; ?> Similar TutorialsGood Afternoon, I wonder if anybody can help me with a couple of PHP issues I am having. I am a Junior Web Designer and have very basic PHP knowledge. I have already done most of the work but I'm having an issue that is driving me mental. I purchased a html template which has a pre-configured contact form that uses jquery validation and "sendmail function." I have made the relevant changes to the PHP file (recipient address and subjet line) however when I go live with the system it only works once and then the html page doesn't process the message. If I go to the PHP location I get a 500 Internal Server Error message. I have contacted my hosting provider (mellowhost) and they have said that my script will only work if I add SMTP Authentication to it, which I have no idea how to do. Here is my script: Code: [Select] <?php // Chnage this according to your settings $to = 'support@gainfordstevens.co.uk'; // Change the mail according to your need. $subject = "Contact Form"; // Mail Subject $success_msg = '<strong style="color:#0033CC">Your Message has been submitted and we will get back to you ASAP.</strong><br /><br />'; // The message displayed after successful mail delivery $failure_msg = '<h2>Contact Form Submitted!</h2> <p>Due to some reason mail is not sent.</p>'; // The message displayed after mail delivery failure //Do not edit below this line. if ( trim($_POST['names']) != '' ) { $names = stripslashes(strip_tags($_POST['names'])); } else { $names = 'No name entered'; } if ( trim($_POST['emails']) != '' ) { $emails = stripslashes(strip_tags($_POST['emails'])); } else { $emails = 'No email entered'; } if ( trim($_POST['phone']) != '' ) { $phone = stripslashes(strip_tags($_POST['phone'])); } else { $phone = 'No phone number entered'; } if ( trim($_POST['comments']) != '' ) { $comments = nl2br(stripslashes(strip_tags($_POST['comments']))); } else { $comments = 'No comments entered'; } ob_start(); ?> <html> <head> <style type="text/css"> .style3 {color: #000000} </style> </head> <body> <table width="550" border="1" cellspacing="2" cellpadding="2"> <tr bgcolor="#eeffee"> <td width="132"><span class="style3">Name</span></td> <td width="398"><?=$names;?></td> </tr> <tr bgcolor="#eeeeff"> <td>Email</td> <td><?=$emails;?></td> </tr> <tr bgcolor="#eeffee"> <td>Comments</td> <td><?=$comments;?></td> </tr> </table> </body> </html> <? $body = ob_get_contents(); ob_end_clean(); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: '.$names.' <'.$emails.'>' . "\r\n"; if(mail($to, $subject, $body, $headers)) { echo $success_msg; } else { echo $failure_msg; } ?> Please can somebody help me find some PHP solace? Thanks-in-advance. Liam Ok I am having one of those php nightmare. The kind that you simply say, 'WHAT the *^$%*&YU'? I have formed a php called a_user_page.php that is called for by index.php?a=user_page Uses same format as various others that have no problem being viewed on screen. Ok did this some time ago. The page came up and worked perfectly. Now I want to add content to this page. So i naturally save the updated page in a different folder. I am use to things not going my way. Uploaded through ftp program. Page will not view. Strange. So I up loaded the original file and it works. OK So I redue the change I want done making only one word change in heading USER PAGE to USER PROFILE PAGE. Only change. Uploaded. Still Not work SO upload original file and works. OK? So enter into the cpanel and file manager and edit the file online. Put one word change in heading USER PAGE to USER PROFILE PAGE Save View NOT WORK??? Uploaded original file, views!!! What the ? I have tried clear cache and cookies and different browsers. I am Hey,
I have an issue where the below script doesnt appear to be working. It doesnt actually display anything on the page, it seems as though after the first PHP tag is just ignores the rest of the script. when looking at the page source all it shows is:
<HTML> <HEAD> <TITLE>Logs</TITLE> </HEAD> <BODY>The actual code is below: <HTML> <HEAD> <TITLE>Logs</TITLE> </HEAD> <BODY> <?PHP $mysqlserver="localhost"; $mysqlusername="root"; $mysqlpassword="test"; $dbname = 'test'; $con=mysqli_connect($mysqlserver, $mysqlusername, $mysqlpassword, $dbname); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con, "SELECT * FROM forwardtable"); echo "<table border='1'> <tr> <th>Acc Num</th> <th>Send Date</th> <th>Send Time</th> </tr>"; while($rowContent = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $rowContent['Acc'] . "</td>"; echo "<td>" . $rowContent['Date'] . "</td>"; echo "<td>" . $rowContent['Time'] . "</td>"; echo "</tr>"; } echo "</table>" ?> </BODY> </HTML>If I remove the PHP from within the code the source code goes as it should and shows the </BODY> and </HTML> tags. Any ideas anyone? Thanks, Matt basically its a design flaw but im too far into it so im going to have to find a way to get this to work. Basically i have an anonymous board, anyone can post as long as they have cookies enabled. Cookies are key because they help bans and keeping track. The problem is the following. The Admin i.e me needs to have the same cookie no matter where i login from. This is to stop the admin being banned by mods. as that cookie key cant be banned. now any new visitor to the site gets assigned a cookie. So if the admin went to the site he would get a cookie. But when he loggs in i want it to get rid of the old cookie and replace it with his admin cookie so say for argument sake. he goes to the site and gets assigned Cookie1 in the login confirm i have setcookie(cook,cookie1, time() -3600); setcookie(cook,$admincook,time() + 60 *24); after i log in as admin and check the cookie $_COOKIE[cook]; it still displays as cookie1 But for some strange reason when i post a thread the value of $admincook gets stored in the database. However this is only for posting a thread and not for any of the other options, such as asking a question etc. the method of getting the cookie value when posting a thread is the EXACT same... i really don't know why it wont work. my project is over several files and over 15 thousand lines of code. so im not sure what parts i should give you. my main problem is that expiring the cookie and resetting it again straight away doesn't seem to work. Hey guys so Ive been messing with a number of .ini files (im sure this isnt a good thing) because Ive been trying to write a script that uploads files as big as 1GB and in doing so Ive edited the my suhosin.ini because in looking at my php_info() it said that all my pot max, get max, request etc were all undesirably low. Anyways I edited the file and then restarted apache but the changes that I made in suhosin.ini arent being displayed when i go to my php_info(). Cant anyone tell me if I missed a step and how do I get the server to recognize the changes as I believe it is these settings that are buggering up my upload script. -SB Hey guys, Been developing a bespoke "helpdesk" system for work and, while it works well on the whole, I am having major problems with base64 encoded email bodies. Admittedly, this might be due to my misunderstanding of imap body parts. It seems in my current setup, the system thinks that all mails are either "type" 0 or 4. As a result, base64 emails don't get decoded and display as an unreadable long string. Here is what my code for the body decoding looks like just now - can provide more on request. $from=$overview[0]->from; $subject=$overview[0]->subject; $subdb=mysql_real_escape_string($subject); $lookingfor=explode("~#",$body); $result=$from; $find=strrpos($ir, $lookingfor[1]); $findreplystream=mysql_query("SELECT * FROM tickets WHERE ticket_md5='$lookingfor[1]'") or die(''.mysql_error().''); $stream=mysql_fetch_array($findreplystream); $now=time(); if($structure->encoding == 0){ $arr1=array("=A3", "=80"); $arr2=array("£", "€"); $newcontent=$explodeunder[0]; define("CHARSET", "ISO-8859-1"); $dbcontenta=str_replace($arr1, $arr2, $newcontent); $r=mb_detect_encoding($dbcontenta); if($r=="UTF-8"){ $dbcontents=mb_convert_encoding($dbcontenta, "ISO-8859-1", "UTF-8"); $dbcontent1=addslashes($dbcontents); $dbcontent2=strip_tags($dbcontent1); } elseif($r=="ASCII"){ $dbcontentb=mb_convert_encoding($dbcontenta, "UTF-8", "ASCII"); $dbcontents=mb_convert_encoding($dbcontentb, "ISO-8859-1", "UTF-8"); $dbcontent1=addslashes($dbcontents); $dbcontentf=strip_tags($dbcontent1); $dbcontent2=quoted_printable_decode($dbcontentf); } } elseif($structure->encoding == 4) { $dbcontent=$explodeunder[0]; $dbcontentf=quoted_printable_decode($dbcontent); $dbcontent2=mb_convert_encoding($dbcontentf, "ISO-8859-1", "UTF-8"); } elseif($structure->encoding == 3) { $dbcontent2=imap_base64($explodeunder[0]); } elseif($structure->encoding == 1){ $dbcontent3=imap_8bit($explodeunder[0]); $dbcontent2=quoted_printable_decode($dbcontent3); } Can anyone advise me with this? I'd be greatful for any assistance at all, as it's causing me nightmares! All the best I have the " or the ' all wrong. Can someone tell me how to do the quoation marks correctly so I dont get a syntax error: as can be seen, the date 10/5/14 is not a variable but I want to convert it to a format that can go into a DATE field. Code: [Select] $query = "update table set expir_date = date("Y-m-d", 10/5/14) where id = '$id' "; I am having a nightmare with an explode and cant get it to work. I am posting a string using JQuery to a PHP form which needs to explode the string into an indexed array to be inserted into a database. This is what the string looks like "importance%5B101%5D=50&importance%5B100%5D=50&importance%5B99%5D=50&importance%5B98%5D=50" The original array has been serialised into the above string. The arrayname is importance. The array's index (inside the square brackets) is referenced from an ID from the page. The square brackets have been replaced by '%5B' and '%5D' and surround the array index by the JQuery. The value for each of these array items is shown as =50. So its basically the same as a GET when we have name=value&name1=value1etc') How would i explode the string above to remove the '%5B' and '%5D' to make the '[' and ']' reappear and then from then it can be read as a GET post? like 'name=value&name1=value1etc'. Using the new array of that index ready to be inserted into a MySQL database. Im going mad trying to solve this!!! Hi all, im trying to shorten this string which cnotains about 1000 characters, to say 250 Code: [Select] <?php echo $row_Best_Sellers['experience_name']; ?> Ive tried using the below to no avail, can anybody give me some advice? Code: [Select] <?PHP $small = some_function($row_Best_Sellers['experience_description']); echo $small; function some_function($string){ $string = substr($string,0,100); $string = substr($string,0,strrpos($string," ")); return $string; } ?> Hi all, Experimenting with this instant search buzz only I cant seem to replicate the function! I think my PHP may be cocking up but Ive been staring for too long to see anything. Could anybody take a quick glance and see if they can see anything? Code: [Select] <?php if(!empty($_GET['q'])) { search(); } function search() { $con = mysql_connect('localhost','login', 'pass'); mysql_select_db('db', $con); $q = htmlspecialchars($_GET['q'],ENT_QUOTES); $sql = mysql_query(" SELECT post_title as post FROM wp_posts WHERE post_title LIKE '%{$q}%' OR post_title LIKE '%{$q}%' "); $results=array(); while($v = mysql_fetch_object($sql)){ $results[] = array( 'title'=>$v->title, 'post'=>$v->post ); } echo json_encode($results); } ?> Hi, I am currently trying to build an Artist's website, the artist wanted a CMS that was completely customized to the site (so no Wordpress, Joomla, Drupel, etc) - because of this I am having to create a CMS completely from scratch.
The problem I am having is with the database connection (hence the topic title), other sites that I have built with this same code work fine - however this particular site does not seem to want to play ball. It keeps giving me this error:
SQLSTATE[HY000] [1045] Access denied for user 'web113-janesart'@'10.0.44.113' (using password: YES)I have tried obvious things such as spelling mistakes, wrong password/username/db name, nothing seems to get rid of this error. Any help on what else this could be would be appreciated. Here 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 Hello all,
Based on the suggestion of you wonderful folks here, I went away for a few days (to learn about PDO and Prepared Statements) in order to replace the MySQLi commands in my code. That's gone pretty well thus far...with me having learnt and successfully replaced most of my "bad" code with elegant, SQL-Injection-proof code (or so I hope).
The one-and-only problem I'm having (for now at least) is that I'm having trouble understanding how to execute an UPDATE query within the resultset of a SELECT query (using PDO and prepared statements, of course).
Let me explain (my scenario), and since a picture speaks a thousand words I've also inlcuded a screenshot to show you guys my setup:
In my table I have two columns (which are essentially flags i.e. Y/N), one for "items alreay purchased" and the other for "items to be purchased later". The first flag, if/when set ON (Y) will highlight row(s) in red...and the second flag will highlight row(s) in blue (when set ON).
I initially had four buttons, two each for setting the flags/columns to "Y", and another two to reverse the columns/flags to "N". That was when I had my delete functionality as a separate operation on a separate tab/list item, and that was fine.
Now that I've realized I can include both operations (update and delete) on just the one tab, I've also figured it would be better to pare down those four buttons (into just two), and set them up as a toggle feature i.e. if the value is currently "Y" then the button will set it to "N", and vice versa.
So, looking at my attached picture, if a person selects (using the checkboxes) the first four rows and clicks the first button (labeled "Toggle selected items as Purchased/Not Purchased") then the following must happen:
1. The purchased_flag for rows # 2 and 4 must be switched OFF (set to N)...so they will no longer be highlighted in red.
2. The purchased_flag for row # 3 must be switched ON (set to Y)...so that row will now be highlighted in red.
3. Nothing must be done to rows # 1 and 5 since: a) row 5 was not selected/checked to begin with, and b) row # 1 has its purchase_later_flag set ON (to Y), so it must be skipped over.
Looking at my code below, I'm guessing (and here's where I need the help) that there's something wrong in the code within the section that says "/*** loop through the results/collection of checked items ***/". I've probably made it more complex than it should be, and that's due to the fact that I have no idea what I'm doing (or rather, how I should be doing it), and this has driven me insane for the last 2 days...which prompted me to "throw in the towel" and seek the help of you very helpful and intellegent folks. BTW, I am a newbie at this, so if I could be provided the exact code, that would be most wonderful, and much highly appreciated.
Thanks to you folks, I'm feeling real good (with a great sense of achievement) after having come here and got the great advice to learn PDO and prepared statements.
Just this one nasty little hurdle is stopping me from getting to "end-of-job" on my very first WebApp. BTW, sorry about the long post...this is the best/only way I could clearly explaing my situation.
Cheers guys!
case "update-delete": if(isset($_POST['highlight-purchased'])) { // ****** Setup customized query to obtain only items that are checked ****** $sql = "SELECT * FROM shoplist WHERE"; for($i=0; $i < count($_POST['checkboxes']); $i++) { $sql=$sql . " idnumber=" . $_POST['checkboxes'][$i] . " or"; } $sql= rtrim($sql, "or"); $statement = $conn->prepare($sql); $statement->execute(); // *** fetch results for all checked items (1st query) *** // $result = $statement->fetchAll(); $statement->closeCursor(); // Setup query that will change the purchased flag to "N", if it's currently set to "Y" $sqlSetToN = "UPDATE shoplist SET purchased = 'N' WHERE purchased = 'Y'"; // Setup query that will change the purchased flag to "Y", if it's currently set to "N", "", or NULL $sqlSetToY = "UPDATE shoplist SET purchased = 'Y' WHERE purchased = 'N' OR purchased = '' OR purchased IS NULL"; $statementSetToN = $conn->prepare($sqlSetToN); $statementSetToY = $conn->prepare($sqlSetToY); /*** loop through the results/collection of checked items ***/ foreach($result as $row) { if ($row["purchased"] != "Y") { // *** fetch one row at a time pertaining to the 2nd query *** // $resultSetToY = $statementSetToY->fetch(); foreach($resultSetToY as $row) { $statementSetToY->execute(); } } else { // *** fetch one row at a time pertaining to the 2nd query *** // $resultSetToN = $statementSetToN->fetch(); foreach($resultSetToN as $row) { $statementSetToN->execute(); } } } break; }CRUD Queston.png 20.68KB 0 downloads 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> Say I have this query: site.com?var=1 ..I have a form with 'var2' field which submits via get. Is there a way to produce: site.com?var=1&var2=formdata I was hoping there would be a quick way to affix, but can't find any info. Also, the query could sometimes be: site.com?var2=formdata&var=1 I would have to produce: site.com?var2=updatedformdata&var=1 Is my only option to further parse the query? I'm trying to update every record where one field in a row is less than the other. The code gets each row i'm looking for and sets up the query right, I hope I combined the entire query into one string each query seperated by a ; so it's like UPDATE `table` SET field2= '1' WHERE field1= '1';UPDATE `table` SET field2= '1' WHERE field1= '2';UPDATE `table` SET field2= '1' WHERE field1= '3';UPDATE `table` SET field2= '1' WHERE field1= '4';UPDATE `table` SET field2= '1' WHERE field1= '5'; this executes properly if i run the query in phpMyAdmin, however when I run the query in PHP, it does nothing... Any advice? I was just wondering if it's possible to run a query on data that has been returned from a previous query? For example, if I do Code: [Select] $sql = 'My query'; $rs = mysql_query($sql, $mysql_conn); Is it then possible to run a second query on this data such as Code: [Select] $sql = 'My query'; $secondrs = mysql_query($sql, $rs, $mysql_conn); Thanks for any help here's the code: Code: [Select] $companyName = 'big company'; $address1 = 'big bay #8'; $address2 = 'some big warehouse'; $city = 'big city'; $province = 'AB'; $postalCode = 'T1T0N0'; $phone = '0123456789'; $email2 = 'bigKahuna@bigKahuna.edu'; $query = "INSERT INTO clients ( companyName, address1, address2, city, province, postalCode, phone, email) VALUES ( ". $companyName.",".$address1.",".$address2.",".$city.",".$postalCode.",".$phone.",".$email2.")"; $result = mysql_query($query, $connexion); if ($result) { // Success! echo "Fabulous! check the DB, we did it! :D<br>"; ?> <pre> <?php print_r($result); ?> </pre> <?php } else { // Fail! echo"CRAAAAAPP! something went wrong. FIX IT! :P<br>"; echo mysql_error(); } if (isset($connexion)) { mysql_close($connexion); } i copied it over from an old *working* file to illustrate how a simple INSERT works. this is the error i get: 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 'company,big bay #8,some big warehouse,big city,T1T0N0,0123456789,bigKahuna@bigKa' at line 4 looks completely valid to me. all the database table elements are set to VARCHAR(80), so it can't be a space/type issue... halp! WR! What would be the correct way to close a mysql query? At current the second query below returns results from the 1st query AND the 2nd query The 3rd query returns results from the 1st, 2nd and 3rd query. etc etc. At the moment I get somthing returned along the lines of... QUERY 1 RESULTS Accommodation 1 Accommodation 2 Accommodation 3 QUERY 2 RESULTS Restaurant 1 Restaurant 2 Restaurant 3 Accommodation 1 Accommodation 2 Accommodation 3 QUERY 3 RESULTS Takeaways 1 Takeaways 2 Takeaways 3 Restaurant 1 Restaurant 2 Restaurant 3 Accommodation 1 Accommodation 2 Accommodation 3 Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php include($_SERVER['DOCUMENT_ROOT'].'/include/db.php'); ?> <title>Untitled Document</title> <style type="text/css"> <!-- --> </style> <link href="a.css" rel="stylesheet" type="text/css" /> </head><body> <div id="listhold"> <!------------------------------------------------------------------------------------------------------------------------------------------------------> <div class="list"><a href="Placestostay.html">Places To Stay</a><br /> <?php $title ="TITLE GOES HERE"; $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Accommodation' AND confirmed ='Yes' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) {$i++; $FileName = str_replace(' ','_',$nt[$i]) . ".php"; $FileUsed = str_replace('_',' ',$nt[$i]); echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>" . $nt[$i] . "</a>" . "<br/>"; $FileHandle = fopen($FileName, 'w') or die("cant open file"); $pageContents = file_get_contents("header.php"); fwrite($FileHandle,"$pageContents");} fclose($FileHandle); ?> </div> <!------------------------------------------------------------------------------------------------------------------------------------------------------> <div class="list"><a href="Eatingout.html">Eating Out</a><br /> <?php $title ="TITLE GOES HERE"; $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Restaurant' AND confirmed ='Yes' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) {$i++; $FileName = str_replace(' ','_',$nt[$i]) . ".php"; $FileUsed = str_replace('_',' ',$nt[$i]); echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>" . $nt[$i] . "</a>" . "<br/>"; $FileHandle = fopen($FileName, 'w') or die("cant open file"); $pageContents = file_get_contents("header.php"); fwrite($FileHandle,"$pageContents");} fclose($FileHandle); ?> </div> <!------------------------------------------------------------------------------------------------------------------------------------------------------> <div class="list"><a href="Eatingin.html">Eating In</a><br /> <?php $title ="TITLE GOES HERE"; $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Takeaways' AND confirmed ='Yes' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) {$i++; $FileName = str_replace(' ','_',$nt[$i]) . ".php"; $FileUsed = str_replace('_',' ',$nt[$i]); echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>" . $nt[$i] . "</a>" . "<br/>"; $FileHandle = fopen($FileName, 'w') or die("cant open file"); $pageContents = file_get_contents("header.php"); fwrite($FileHandle,"$pageContents");} fclose($FileHandle); ?> </div> <!------------------------------------------------------------------------------SKILLED TRADES BELOW---------------------------------------------------> <div class="list"><a href="Skilledtrades.html">Skilled Trades</a><br/> <?php $title ="TITLE GOES HERE"; $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Skilled Trades' AND confirmed ='Yes' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) {$i++; $FileName = str_replace(' ','_',$nt[$i]) . ".php"; $FileUsed = str_replace('_',' ',$nt[$i]); echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>" . $nt[$i] . "</a>" . "<br/>"; $FileHandle = fopen($FileName, 'w') or die("cant open file"); $pageContents = file_get_contents("header.php"); fwrite($FileHandle,"$pageContents");} fclose($FileHandle); ?> </div> 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? |