GregL83
-
Posts
119 -
Joined
-
Last visited
Never
Posts posted by GregL83
-
-
Hello,
I am having a weird problem with my webhost. Originally I was running PHP 4.4.7 and MySQL. I had my application actively running. I then made the move to switch to OOP and needed to upgrade to PHP 5. I called my webhost and told them that I need PHP 5. They went ahead and enabled it. They then informed me that I was recieving an error in my ctg-error log. I can't fully remember the error but its was involving session_path line 0 and some othe warnings that didn't seem to affect my application. They told me they would update a path in a system setting to fix the error. After these two changes where made I went back to a previously functional application page and recieved a new error.
"Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in webpath/htdocs/locater.php on line 95"
I have simplified the code that recieves this error. It is as follows:
<?php ... query = "SELECT col3, col4 FROM samp WHERE col1 = 'test1' ORDER BY col3"; $result = mysql_query($query); while(list($col3, $col4) = mysql_fetch_row($result)){ echo $col3; echo $col4; } ... ?>
I can't figure out why this does not work..... Please help!
-
you could echo javascript....
also I use <?php echo $_SERVER['PHP_SELF']; ?>, don't know if that matters
echo the javascript widow.location = "index.html" or your location requested....
-
thats seems confusing...here is a sample that DOESNT work...
file: set.php
<script type="text/javascript">
var ajaxRequest; // AJAX main variable
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create Function To Receive Data Sent From Server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var result = ajaxRequest.responseText;
alert(result);
}
}
var params = "ajax=greg";
var url = "ajax.php";
ajaxRequest.open("POST", url, true);
ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajaxRequest.setRequestHeader("Content-length", params.length);
ajaxRequest.setRequestHeader("Connection", "close");
ajaxRequest.send(params);
}
</script>
<?php
# display cookie
if(isset($_COOKIE["name"])){
echo "Cookie set to \"".$_COOKIE["name"]."\"";
}
else{
echo "Cookie not set";
}
?>
file: ajax.php
<?php
if(isset($_POST['ajax'])){
$variable = $_POST['ajax'];
setcookie("name",$variable, time() + 3600, "/");
}
?>
file: home.php
<?php
# home
if(isset($_COOKIE["name"])){
echo "Cookie is set to \"".$_COOKIE["name"]."\".";
}
else{
echo "Cookie not set";
}
?>
I used this code to try and test the ajax setcookie example with no success....
-
Weird I will go into more detail.
I have refreshed the page many times with no result.
I am using the correct code to set a cookie as I have tested it without AJAX on the same vserver.
Basically, I have a login script that uses AJAX to run PHP code and validate the username and password entered in form fields. If valid, php sets session variables and returns result code back to the calling page. At this point the page is redirected.
I am trying to have the ajax page also set cookies if user selects remember me checkbox. I simply passed the checkbox value, along with username and password, of true|false to the ajax page. The PHP adds the cookie depending on the value of the checkbox.
My browser never recognizes the cookie that was set from the ajax page. I have tried testing basic ajax request setting cookie and got no results as well.
-
so any ideas????
How can I set cookies from an ajax page???
-
the issue is accessing the cookie. I believe it is never set because it is trying to be set through an ajax page. It seems I cannot set a cookie on an ajax page with php....I cannot figure a away around this
-
Hello,
I need help setting a cookie from an ajax page. Basically
page.php (javascript uses ajax to POST data to ajax page -> ajax_page.php (recieves posted data and sets cookie)
Cookie never gets set. I cannot access the cookie with any pages. I have tested setting cookies without ajax and it works.
I use: setcookie("number","one",time() + 3600, "/");
Please help...
-
Clown, thanks for the reply... I have now learned more about the isset function. My PHP teacher sucks!
anyhow, what worked for me, was if(isset($_FILES["file"])){}
-
Do you have a database?
Are you using XML?
I am a noob, but I am pretty sure you need to have and index to search. I would have a database with the pictures linked to the product information page. You then could do a search of the database index of your choice and then return all the results. I haven't yet built a php search like this but I believe that this is where you need to go. Good luck. Hope my little input could help you get started or spark conversation...
-
Something else I tried is:
if($_POST['file']) {}
Problem with this is I get a undefined index at the line because the variable $_POST['file'] doesn't exist if no file is uploaded... How do i get php to run a bit of code only if the the variable exists?
-
So another noob question from GregL83 .
I want to run some code only if a file is selected to be uploaded.
if(is_uploaded_file($_FILES["file"])) { if(($_FILES["file"]["size"] < 250000)) { if($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"]."<br/>"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; $ftype = substr($_FILES["file"]["type"],(strlen($_FILES["file"]["type"]))-3); echo $ftype."<br/>"; move_uploaded_file($_FILES["file"]["tmp_name"], "images/main_image.".$ftype); echo "Stored in: "."images/".$_FILES["file"]["name"]; } } }
The line of importance is at the top! I want the functions to run if a file is uploaded. Let me know if you need the form, but i dont think it is nessecary to identify the proper method. Thanks once again. You guys are great!
-
Thanks for the help.
-
Simple questions for the noob...I have an if statement where I want true to be returned dependent on three things. The first must always be true and the second and third must have one of the two true...I am not sure how the operation is conducted...
if(isset($_POST['submit']) && $item = "width" or $item = "height") { $update["$item"] = $_POST[$item]."px"; }
Thanks for the help..
-
Yes! After you first response i went back and changed the loop. Thats when I noticed that the WHERE statemnet needed to be further delcared as you stated in your second response. So now the new forech loop works and well...looks far more efficient than my original. Thanks for the help! Here is what I changed it to
$id = "01"; $update = array("1" => "Z", "2" => "X", "3" => "Y"); foreach($update as $number => $letter) { $query = "UPDATE test SET letter = '".$letter."' WHERE id = '".$id."' AND number = '".$number."'"; $result = mysql_query($query) or die(mysql_error()); }
No echo statements = working code!!! Thanks again!
-
k, thanks for the response... I'll see if the foreach loop will work...I didn't submit the whole peice of code, just the section that is having trouble so the id is declared earlier...thanks for the help, I'll see if the foreach works.but I still don't understand why logically the first way wouldn't....??? I'll make the coded as easy as possible to debug
-
Hello, I am new at PHP and I have a project due tonight. There is probably a really simple answer to my question but I can't figure it out... please help
I have an array that stores pieces of information that I want to update to a database. I decided to use the for loop to retrieve the peices of information and one by one store them into the database. The last peice of the array is stored repeatedly for the other values....I have echoed the process the loop takes and i cannot figure out the problem...Here is a simplified version of my code:
$update = array(array("2" => "A"),array("3" => "B"),array("4" => "C")); print_r($update); $t = count($update); echo "<br />"."Number in Array : ".$t."<br />"; for ($c = "0"; $c < $t; $c++) { echo "Count equals: ".$c."<br />"; $number = key($update[$c]); echo "Number equals: ".$number."<br />"; $letter = current($update[$c]); echo "Letter equals: ".$letter."<br />"; $query = "UPDATE test SET number = '".$number."', letter = '".$letter."' WHERE id = '".$id."'"; $result = mysql_query($query); if($result){ echo "Database has been updated!"."<br/>"; } }
The result is that I have the number 4 and letter c stored three times...but my echoes show each alue correctly...why doesnt the update work like the echoed values in the loop?????? PLEASE HELP!!
-
I came up with the same error....thanks for the attempt
-
Hello, I am adding a PHP form to mail script to my contacts page of my website. I used a script generator from thesitewizard.com; however, I am getting an error message when I try and test it out. The message is as follows:
"The server encountered an unexpected condition which prevented it from fulfilling the request.
The script had an error or it did not produce any output. If there was an error, you should be able to see it in the error log."
I can't find the error log or seem to be able to fix the problem. My web host is powweb and they have: PHP4 & PHP5 w/Zend Optimizer, Perl5, Sendmail listed as supported software.
here is my .php file's code:
<?
$mailto = 'Langla79@erau.edu' ;
$subject = "YourScene Message" ;
$formurl = "http://www.***.us/contact.html" ; //note I blanked out website for privacy, thanks
$errorurl = "http://www.***.us/contact_error.html" ;
$thankyouurl = "http://www.***.us/contact_thanks.html" ;
$uself = 0;
$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$name = $_POST['name'] ;
$email = $_POST['email'] ;
$comments = $_POST['comments'] ;
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg( "[\r\n]", $name ) || ereg( "[\r\n]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}
if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}
$messageproper =
"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $name\n" .
"Email of sender: $email\n" .
"------------------------- COMMENTS -------------------------\n\n" .
$comments .
"\n\n------------------------------------------------------------\n" ;
mail($mailto, $subject, $messageproper,
"From: \"$name\" <$email>" . $headersep . "Reply-To: \"$name\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" );
header( "Location: $thankyouurl" );
exit ;
?>
Here is my code from the form:
<form action="data/contact.php" method="post" name="Comments" id="Comments"><div align="center">
<p><span class="style3">Full Name:</span>
<input name="name" type="text" id="full_name" maxlength="25">
<span class="style3">Email:</span>
<input name="email" type="text" maxlength="25">
</p>
<p><span class="style3">Message</span><br>
<textarea name="comments" cols="50" rows="7"></textarea>
</p>
</div>
</label>
<label> </label>
<div align="center">
<input name="Submit" type="submit" value="Send">
<input type="reset" name="Submit2" value="Reset">
</label>
</div>
<label></label>
</form></td>
PLEASE HELP!!!! Thank you for your time!
PHP 5.0 MySQL Error
in PHP Coding Help
Posted
I added that line to my query and nothing changed...still the same errors.
I don't think this is a coding error. The problem began after my webhost messed around with server settings.
Does anybody have any clue how to find the problem and solve it?? I have tested this method of getting variables from my MySQL database and get this error evertime. It is very frustrating because it is only a few lines of code and I have two books and many tutorials saying the code is fine...
Please Help!!!