cspgsl Posted May 5, 2006 Author Share Posted May 5, 2006 Apart from the code, I must admit that I'm having trouble visualizing how to put this in an update record form... Quote Link to comment https://forums.phpfreaks.com/topic/9141-sql-not-returning-results/page/2/#findComment-33744 Share on other sites More sharing options...
alpine Posted May 5, 2006 Share Posted May 5, 2006 [!--quoteo(post=371713:date=May 5 2006, 04:21 PM:name=cspgsl)--][div class=\'quotetop\']QUOTE(cspgsl @ May 5 2006, 04:21 PM) [snapback]371713[/snapback][/div][div class=\'quotemain\'][!--quotec--]Apart from the code, I must admit that I'm having trouble visualizing how to put this in an update record form...[/quote]As far as i know, no-one is born with programming skills :) - we all learn something new almost every single day we do this. Quote Link to comment https://forums.phpfreaks.com/topic/9141-sql-not-returning-results/page/2/#findComment-33746 Share on other sites More sharing options...
cspgsl Posted May 5, 2006 Author Share Posted May 5, 2006 I have always thought it better to be born lucky than smart however, this learning curve is very enjoyable. I would just like to learn at a little more competent rate though... That seems to have resolved it, [b]thank you, thank you[/b]Now if someone could point me in the direction of creating an update record form and incorporating the code I could go to bed and actually sleep tonite. [!--quoteo(post=371715:date=May 5 2006, 05:24 PM:name=alpine)--][div class=\'quotetop\']QUOTE(alpine @ May 5 2006, 05:24 PM) [snapback]371715[/snapback][/div][div class=\'quotemain\'][!--quotec--]As far as i know, no-one is born with programming skills :) - we all learn something new almost every single day we do this.[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/9141-sql-not-returning-results/page/2/#findComment-33749 Share on other sites More sharing options...
alpine Posted May 6, 2006 Share Posted May 6, 2006 [code] <?phpecho $kt_login_user;print "<p> </p>";if(isset($_POST['update'])){$new_msg = htmlspecialchars($_POST['welcome'])$sql = mysql_query("update users set welcome = '$new_msg' where username = '$kt_login_user'");if($sql){ print "<b>Saved!</b>";}}$qry = mysql_query("SELECT welcome FROM users WHERE username = '$kt_login_user' limit 1");$r = mysql_fetch_array($qry);$kt_welcome = $r['welcome'];if(!$kt_welcome){$kt_welcome = "My default text";}echo <<<__HTML_END<form method="post" action="this_page.php"><textarea name="welcome" cols="80" rows="20">$kt_welcome</textarea><br /><input type="submit" name="update" value="Save" /></form>__HTML_END;mysql_close();?>[/code]This allows the textfield to be posted blank/empty Quote Link to comment https://forums.phpfreaks.com/topic/9141-sql-not-returning-results/page/2/#findComment-33795 Share on other sites More sharing options...
cspgsl Posted May 6, 2006 Author Share Posted May 6, 2006 Good day Alpine, it seems you sleep like I do.Your last code yesterday was working brilliantly until I resumed my online session this morning. For whatever reason the code broke overnight (internet gremlins???) which is strange as it worked for the hour or so of testing done at the end of yesterday's dialogue. The message I was getting this morning [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pencils/public_html/interview/home_page.php on line 56[/quote] was familiar so I placed an @ sign in front of [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]mysql_fetch_array($qry);[/quote] and it resolved the problem and it worked for a short time.I then retested it several more times. Logged in and out several times, closed and re-opened the browser, tried it in IE and FX and Netscape and found that "My default text" is returned regardless of the user. I tried your latest post but get the following error [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Parse error: parse error, unexpected T_VARIABLE in /home/pencils/public_html/interview/home_page.php on line 57[/quote] where this is the line of offending line [code]$sql = mysql_query("update users set welcome = '$new_msg' where username = '$kt_login_user'");[/code]Sorry to be such a pain... Quote Link to comment https://forums.phpfreaks.com/topic/9141-sql-not-returning-results/page/2/#findComment-33831 Share on other sites More sharing options...
alpine Posted May 6, 2006 Share Posted May 6, 2006 hi again, dont worry - we are solving a problem.As to the parse error i forgot (sorry) to end a variable set with [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--];[!--colorc--][/span][!--/colorc--]Now - as to your fetch array warning, this (also your previous num_rows problems) indicates a problem when querying against the database - are you 100% sure there are no misspelling in column names used?? By adding a @ only means it wont print out the warning msg, it still fails like when you are getting the warning printed out - surpress errors with caution (don't mis-use @)The following i have tested with hard coded username - and it works 100% every time.Test it and see what u get, i've added mysql_error():[code]<?php// require("secret/db_connection.php");// $kt_login_user = "tom"; // replaces the SESSION to testecho $kt_login_user;if(isset($_POST['update'])){$new_msg = htmlspecialchars($_POST['welcome']);$sql = mysql_query("update users set welcome = '$new_msg' where username = '$kt_login_user'") or die(mysql_error());if(mysql_affected_rows()==1){ print "<b>Text updated!</b><br />";}else{ print "<b>Warning: no changes where made</b><br />";}}$qry = mysql_query("SELECT welcome FROM users WHERE username = '$kt_login_user'") or die(mysql_error());if(mysql_num_rows($qry)==1){$r = mysql_fetch_array($qry);$kt_welcome = $r['welcome'];}else{ print "<b>Warning: unique user not found</b><br />";}if(!$kt_welcome){$kt_welcome = "My default text";}echo <<<__HTML_END<form method="post" action="this_page.php"><textarea name="welcome" cols="80" rows="20">$kt_welcome</textarea><br /><input type="submit" name="update" value="Save" /></form>__HTML_END;mysql_close();?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9141-sql-not-returning-results/page/2/#findComment-33868 Share on other sites More sharing options...
cspgsl Posted May 6, 2006 Author Share Posted May 6, 2006 [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] dont worry - we are solving a problem. [/quote] Humble thanks[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]end a variable set with ;[/quote] I should have caught that one...[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]no misspelling in column names used?? [/quote] I take it that the names are as in the session list in the bindings window (I am using Dreamweaver MX and MX Kollection). There are no errors as the selections are made from the session in bindings [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--](don't mis-use @)[/quote] good point, thanks[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] following i have tested[/quote]I took this and pasted it into the page changing the form action to a page in my site. Upon opening the page the text from the user's record is there and has not failed. When I click Save it opens the file I specified. In reading through the code it would appear that it should update the record however, it does not. Instead what happens is if I go back to the update page I get a message "No database selected" and the balance of the page below echo $kt_login_user; is blank (view source reveals no content). If I click on Back and then return to the update page the same No database message is there. It requires logging out once to reset it to work again. In any event, the field is not updated. Quote Link to comment https://forums.phpfreaks.com/topic/9141-sql-not-returning-results/page/2/#findComment-33880 Share on other sites More sharing options...
alpine Posted May 6, 2006 Share Posted May 6, 2006 If your session username finds a valid user it should work - the code i suplied has form action pointed on itself - one file handling both view stored and update.You dont get any mysql errors either ??** edit ** i see your edited post about no db selected, how do you connect then??Like this works:[code]$dbhostname = "xxx";$dbuser = "xxx";$dbpassword = "xxx";$db = "xx";$connect = mysql_connect($dbhostname, $dbuser, $dbpassword) or die("unable to connect to db");$choose = mysql_select_db("$db") or die("Unable to select db");[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9141-sql-not-returning-results/page/2/#findComment-33883 Share on other sites More sharing options...
cspgsl Posted May 6, 2006 Author Share Posted May 6, 2006 [!--quoteo(post=371861:date=May 6 2006, 03:31 PM:name=alpine)--][div class=\'quotetop\']QUOTE(alpine @ May 6 2006, 03:31 PM) [snapback]371861[/snapback][/div][div class=\'quotemain\'][!--quotec--]If your session username finds a valid user it should work - the code i suplied has form action pointed on itself - one file handling both view stored and update.You dont get any mysql errors either ??[/quote]If you are referring to [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]action="this_page.php"[/quote] it consistently returns "No Database selected" regardless of teh user I log in with. My process goes from a login page to a page with sevearl links, one of which is a link to the update page (there will be a few update pages by the time I'm done). Could it have anything to do with that?I don't get the mysql error that the @ sign fixed (the @ sign is [u]no longer[/u] in the page)Alpine:I have to walk the dogs or else they will pee on my carpets and the wife will get mad; you know, she who must be obeyed...Back in about an hour.Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/9141-sql-not-returning-results/page/2/#findComment-33886 Share on other sites More sharing options...
alpine Posted May 6, 2006 Share Posted May 6, 2006 could you provide how you connect to your db, and if you are including this as a file with include(), require(), require_once() etc.using --> require("path/dbfile.php"); where dbfile.php contains my previous db connection setup is tested and is working. Form action you put to $_SERVER[PHP_SELF] or the actual name you have chosen for this file, for example "update_welcome.php" or whatever.? so - you still have your wife ??!!!! *lol* Quote Link to comment https://forums.phpfreaks.com/topic/9141-sql-not-returning-results/page/2/#findComment-33889 Share on other sites More sharing options...
cspgsl Posted May 6, 2006 Author Share Posted May 6, 2006 [code] <? session_start(); if (!isset($_SESSION['kt_login_user'])): $_SESSION['kt_login_user'] = "Anonymous"; $_SESSION['kt_name'] = $_POST['kt_name']; $_SESSION['kt_welcome'] = $_POST['kt_welcome'];endif;error_reporting(E_ALL);?><?php require_once('../../Connections/connBSD.php'); ?>[/code]Contents of Connections/connBSD.php [code]<?php# FileName="Connection_php_mysql.htm"# Type="MYSQL"# HTTP="true"$hostname_connBSD = "localhost";$database_connBSD = "pencils_users";$username_connBSD = "pencils_cspgsl";$password_connBSD = "drtlk001";$connBSD = mysql_pconnect($hostname_connBSD, $username_connBSD, $password_connBSD) or trigger_error(mysql_error(),E_USER_ERROR); ?>[/code]The No database selected only appears after I click on Save. Even then, the echo $kt_login_user; returns a resultWife is off antique hunting and has the dog's leads in the car... no my fault. I let them out in the backyard, that should keep the carpets clean but there goes the grass (oh my).See last post[!--quoteo(post=371867:date=May 6 2006, 03:56 PM:name=alpine)--][div class=\'quotetop\']QUOTE(alpine @ May 6 2006, 03:56 PM) [snapback]371867[/snapback][/div][div class=\'quotemain\'][!--quotec--]could you provide how you connect to your db, and if you are including this as a file with include(), require(), require_once() etc.[/quote][!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]using --> require("path/dbfile.php"); where dbfile.php contains my previous db connection setup is tested and is working. Form action you put to $_SERVER[PHP_SELF] or the actual name you have chosen for this file, for example "update_welcome.php" or whatever.[/quote]I changed it to return to the page opened from logging on (with the multiple links) Quote Link to comment https://forums.phpfreaks.com/topic/9141-sql-not-returning-results/page/2/#findComment-33890 Share on other sites More sharing options...
alpine Posted May 7, 2006 Share Posted May 7, 2006 try changing --> require_once('../../Connections/connBSD.php');to --> require('../../Connections/connBSD.php');I've seen this problem in another thread some time ago, the "once" makes fuzz sometimes -Also change your content of connBSD.php to this(inserting your names and passwords ofc):[code]$hostname_connBSD = "xxxx";$database_connBSD = "xxxx";$username_connBSD = "xxxx";$password_connBSD = "xxxx";$connBSD = mysql_connect($hostname_connBSD, $username_connBSD, $password_connBSD) or trigger_error(mysql_error(),E_USER_ERROR);$selectDB = mysql_select_db("$database_connBSD") or die("Unable to select db");[/code]- Quote Link to comment https://forums.phpfreaks.com/topic/9141-sql-not-returning-results/page/2/#findComment-33985 Share on other sites More sharing options...
cspgsl Posted May 7, 2006 Author Share Posted May 7, 2006 Good morning again. It's now questionable as to who I am talking with more... you or my wife #lolIt would appear that this change has made all the difference with respect to eliminating any errors on opening the update page. [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]try changing --> require_once('../../Connections/connBSD.php');to --> require('../../Connections/connBSD.php');[/quote]I added this too[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Also change your content of connBSD.php to this$selectDB = mysql_select_db("$database_connBSD") or die("Unable to select db");[/code][/quote]I went back and inserted your post from yesterday morning (below) where you indicated there was a parse error and it is now working without error except that it isn't updating the user's record.[code] <?phpprint "<p> </p>";if(isset($_POST['update'])){$new_msg = htmlspecialchars($_POST['welcome']);$sql = mysql_query("update users set welcome = '$new_msg' where username = '$kt_login_user'");if($sql){ print "<b>Saved!</b>";}}$qry = mysql_query("SELECT welcome FROM users WHERE username = '$kt_login_user' limit 1");$r = mysql_fetch_array($qry);$kt_welcome = $r['welcome'];if(!$kt_welcome){$kt_welcome = "My default text";}echo <<<__HTML_END<form method="post" action="entree.php"><textarea name="welcome" cols="80" rows="20">$kt_welcome</textarea><br /><input type="submit" name="update" value="Save" /></form>__HTML_END;mysql_close();?>[/code]Also, your last code starting [code]// require("secret/db_connection.php");[/code] also works but, it does not updating the user's record either.I have printed out your code and I am now trying to understand what each line does. I'm sure I will be back to you with questions. Quote Link to comment https://forums.phpfreaks.com/topic/9141-sql-not-returning-results/page/2/#findComment-34000 Share on other sites More sharing options...
alpine Posted May 7, 2006 Share Posted May 7, 2006 but work on the following posted code: [a href=\"http://www.phpfreaks.com/forums/index.php?s=&showtopic=92839&view=findpost&p=371846\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...ndpost&p=371846[/a]I see you have fallen back to another one :)Remember also that when you set/start a new session, it wont take effect untill the next pageload, meaning setting a session and using it on the same code without reloading the page wont work - i am beginning to think you might have several different issues that all needs to be fixed - so start with one code and work your way. Quote Link to comment https://forums.phpfreaks.com/topic/9141-sql-not-returning-results/page/2/#findComment-34049 Share on other sites More sharing options...
cspgsl Posted May 7, 2006 Author Share Posted May 7, 2006 Sorry, I am afraid you lost me. Are you suggesting that I use the code as in the following post? (your quote): [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]but work on the following posted code: [a href=\"http://www.phpfreaks.com/forums/index.php?s=&showtopic=92839&view=findpost&p=371846\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...ndpost&p=371846[/a][/quote]That is going back to the beginning, isn't it?[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]I see you have fallen back to another one :)[/quote] I am using the last one you sent with the opening comments[code]//require("secret/db_connection.php");// $kt_login_user = "tom"; // replaces the SESSION to test[/code] I also tried the code you sent where you indicated there was a parse error [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--][a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=92839&pid=371771&mode=threaded&show=&st=30entry371771\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...30entry371771[/a][/quote] and I was indicating that it was returning the contents of the user's record without error. The only thing was if I changed it it was not updating the user's record. [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Remember also that when you set/start a new session, it wont take effect untill the next pageload, meaning setting a session and using it on the same code without reloading the page wont work[/quote]Are you referring to seeing the changes made without logging out and restarting the session?i am beginning to think you might have several different issues [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] not the leaset of which is being very green[/quote] that all needs to be fixed Thanks Quote Link to comment https://forums.phpfreaks.com/topic/9141-sql-not-returning-results/page/2/#findComment-34063 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.