hielo 65 Veteran Poster

Glad to help!

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

hielo 65 Veteran Poster

that typically happens when you are trying to do CROSS domain request or CROSS protocol requests.

hielo 65 Veteran Poster

Refer to the manual:
http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

Specifically, in the user comments at the bottom of the page, look for the comment
"Posted by Duane Hitz on March 31 2006 8:19am"

hielo 65 Veteran Poster

It sounds like you are executing:

$res = mysql_query("some query here");
while($row = mysql_fetch_assoc($res) )
{
 //...code here
}

what you need to do is add " or die( mysql_error() );" so that you get details about the error.

$res = mysql_query("some query here") or die( mysql_error() );
while($row = mysql_fetch_assoc($res) )
{
 //...code here
}
hielo 65 Veteran Poster

You must be doing something wrong. I tried using the ajax approach and it works fine.
You are probably trying to get the responseXML from your ajax object, but there is no SERVER involved that "tells" the browser that the content IS xml. This is a well known issue in IE. Instead, you need to get the responseText from it, which should give you the xml as a string. Then use that string with the code you posted above(http://www.daniweb.com/forums/post1327817.html#post1327817), but instead of xmlDoc.loadXML("filters.xml") , you will need xmlDoc.loadXML(http.responseText) NOTE: http a reference to the ajax object you will be creating.

hielo 65 Veteran Poster

CREATE TABLE student(
name CHAR(100),
father CHAR(100),
mother CHAR(100),
address VARCHAR(255),
PRIMARY KEY (name,father,mother)
)

hielo 65 Veteran Poster

Do you know for a fact that your server is returning a VALID xml document?

hielo 65 Veteran Poster

Fix line 5. The name of your select is "additions" NOT "extrastuff". Also, on line 14, the third parameter to mysql_connect() should be $pass.

Lastly, the syntax for INSERT is:

INSERT INTO TableName(FieldName1, FieldName2) VALUES('valueForField1','valueForField2')
hielo 65 Veteran Poster

what is init.php? How and where are you connecting to the db server?

hielo 65 Veteran Poster

It sounds like you are INITIALLY arriving at the page via editsites.php?siteid=95 , in which case line 11 works as expected. BUT your FORM does not "save" that siteid, so when you submit/POST the form, it is going to editsites.php, NOT to editsites.php?siteid=95.

So add the site id to your FORM's action:

<form action="editsites.php?siteid=<?php echo intval($_GET['siteid']);?>" method="post"...>
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

try:

function toArray($str, $delimiter=',', $assoc=false)
{
	$data=explode($delimiter,$str);
	if(TRUE===$assoc)
	{
		$temp=array();
		$i=-1;
		$limit=count($data);
		while(++$i < $limit)
		{
			$key=$data[$i];
			$val=$data[++$i];
			$temp[ $key ]=$val;
		}
		unset($data);
		$data=$temp;
	}
return $data;
}

$str="category_name:-abs43;c1-abs43;types:-abs43;t1";
$result=toArray($str,'-abs43;',TRUE);
print_r($result);
hielo 65 Veteran Poster

The security settings on your IE might be preventing your script from working. Go to IE and click on:

Tools > Internet Options > Security > Local Intranet > Custom Level > Settings
> ActiveX Controls and plugins > Initialize and script ActiveX controls not marked as safe for scripting =>Enable

On the script you posted above, change loadXML() to load().

Then try it again.

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

loadXML() is for inline xml, not for a file. To load a file you need the load() method. Also, make sure the xml file is in the same folder as the page where you have the test page OR provide a full path to your xml file.

Don't forget to escape backslashes:
WRONG: var file="C:\somefolder\file.xml"; CORRECT: var file="C:\\somefolder\\file.xml";

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

I see this multiple times:

echo "<option value=$row[id]>$row[contam]</option>";

However, NONE of your SELECT statements are "asking" for the column `id`, so $row[id] is empty and you would NOT see a value for your elements when the form is posted.

If your table does have an `id` column, be sure to SELECT it as well: SELECT id, contam, gac_value ...

hielo 65 Veteran Poster

a. Post the code you have thus far (the file doing the "importing")
b.specify how you are accessing/loading your test page from the browser (ex: using http://localhost, file:///path/to/file, http://yoursite.com)
c. post a sample of the xml file you are trying to load.

hielo 65 Veteran Poster

On the SECOND link you provided, look for the post by andy (August 11, 2009 at 3:52 am ). It has the code you need AND a full downloadable demo. If you do NOT want the numbers, then simply OMIT $pages->paginate();

hielo 65 Veteran Poster

First make a DELETE query. It it succeeds, then make an UPDATE query - ex:

$id=3;
mysql_connect("localhost","username","password") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error());
mysql_query("DELETE FROM tableName WHERE `id`=$id") or die(mysql_error());
mysql_query("UPDATE tableName SET `userno`=`userno`-1 WHERE `id` > $id") or die(mysql_error());
hielo 65 Veteran Poster
list($rooms) = mysql_num_rows(mysql_query("SELECT * FROM choose_rooms",$db));

Your connection variable is $con, NOT $db! So change $db to $con.

hielo 65 Veteran Poster

Be sure to test it by opening it directly from the browser, not through the preview option of your editor. If it still does not work, then would expect you to be getting some error message. Are you? What browser are you using?

hielo 65 Veteran Poster

Did you copy and paste the above code onto a BLANK document and saved it as test.html?
It worked for me in Chrome and FF. Hence my comment, "This is a far as I go"

hielo 65 Veteran Poster

syd919, on your follow-up post (Sep 7th, 2010, 07:07 ) you have: <?php echo $_SERVER['PHP_SELF']> That is NOT what I posted. It should end with semi-colon followed ? and >:

<?php echo $_SERVER['PHP_SELF'];?>

As for Nyight's comment, about the if clause, he is right. I missed the leading ! symbol. It should be: if( !file_put_contents( $file, $data, FILE_APPEND) )

hielo 65 Veteran Poster

change:
Resource id #2

to:
$con

hielo 65 Veteran Poster

Glad to help.

Regards,
Hielo

hielo 65 Veteran Poster

Glad to help.

PS: Be sure to mark the thread as solved.

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

Did you remember to initialize n to zero somewhere? Did you remember to use dataType: "xml" in your jQuery ajax options?

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

When using ajax, from your local machine, you need a local web server installed. You cannot open your test file via "file://...". You must open your file using "http://..." since ajax makes http requests. If you are using the "file" protocol instead of the "http" protocol, it will not work.

Also, your ajax request can only be made to files that exist on YOUR own server, not to external/remote servers.

If you do not have a local web server installed, you can try installing WAMP:
http://www.wampserver.com/en/

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

try:

<?php
if( isset($_POST['submit']) && $_POST['submit']=='OK' )
{
	$data=$_POST['anything'].PHP_EOL;
	$file=dirname(__FILE__) ."/form_output.txt";
	if( file_put_contents( $file, $data, FILE_APPEND) )
	{
		echo "unable to write to file. Verify path and permissions";
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"/>
    <title>Test</title>
  </head>

  <body>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" name="TestForm"/>

      <p />
      Input anything: <input type="text" name="anything" value="Default"/> <br />
      <input type="submit" value="OK" name="submit"/>
    </form>
  </body>
</html>
hielo 65 Veteran Poster

This is a far as I go:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html> 
<head> 
<base href="http://arshaw.com/js/fullcalendar/examples/" />
<link rel='stylesheet' type='text/css' href='../fullcalendar.css' /> 
<script type='text/javascript' src='../jquery/jquery.js'></script> 
<script type='text/javascript' src='../jquery/jquery-ui-custom.js'></script> 
<script type='text/javascript' src='../fullcalendar.min.js'></script> 
<script type='text/javascript'> 
var data=null;
var newwindow2=null;
var calendar=null;
	$(document).ready(function() {
	
		var date = new Date();
		var d = date.getDate();
		var m = date.getMonth();
		var y = date.getFullYear();
		
		calendar = $('#calendar').fullCalendar({
			header: {
				left: 'prev,next today',
				center: 'title',
				right: 'month,agendaWeek,agendaDay'
			},
			selectable: true,
			selectHelper: true,
			select:pop,
			/*
			select: function(start, end, allDay) {
				var title = prompt('Event Title:');
				if (title) {
					calendar.fullCalendar('renderEvent',
						{
							title: title,
							start: start,
							end: end,
							allDay: allDay
						},
						true // make the event "stick"
					);
				}
				calendar.fullCalendar('unselect');
			},
			*/
			editable: true,
			events: [
				{
					title: 'All Day Event',
					start: new Date(y, m, 1)
				},
				{
					title: 'Long Event',
					start: new Date(y, m, d-5),
					end: new Date(y, m, d-2)
				},
				{
					id: 999,
					title: 'Repeating Event',
					start: new Date(y, m, d-3, 16, 0),
					allDay: false
				},
				{
					id: 999,
					title: 'Repeating Event',
					start: new Date(y, m, d+4, 16, 0),
					allDay: false
				},
				{
					title: 'Meeting',
					start: new Date(y, m, d, 10, 30),
					allDay: false
				},
				{
					title: 'Lunch',
					start: new Date(y, m, d, 12, 0),
					end: new Date(y, m, d, 14, 0),
					allDay: false
				},
				{
					title: 'Birthday Party',
					start: new Date(y, m, d+1, 19, 0),
					end: new Date(y, m, d+1, 22, 30),
					allDay: false
				},
				{
					title: 'Click for Google',
					start: new Date(y, m, 28),
					end: new Date(y, m, 29), …
hielo 65 Veteran Poster

and On line 14 you are using $cid for $_POST;
and again on 29 same variable is used (isset($_POST))
$cid = $_POST;
is it working correctly???

What's your point? He is consistently setting the value of $cid to $_POST. If anything, it is redundant. Hence my suggestion to put $cid = isset($_POST['catId']) ? $_POST['catId'] : 0; on line 10. That way he can get rid of lines 14 and 29.

From what I can see, the problem is not $catId, but not using the right variable in the UPDATE statement.

hielo 65 Veteran Poster

on lines 44 and 49 you have: UPDATE tbl_category SET cat_name ='$name2' WHERE cat_id = '$name' If I am not mistaken it should be ... WHERE cat_id=$cid Also, on line 10 put the following: $cid = isset($_POST['catId']) ? $_POST['catId'] : 0;

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

assuming you had:

<input type="text" name="person" value="John"/>
<input name="sport[]" type="checkbox" value="baseball">
<input name="sport[]" type="checkbox" value="basquetball">
<input name="sport[]" type="checkbox" value="football">
<input name="sport[]" type="checkbox" value="hocket">

then:

foreach($_POST['sport'] as $value)
{
  $sql = sprintf("INSERT INTO `Atletes`(`personId`,`sportName`) VALUES('%s','%s')"
                ,mysql_real_escape_string($_POST['person'])
                ,mysql_real_escape_string($value)
                );
}
hielo 65 Veteran Poster

Hielo you have the Javascript embedded into the HTML...I'm calling an external JS file

It shouldn't make a difference, but just to humor you I tried the html code you posted and the exact js (except I added the two closing braces at the end of your onload function and it works fine. Here's my complete Objects.js file:

function car(seats,engine,theradio) {
this.seats=seats;
this.engine=engine;
this.theradio=theradio;
}

var work_car=new car ("cloth","V8","Tape Deck");
var b1=null;

window.onload=function(){
	b1 = document.getElementById("work_car");
	b1.onclick=function(){
		alert("I want a car with " + work_car.seats + " yeah");
	};
};
hielo 65 Veteran Poster

Based on your follow-up question, it sounds like you are asking how to accomplish what you are already doing here:
http://mweisfeld.1upware.com/joke.html

Isn't it?

hielo 65 Veteran Poster

Glad to help.

PS: Be sure to mark the thread as solved.

hielo 65 Veteran Poster

Is there any way to make javascript interpreter to wait for ajax call

Yes, just provide the async:false option to the ajax call:

hielo 65 Veteran Poster

try adding the apostrophes to the list of chars in $valid_chars_regex

OR simply use str_replace() after your preg_replace() on the code you posted:

$file_name = preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));

$file_name=str_replace("'","",$file_name);

	if (strlen($file_name) == 0 || strlen($file_name) > $MAX_FILENAME_LENGTH) {
		HandleError("Invalid file name");
		exit(0);
	}
hielo 65 Veteran Poster

if you want the browser to actually navigate to joke.text then change your form to:

<form method="post" action="joke.txt">
      <input type = "submit" value = "Fetch Answer">
    </form>