Retrieving sql data in iframes - sql

I have a php script (ini.php), that open in an iframe inside of "main.php":
<iframe src='ini.php' style='width:650px;' frameborder='0' id="IDMain" allowtransparency="YES" scrolling="NO"></iframe>
The SQL does not retrieve the data in "ini.php".
But if I incorporate the code of "ini.php" in "main.php", without using an iframe, the query retrieves all the information.
I must have an iframe in order to change all the different scripts in the same iframe.
Any help here?
Thanks
In addition more information:
The main.php is in session after logged. Previously I had the whole frame repeated in each script, and everything was ok.main.php, ini.php, and so on. Each script with header, left, right, main and footer. To make it faster and easier I decide to make the main script called main.php, that with an included script called config.inc.php that has several functions, also connects to data base, to retrieve some data to the header, left , right and footer sides of the main area (iframe) where the others different scripts, just to opens inside of a iframe, maintaining the information around. Each script, (like ini.php), that runs in the iframe also include the config.inc.php file, to connect as well to database. But does not retrieve any information
The connection to database in config script is:
<$connect=mysql_connect ("localhost","database","password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("database", $connect) or die ("'I cannot connect to the database "); >
The query in ini,php (and others) is:
`
if ($id) {
$id_session=$_SESSION['id_session'];
$namesession=$_SESSION['name_session'];
$sql="select * from data where id='$id_sessino' limit 1 ";
$result=mysql_db_query("database",$sql);
$regist=mysql_fetch_array($result);
$id=$regist["id"];
$id_session=$regist["id"];
$namesession=$regist["name_session"];
$country=$regist["country"];
And soo on…
}
`
I hope with is information it makes it clear what do I mean. Thank you

Check PHP help for mysql_db_query. Since you are not giving it any open db link, it tries to do some default magic, which likely fails, because, as I mentioned in the comment, the two scripts (in parent window and inside the iframe) are run separately and have no idea about each other *unless you are doing some synchronizing, that isn't shown in the code snippets. That means that the iframe script doesn't know anything about the connection you've opened in the parent page, and fails. Check your logs, you should see some E_WARNING complaints (if you are logging this level).
Also, as the documentation says, you might be better off with MySQLi or PDO_MySQL extensions. But the principle will remain the same - the script in questoin has to have an open connection to the database (and I'm not sure whether you can easily and safely transfer an open from one script to the other one, so you'll likely have to do it all in the iframe script).

Try two things, first I would change the MySQL_fetch_array part to
While($regist = mysql_fetch_array($result))
{
//Code goes here
}
Secondly try referring to the array vales as numbers rather than names, so regist['id'] would become regist[0]. They will be in the order the are in the database.
Also since you select your database when creating connection why not just use mysql_query("QUERY HERE"); Rather than mysql_db_query

Related

How can i manage a global variable among different webpages in wix?

I am developing a site for online test series. I receive details o student on one page and wish to display the info on net page as dashboard. I need a global variables that can hold the detail of student like his roll no, name, email, class, semester, subject and the test he wishes to solve.
I have tries using a separate .js file to hold variables. However, the values of variables get lost as i move to next page.
can anyone help?
The code and links are attached.
https://ishuuw.wixsite.com/ymatutor/test-series
//import wixData from 'wix-data';
import {globalVars} from 'public/vars.js';
$w.onReady(function () {
});
export function button2_click(onClick,button2){
globalVars.StudentRoll=$w('#input1').value
globalVars.StudentName=$w('#input5').value
globalVars.StudentSurname=$w('#input6').value
globalVars.StudentMail=$w('#input7').value
globalVars.StudentClass=$w('#dropdown1').value
globalVars.StudentYear=$w('#dropdown2').value
globalVars.StudentSemester=$w('#dropdown3').value
globalVars.StudentPaper=$w('#dropdown5').value
globalVars.StudentTest=$w('#dropdown6').value
//Just to test, this works well
$w('#text63').text=globalVars.StudentRoll
$w('#text64').text=globalVars.StudentName
$w('#text65').text=globalVars.StudentSurname
$w('#text66').text=globalVars.StudentMail
$w('#text67').text=globalVars.StudentClass
$w('#text68').text=globalVars.StudentYear
$w('#text69').text=globalVars.StudentSemester
$w('#text70').text=globalVars.StudentPaper
$w('#text71').text=globalVars.StudentTest
}
`
Sounds like you should be using wix-storage. That will allow you to pass information between pages.
Use local storage if you want the data to persist for the user even after the user ends the session. Meaning, next session, the user's data will still be available.
Use session storage if you want the data to be removed when the user's session ends.

PleaseWaitButton in perl? loading gif etc. during long sql query

I have a web app that is all run via one perl file that works with a database. At one point the user can execute an action that takes a lot of time (it adds a bunch of rows from one table to another). Is there a way I can have a wait .gif or message show while the sql is executing, and then have it disappear once it's over? I'm pretty new to perl, saw that this was possible through Javascript and the PleaseWaitButton though. Any help would be much appreciate though. My code for the lengthy update part is below, so I image whatever thing would need to be inserted somewhere in there:
if((#inTable[0])==0){
my $update = `perl /stockhistory.pl
my #updatearray = split(" ", $update);
my $val;
for(my $i = 0; $i < scalar #updatearray; $i+=6){
$val = eval{ExecSQL($dbuser, $dbpasswd, "insert into PORT_ModernData (SYMBOL, TIME, OPEN, HIGH, LOW, CLOSE, VOLUME) VALUES (?,?,?,?,?,?,?)",undef, $stocksy,, $updatearray[$i], $updatearray[$i+1], $updatearray[$i+2], $updatearray[$i+3], $updatearray[$i+4], $updatearray[$i+5]);};
}
}
Thanks for any and all help!
The way I understand your problem, I would suggest Javascript, though I do like avoiding it myself.
This way, the user can click the button, triggering the sql get, and the message comes up, while the server does what it does, when done, Javascript can tell the user so and provide the link, data or whatever the result is.
With perl, this would involve a more complicated procedure including further server/client communication.
I would gladly be corrected, though, if anyone knows better.

GetResource, dynamic parent.

my problem is the following. I'm currently making a blog-page with get-page, get-resources, form-it, and wayfinder. This question requires a decent amount of knowledge about Modx and snippits. I've got the page numberin and all working and i've got a template page with all my calls in it (called weblogTemplate). This template has the following wayfinder call in it :
[[!getResources? &parents=`5` &limit=`5` &tpl=`blogPost`]]
[[!getPage?
&elementClass=`modSnippet`
&element=`getResources`
&parents=`4`
&depth=`2`
&limit=`5`
&pageNavOuterTpl=`[[+first]][[+prev]][[+pages]][[+next]][[+last]]`
&pageVarKey=`page`
&pageFirstTpl=`<li class="controlFirst"><a[[+classes]][[+title]] href="[[+href]]">Eerste pagina</a></li>`
&pageLastTpl=`<li class="controlLast"><a[[+classes]][[+title]] href="[[+href]]">Laatste pagina</a></li>`
&pagePrevTpl=`<li class="controlPrev"><a[[+classes]][[+title]] href="[[+href]]"><<</a></li>`
&pageNextTpl=`<li class="controlNext"><a[[+classes]][[+title]] href="[[+href]]">>></a></li>`
&includeTVs=`1`
&includeContent=`1`
&tpl=`blogListPost`
]]
as you can see the parent is set here to id number 5. This is fine for the homepage but any child page connected in the blog page also uses the same template and so would also have the same menu as the parent. You could use a fix to simply create 1 template for a page and keep using a different getResource call but keep in mind that it is a blog im making, new pages keep getting added. The user can't (, and wouldn't even understand to) make a template and edit any code. A solution i thought of would be to make the parent id dynamic, so it adjust to whatever page it is currently on. So for example if it was on the page with id number 12 it would make the parent call set to 12 and so show all the content under id number 12. If anyone has any ideas / thoughts / solutions i would be very grateful to hear them.
(a link about wayfinder that i used.)
The best solution would be to use two templates - one for main and one for the blog pages and use in blog templates:
&parents=`[[*id]]`
The problem with the user solveds by setting default_template in the system settings.
This worked for me:
[[!getPage?
&elementClass=`modSnippet`
&element=`getResources`
&parents=`[[*id]]`
&depth=`0`
&limit=`10`
&pageNavOuterTpl=`[[+first]][[+prev]][[+pages]][[+next]][[+last]]`
&pageVarKey=`page`
&pageFirstTpl=`<li class="controlFirst"><a[[+classes]][[+title]] href="[[+href]]">Eerste pagina</a></li>`
&pageLastTpl=`<li class="controlLast"><a[[+classes]][[+title]] href="[[+href]]">Laatste pagina</a></li>`
&pagePrevTpl=`<li class="controlPrev"><a[[+classes]][[+title]] href="[[+href]]"><<</a></li>`
&pageNextTpl=`<li class="controlNext"><a[[+classes]][[+title]] href="[[+href]]">>></a></li>`
&includeTVs=`1`
&includeContent=`1`
&tpl=`blogListPost`
]]
Thanks to Vasis for the provided help.

Change database of a ColdFusion website

I'm newbie in ColdFusion.
I have a running ColdFusion website I'd like to update. I've copy the database to make some test, in the ColdFusion manager I have created a new datasource with the copied database. But now how can I tell my website that it need to use the copied database?
Thanks
Look in your code and find any cfquery tags and make sure they are using the new dsn in the datasource attribute. Depending on how the code is written, there may be a global variable that holds the dsn and you can just change it there.
Now that you have a test database, you probably want to use conditional logic to determine which one to use. Here is an example from one of my files.
<cfscript>
if (cgi.path_info contains "dwtest") {
dsn = "AntibioticsTest";
} else {
dsn = "Antibiotics";
}
</cfscript>
<cfquery name="GetLastInsertDates" datasource="#dsn#">
sql not relevent
</cfquery>
As mentioned in jhinkley's answer, this variable might be a global variable in which case it's most likely found in Application.cfc.

Connection strings for different users

How do I send two users coming from different company domains to different SQL databases to retrieve/store data? I use Application variables to store the connection strings and the Request.ServerVariables("LOGON_USER") variable is an effective way to get the domain name. Is the GLOBAL.AsA file to be modified? The table names are exactly the same in both databases, so I think changing the connection strings based on the user domain should do the trick.
User A with domain ABC --> Application("ConnecttoDB") send to database A
User B with domain XYZ --> Application("ConnecttoDB") send to database B
I have roughly 900+ classic ASP pages so I would really hate to add a bunch of IF-THEN's to choose the correct database in each page. All ideas are greatly appreciated!
UPDATE: To make things simple I'm envisioning one single Application variable (i.e.: ConnecttoDB) However, wouldn't its value be constantly changing every time a different user gets access and altering page results?
You can't use an Application variable since that's shared across all users. This would be a race condition. Instead you'll need to use the Session object to store the connection and then use that whenever you need to connect to the DB.
myDB=Server.CreateObject("ADODB.Connection")
StrConn = Session("ConnecttoDB")
myDB.Open StrConn
Here's one way of doing it:
I'm guessing that your classes for your web page codebehind files inheit the Page class. Create a new class file in your ASP.net project that inherits Page. Call it JorgePage. Then, make your codebehind file classes inherit JorgePage.
In JorgePage, write two functions:
private string getUsersDomain()
{
// returns the user's domain
}
protected string getUsersConnectionString()
{
switch (getUsersDomain().ToUpper())
{
case "ABC":
return Application("ConnecttoDB_ABC");
break;
case "xYZ":
return Application("ConnecttoDB_XYZ");
break;
}
}
Now, the function getUsersConnectionString() is available in the context of all your pages and returns the correct connection string. Furthermore, you have the code in only one place, so if you need to change the logic later, you can do so easily.
Given that you're using classic ASP, you can define a function to return the appropriate connection string in another .asp file and use the #include directive to add it to all your pages.