hielo 65 Veteran Poster

change: <input type="submit" name="submit" id="submit" value="Submit"> to: <input type="submit" name="Submit" id="Submit" value="Submit"> uppercase "S" for the name and id. Do not use lower case since it is reserved for javascript.

As for your problem (with the current submit button), it is on line 138. Change the input field as suggested above and leave line 38 as it currently is.

hielo 65 Veteran Poster

change: page_request.onreadystatechange=function(page_request, containerid){ to: page_request.onreadystatechange=function(){ if you leave them there, then they will be undefined within the onreadystatechange function unless you explicitly pass those values. But you do not need to do this since the variables of function ajaxpage() are visible within the onreadystatechange function.

hielo 65 Veteran Poster

When you create a table, you need to specify the engine - ex:

CREATE TABLE `dbName`.`tableName` (
 ...
)
ENGINE = INNODB
CHARACTER SET utf8 COLLATE utf8_general_ci;

By default, it is MyIsam. As a matter of fact, line 7 of your post CLEARLY shows that MyISAM IS the default engine on your db server.

Your post simply confirms that your DB "supports" InnoDB IF you choose to use it on your tables, but you have to specify which engine to use on the tables. If you don't it will assume you meant MyISAM, which does NOT support constraints.

All the tables involved in the relationship constraints will need the InnoDB storage engine.

hielo 65 Veteran Poster

save this as hielo.html and try it:

<!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" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>test page</title>

<script type="text/javascript">

function ajaxpage(url, containerid){
	page_request = false;
	if (window.XMLHttpRequest){ // if Mozilla, Safari etc
		page_request = new XMLHttpRequest()
	}
	else if (window.ActiveXObject){ // if IE
		try {
			page_request = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e){
			try{
				page_request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				return false;
			}
		}
	}
	else{
		return false;
	}
	page_request.onreadystatechange=function(page_request, containerid){
		if (page_request.readyState == 4 && (page_request.status==200 || window.location.protocol.indexOf("http")==-1)){
			document.getElementById(containerid).innerHTML=page_request.responseText;
			page_request=null;
		}
	}

	page_request.open('GET', url, true);
	page_request.send(null);
return false;
}


</script>
</head> 

<html>
<body>
	<div id="leftdiv" style="float:left;">
		<a href="#" onclick="return ajaxpage('page1.htm', 'rightdiv');">Menu1</a>
		<a href="#" onclick="return ajaxpage('page2.htm', 'rightdiv');">Menu2</a>
		<a href="#" onclick="return ajaxpage('page3.htm', 'rightdiv');">Menu3</a>
	</div>
	<div id="rightdiv" style="float:right;"></div>
</body>
</html>
hielo 65 Veteran Poster

all you need to do is use preg_replace() to remove the unwanted set of characters.

//your initial string
$str = 'img*1L%^_ove>ly.jpg';

/*
//this removes anything that is NOT
//a,b,c,....z
//A,B,C,...Z
//0,1,2,...9
//In other words, it KEEPS only a-z, A-Z, and 0-9. 
//If you want other character(s), simply add 
//it(them) immediately after the "9"
*/
$str = preg_replace('#[^a-zA-Z0-9]#','',$str);
hielo 65 Veteran Poster

In details.php you would need something similar to:

<?php
mysql_connect("localhost", "username", "password") or die( mysql_error() );
mysql_select_db("dbname")  or die( mysql_error() );

$sql =sprintf('SELECT * FROM job_profile WHERE id=%d', intval($_GET['id']);
$result = mysql_query( $sql ) or die( "Error executing:<br>$sql<br>".mysql_error() ) ;

if( mysql_num_rows($result) )
{
  echo '<div>No records found</div>';
}
else
{
  $row=mysql_fetch_assoc($result);
  echo '<table><thead>';
  echo '<tr><th>' . implode('</th><th>', array_keys($row)) . '</th></tr></thead><tbody>';
  do{
    echo '<tr><td>' . implode('</th><th>', $row) . '</td></tr>';
  }while($row=mysql_fetch_assoc($result));
  echo '</tbody></table>';
}
?>
hielo 65 Veteran Poster

You are welcome.

Regards,
Hielo

hielo 65 Veteran Poster

on line 2 you forgot to call mysql_query() so that it ACTUALLY executes the query. You are simply assigning a string (the sql statement) to $blogpost.

hielo 65 Veteran Poster

Make sure your tables are using InnoDB Storage engine and then try:

ALTER TABLE `ORDERS` ADD FOREIGN KEY(`CUSTOMER_NUM`) REFERENCES `CUSTOMER`(`CUSTOMER_NUM`);
hielo 65 Veteran Poster

try my post.

SELECT blogpost, DATE_FORMAT(dateandtime,'%M %e %Y at %h:%i%p') as dateandtime FROM TABLENAME

just replace TABLENAME with the actual name of your table.

hielo 65 Veteran Poster

I meant to write "it looks like in your db field `profileid`..."

Based on the link you posted, your links have

href="http://hvn.org.uk/searchengine/details.php?id=<?php echo 1; ?>"

but it should be simply:

href="http://hvn.org.uk/searchengine/details.php?id=1"

hence my suspicion that your table field has PHP code instead of just a unique numeric value.

hielo 65 Veteran Poster

AFTER page_request.send(null) put return false; AND
change these:

<a href="javascript:ajaxpage('pageX.htm', 'rightdiv');">MenuX</a>

to:

<a href="#" onclick="return ajaxpage('pageX.htm', 'rightdiv');">MenuX</a>

where "X" is 1, 2, etc.

hielo 65 Veteran Poster

it should like in your db field `profileid` you have PHP code instead of just a number. Make sure you have a unique number in it.

hielo 65 Veteran Poster

line 54 should be id="rightdiv" NOT class="rightdiv" . Also, get rid of that "dangling" left;

hielo 65 Veteran Poster

instead of

SELECT * ...

use:

SELECT blogpost, DATE_FORMAT(dateandtime,'%M %e %Y at %h:%i%p') as dateandtime ...
hielo 65 Veteran Poster

give them a result as a link which able to redirect them based on their search

assuming your search.php page is doing:

$query = "SELECT linkURL, linkText FROM Resources WHERE linkText LIKE '%{$searchTerm}%'";

(where Resources is your table name) and then generating:

<a href="http://remotesite.com">some text</a>

when you search the db, instead of getting that url ("http://remotesite.com"), be sure that your table has a unique ID for that Resource:

$query = "SELECT id, linkText FROM Resources WHERE linkText LIKE '%{$searchTerm}%'";

and then generate the following links instead:

<a href="search.php?id=37">some text</a>

where 37 is supposed to be the id you retrieved from your query originally. So when the user clicks on the link, the browser will go back to your search.php page, and $_GET will have the id of the link the user clicked. So, BEFORE you even do the SELECT query you would need to see if $_GET is present and if it is, then you query the db for the linkURL and then redirect the user.

<?php
$tableName='Resources';
//do your db connection stuff here


if( isset($_GET['id']) && !empty($_GET['id']) )
{
  $query=sprintf("SELECT linkURL FROM $tableName WHERE id=%d, intval($_GET['id']));  

  //here see if you get a result based on the above query. 
  ...
  
  If yes,
  {
    //then do an update statement 
    /*
    $query=sprintf("UPDATE clickTracker SET clicks = clicks+1 WHERE Resource_id=%d, intval($_GET['id'])); */

    //where $row['linkURL'] is the URL you were supposed to extract above.
    header("Location: " . $row['linkURL']);
    exit();
  }
} 

//here you would do your initial search:
$query = …
hielo 65 Veteran Poster

Are you always getting "ERROR" when you submit the form? If yes, then try changing $header="from: $name <$mail_from>"; to:

$header="From: " . $mail_from . PHP_EOL;
$header="To: " . $to.PHP_EOL;

If you are NOT seeing "ERROR", then check your spam folder.

hielo 65 Veteran Poster

name them with "array notation" syntax:

<input name="name[1]" />
<input name="father[1]" />

<input name="name[2]" />
<input name="father[2]" />

<input name="name[50]" />
<input name="father[50]" />

Then, when you post the data, that index will be used to find the related records:

<?php
//on every iteration, $numKey will vary from 1 to 50
//essentially setting $name to name[1], name[2],..., name[50] on every iteration AND
//the corresponding father[$numKey]
foreach( $_POST['father'] as $numKey=>$v )
{
  $name=$_POST['name'][$numKey];
  $father=$_POST['father'][$numKey];
}
?>
hielo 65 Veteran Poster
<textarea name='content' style='font-size:28px;' id='content' onfocus='this.style.fontSize="12px";' onblur='this.style.fontSize="28px"'>test</textarea>
hielo 65 Veteran Poster

Glad to help.

PS: Don't forget to mark this thread as Solved.

hielo 65 Veteran Poster

{ redirect_to(index.php); } needs to be in quotation marks: { redirect_to("index.php"); } Then go to index.php and make sure the page starts with:
<?php
session_start();

hielo 65 Veteran Poster

Glad to help.

Regards,
Hielo

hielo 65 Veteran Poster

I don't know what the cookies have to do with all of this. I can go to some url on your site, you assign me a cookie. I share the url with my friend, delete my cookies, then go back to your site with the same url and now you can't match my cookie against my url, so you wouldn't know if it is me or my friend.

The whole point of the url with the numbers is that I am the one who is "primarily responsible" for whatever lies behind your resource. The fact that I chose to share it with my friend is a different issue altogether. You could require a username/password upon accessing that resource, BUT if I really wanted to share it with my friend, I would give him/her that info as well. The reality of the situation, is that you have no guarantee that "the primary person" is accessing that url. So cookies will not help you much here.

hielo 65 Veteran Poster

assuming you have a unique identifier for each person (like an email address or an auto-incremented db id), you can combine it with time() and feed it to md5():

echo $tmp = md5($_SESSION['email'].time());

//you would then save this $tmp key onto a db table (make sure that the field you save it does NOT accept duplicate values) and include in some link.
//when the user clicks on that link, you should see that $tmp again, and then try
//to match it against what you saved on the db
hielo 65 Veteran Poster

...but replace the existing blank selection field in my form.

It's not clear to me what it is you are trying to do, but assuming you have: <input type="text" name="username" id="uName" value="" /> then if you change: document.getElementById('employ_data').innerHTML=xmlhttp.responseText; to: document.getElementById('uName').value=xmlhttp.responseText; then ONLY the value of the text field with id="uName" should be set to whatever your ajax request is returning.

hielo 65 Veteran Poster

If I want to run the file as http://localhost/, then I need a webserver like tomcat, don't I?

Yes, that's why I suggested WAMP, but if you have tomcat, go for it.

About suggestion a. This means I cannot post to another server, somewhere on the internet?

Actually, the is not a "suggestion" - it is a statement. For security purposes, AJAX restricts your requests to the same domain, so YES, it means you CANNOT post data to a remote server via ajax.

Since you want the data from the remote server, what you need to do is POST to the remote server from YOUR SERVER (not from your javascript). The same-domain restriction exists at the browser layer, NOT at the server layer.

So, if you still want to use ajax do it as follows:
http://yoursite.com/page.html -> http://yoursite.com/proxy.php -> http://remoteSite/com/postData.php

Explanation: Your page posts to YOUR own script (proxy.php). In turn, proxy.php takes the info posted to if from page.html and POSTs it to remote site and then sends the
result back to page.html

You can use CURL to post your data to the remote server:
http://davidwalsh.name/execute-http-post-php-curl

hielo 65 Veteran Poster
<?php
$start = strtotime("{$startdate} {$starthour}:{$startmin}");

$end =strtotime("+{$hour} hours +{$minute} minutes",$start);

echo 'Start Time'. date('Y-m-d H:i:s', $start);
echo 'End Time'. date('Y-m-d H:i:s', $start);
?>
hielo 65 Veteran Poster

a. make sure that you are posting to the same server where your test page resides
b. make sure you are posting to a page that ends in ".php"
c. make sure you have loaded your base via "http://localhost", and NOT as "file:///"

hielo 65 Veteran Poster

In ajax.php change $_GET to $_POST.
In index.php update the following javascript function:

function display_data(client_id) {
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null) {
        alert ("Your browser does not support AJAX!");
        return;
    }
    var url="ajax.php";
    var parameters="client_id="+client_id;
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete") {
            document.getElementById('employ_data').innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("POST",url,true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", parameters.length);
    xmlhttp.send(parameters);
}
hielo 65 Veteran Poster
<html> 
<head> 
<script> 

url = new Array(); 
url[0] = new Array(); 
url[0][0]=['http://www.URL1.com','http://www.URL9.com']; 
url[0][1]=['http://www.URL2.com','http://www.URL10.com']; 
url[0][2]=['http://www.URL3.com','http://www.URL11.com']; 
url[0][3]=['http://www.URL4.com','http://www.URL12.com']; 
url[0][4]=['http://www.URL5.com','http://www.URL13.com']; 
url[0][5]=['http://www.URL6.com','http://www.URL14.com']; 
url[0][6]=['http://www.URL7.com','http://www.URL15.com']; 
url[0][7]=['http://www.URL8.com','http://www.URL16.com']; 

url[1] = new Array(); 
url[1][0]=['http://www.URL17.com','http://www.URL25.com']; 
url[1][1]=['http://www.URL18.com','http://www.URL26.com']; 
url[1][2]=['http://www.URL19.com','http://www.URL27.com']; 
url[1][3]=['http://www.URL20.com','http://www.URL28.com']; 
url[1][4]=['http://www.URL21.com','http://www.URL29.com']; 
url[1][5]=['http://www.URL22.com','http://www.URL30.com']; 
url[1][6]=['http://www.URL23.com','http://www.URL31.com']; 
url[1][7]=['http://www.URL24.com','http://www.URL32.com']; 




function newURL(){
	var f=document.forms[0];
	try{
		var u = url[f.gender.selectedIndex][f.grade.selectedIndex][f.classroom.selectedIndex];
		alert(u);
		window.open(u,'_self');
	}catch(e){
		alert("All Fields are required");
	}
} 
</script> 
</head> 

<body> 
<form>
<select name="gender">
	<OPTION value="1">Girl</OPTION>
	<OPTION value="2">Boy</OPTION>
</select>

<select name="grade">
	<OPTION value="1">3rd Grade</OPTION>
	<OPTION value="2">4th Grade</OPTION>
	<OPTION value="3">5th Grade</OPTION>
	<OPTION value="4">6th Grade</OPTION>
	<OPTION value="5">7th Grade</OPTION>
	<OPTION value="6">8th Grade</OPTION>
	<OPTION value="7">9th Grade</OPTION>
	<OPTION value="8">10th Grade</OPTION>
</select>
<select name="classroom">
	<OPTION value="1">English</OPTION>
	<OPTION value="2">Math</OPTION>
</select>
<input type="button" onclick="return newURL()" value="Submit"> 
</form> 
</body> 
</html>
hielo 65 Veteran Poster

Hosted on an external server? I am using WAMP which means my server is my computer. So, does it mean that i can actually run my php-mysql script in my machine without internet connection? thank you!

Yes. I already answered that question. You just need to use "localhost" as your primary domain - ex:
http://localhost/index.php

should show you the homepage of your site.

hielo 65 Veteran Poster

Glad to help.

PS: Be sure to mark the thread as solved.

hielo 65 Veteran Poster

again, if the other page is hosted on an external server, then NO. You MUST have internet connection.

hielo 65 Veteran Poster

Glad to help.

PS: Don't forget to mark the thread as solved.

hielo 65 Veteran Poster

If you keep a field as "disabled" the browser will not submit/post the value to the server. You can change that to readonly instead and THEN it should submit the value of the text field.

hielo 65 Veteran Poster

try:

function submitform()
{
document.comm.submit();
setTimeout(function(){self.close();}, 50);
}
hielo 65 Veteran Poster

you need to make sure that in your html markup you have some element with id="skin_fenav1" ex: <div id="skin_fenav1">...</div>

hielo 65 Veteran Poster

If you are asking if you can run local php scripts (scripts that do not fetch anything from a remote website), then yes. Simply open your browser to
http://localhost/yourScript.php

However, if your php script is doing some curl request to some remote server (like google for example), then no. You need an internet connection for your script to find/get that external resource.

hielo 65 Veteran Poster

Does my UPDATE statement need to specify all the fields that it will update or does the " ... " take care of that?

When you execute an UPDATE you need to EXPLICITLY state which fields should be updated and provide the values for them.

So in the above, instead of the "..." I was expecting you to replace it with something like: UPDATE TableName SET `field1`='value1', `field2`='value2' WHERE condition Please, don't take this the wrong way, but based on the question above, I STRONGLY suggest you read an introductory sql tutorial:
http://w3schools.com/sql/default.asp

The little amount of time you spend on the tutorial will more than make up for it in the long run since you will spend less time waiting for answers to beginner questions/mistakes.


On another note, lines 131-154 of your follow-up post to mine need to be at the beginning of the file (not at the end, and they need to be within and if clause:

<?php
if( isset($_POST['Submit']) && $_POST['Submit']=='Submit' )
{
  //code to update your table goes here
  ...
}

//rest of the code to generate your form fields goes here.
...
?>

Lastly, there is no need to execute a mysql_connect() for SELECT and one for UPDATE.
You just need to connect to the db once (at the beginning of the file) and do not close the connection until the very end of the file. In between you can execute any sql statements you want/need

hielo 65 Veteran Poster
<?php
mysql_connect("locahost","username","password") or die(mysql_error());

//change "dbname" to the name of your actual database
mysql_select_db("dbname") or die(mysql_error());

//change "TABLENAME" to the name of the actual table you have
$result=mysql_query("SELECT `names` FROM TABLENAME`") or die( mysql_error() );
while( $row=mysql_fetch_assoc($result) )
{
  echo '<div>' . $row['names'] . '</div>';
}
mysql_close();
?>
hielo 65 Veteran Poster

$result = mysql_query("SELECT `Pass` FROM `wiki` WHERE `User` ='" . $user ."'");
if (!$result) {
die( mysql_error() );
}
elseif( !mysql_num_rows($result) ){
echo "No records matched your search criteria";
}
else{
$row = mysql_fetch_assoc($result);
$pass = $row;
echo "found: " . $row;
}
mysql_free_result($result);
mysql_close($con);

hielo 65 Veteran Poster

At the time of opening the account the balance and interest are set to be zero.

Ok, then there you have it. If BEFORE the UPDATE statement your balance=0 OR interest=0, then that row will be updated but the result will be zero again. This is not a php bug. This is just the result of your formula.

I don't know what you are working on, but to put things into perspective, when you open a bank account, you must have a minimum amount to open that account.

If you are telling me that according to the DEFINITION of your DB Table balance and interest are set to zero, then I can understand that. But if you are telling me that after someone opens an account they are allowed a zero balance, then that is the root of your problem. Your formula will never update to anything beyond zero. You must enter a number greater than zero.

hielo 65 Veteran Poster

are you sure balance and interest are not zero? 0*anything=0

hielo 65 Veteran Poster

You currently have: UPDATE savings_investment SET `balance`= (`balance`+`balance`*`interest`NUMERATOR/DENOMINATOR) enclose the fractional portion in parentheses and include the "*" operator to the left of the open parenthesis: UPDATE savings_investment SET `balance`= (`balance`+`balance`*`interest` * (NUMERATOR/DENOMINATOR) ) You have this problem on all your update statements.

hielo 65 Veteran Poster

Is it possible for the second page to submit its form along with the $_post which contains the information from the first page?

No. as soon as page2 completes execution (basically once it loads in your browser) the current page variables cease to exist. The only reason why the data is maintained across visits is because the browser and the server send a cookie back and forth that identifies a unique file on the server where the $_SESSION info for that particular user is stored.

The other ways to get this working are the hidden fields, sessions, cookies. Can i do without these?

No.

But the approach you described above is server-side. What you can do is to show one form at a time on the browser but do not submit the form right away. Instead, you show form 1 then go "Next" and the current form will hide and the other set of fields will appear. Then "Next", etc. Finally, when the user clicks finish, THEN you actually submit to the server. Ultimately (if you do things right) you will do ONE submission to the server.

http://www.jankoatwarpspeed.com/post/2009/09/28/webform-wizard-jquery.aspx
http://thecodemine.org/

hielo 65 Veteran Poster

i get a pass error

Is this error reported by your server or is it some editor that you are using?

On another note, I missed closing parenthesis at the end of that line:

$q = sprintf("SELECT * FROM users where id='%s' LIMIT 1", mysql_real_escape_string($_GET['id']) ) ;
hielo 65 Veteran Poster

. The function update_interest() did not call in the program. can anyone show how to call that function?

try:

<?php

$connect=mysql_connect("localhost","root","");
mysql_select_db("bank",$connect) or die ("could not select database");

function update_interest($conn){
       

$query="UPDATE savings_investment SET `balance`= (`balance`+`balance`*`interest`12/3000)";
 mysql_query($query) or die(mysql_error());
 
$query="UPDATE shakthi SET `balance`= (`balance`+`balance`*`interest`7/3000)";
 mysql_query($query) or die(mysql_error());
 
$query="UPDATE surathal SET `balance`= (`balance`+`balance`*`interest`14/3000)";
 mysql_query($query) or die(mysql_error());
 
$query="UPDATE abhimani_plus SET `balance`= (`balance`+`balance`*`interest`1/300)";
 mysql_query($query) or die(mysql_error());
}
update_interest($connect);
?>
hielo 65 Veteran Poster

strange - it did not work in this way...

It's not clear what you mean by that, BUT if you were previously extracting the values using something like echo $result['OldValidFrom']; , now you will need to specify the index of the data that interests you- echo $result['OldValidFrom'][0]; .

You can even do a foreach($result['OldValidFrom'] as $index=>$data){ echo $data; }

hielo 65 Veteran Poster

instead of: $q = "SELECT * FROM users where id='$_SESSION[user_id]'" ; try: $q = sprintf("SELECT * FROM users where id='%s' LIMIT 1", mysql_real_escape_string($_GET['id']) ;

hielo 65 Veteran Poster

can you post your code to profile.php?