jeff5656
Members-
Posts
744 -
Joined
-
Last visited
Everything posted by jeff5656
-
Actually that doesn't work. The $_SERVER['DOCUMENT_ROOT'] that I get back is not the actual location where my index file is. I think this link explains why: http://www.helicron.net/php/ Perhaps my host is not using apache (since above only works in apache). In any case, is there a way to solve this with relative paths? I thought that if I was in a subdirectory and I want to point to another subdirectory I would point to include "../anotherdirectory/filename.php"; but that doesn't work. Obviously the best solutions would be some way to automatically determine the root directory (regardless of whether the host has apache). Any ideas?
-
Having problems pointing to where files are. Is this the root?: include "../connectdb.php"; That file is locate din the root. If I am already in the root when I include that statment, the file isn't found. If I use the above code while I am in the subdirectory hello, (root/hello), it works. I use this in every page, so I think I need a way to point to the absolute root, not relative.
-
Oh I wasn't familiar with mysql SUM(). I looked it up and the following code works perfectly thanks! $query = "SELECT user_id, SUM(num_hours) FROM timesheet GROUP BY user_id"; while($row = mysql_fetch_array($result)){ echo "Total ". $row['user_id']. " = ". $row['SUM(num_hours)']; echo "<br />"; }
-
I want to add up all the hours in a field called "num_hours" When I run this code I get a result of 8, even though if you add up the hours it comes to about 20. Interestingly, there are 9 records - so it seems like my code is acting like mysql_num_rows()! $q = "select num_hours from timesheet "; $results = mysql_query ($q) or die (mysql_error()); $invarray = mysql_fetch_array ($results); echo "tot hours =".array_sum($invarray);
-
Wow you are smart. The error was stuck inside the dropdown in HTML so I never saw it untik I viewed the source. Very clever of you :-) <select name="state">Unknown column 'states' in 'order clause' I turns out the fieldname was "name" not state. Thanks!!
-
I have a table called states, but when I do a while loop to populated a dropdown, the dropdown has no content. I use this code for other dropdowns with no problems. Any ideas? <select name="state"><?php $q = "SELECT * FROM states ORDER BY states"; $result=mysql_query($q) or die (mysql_error()); $num_svcs=mysql_num_rows($result); while ($row = mysql_fetch_assoc ($result)) { ?><option value="<?php echo $row['abbrev'];?>"><?php echo $row['name'];?></option> <?php }?> </select>
-
Aha...I see thank you!
-
I get Parse error: syntax error, unexpected T_STRING in with this code. (Line 20 refers to the create table line) I copied this right from http://snipplr.com/view.php?codeview&id=6637 and there are no comments pointing out any errors, so I am at a loss. here is the code (I have always created tables right in phpmyadmin, so it would be great if I could do it this way because then I can modify the code as I create new tables): CREATE TABLE IF NOT EXISTS states ( id INT NOT NULL auto_increment, name CHAR(40) NOT NULL, abbrev CHAR(2) NOT NULL, PRIMARY KEY (id) ); INSERT INTO states VALUES (NULL, 'Alaska', 'AK'); INSERT INTO states VALUES (NULL, 'Alabama', 'AL'); and at the end of all those states: INSERT INTO states VALUES (NULL, 'Armed Forces Middle East', 'AE'); INSERT INTO states VALUES (NULL, 'Armed Forces Pacific', 'AP'); ?>
-
I get the above error with my code. The error says line 147m which is the 1st line shown below: $qq "select service from services where id = '". $userarray['id'] ."' LIMIT 1"; $results2 = mysql_query ($qq) or die (mysql_error()); $qqr = mysql_fetch_assoc ($results2);
-
I get the above error (Column count doesn't match value count at row 1) with this code: $query = "INSERT INTO shop (id,store, item, priceunit, units, unitname, dateadded) VALUES ('','$store', '$item', '$priceunit','$units', '$unitname' '$dateadded')"; echo $query; mysql_query($query) or die("<br>error. ".mysql_error()); here's my table: CREATE TABLE `shop` ( `id` int(10) NOT NULL auto_increment, `store` varchar(40) NOT NULL default '', `item` varchar(60) NOT NULL default '', `units` varchar(20) NOT NULL default '', `priceunit` varchar(20) NOT NULL default '', `dateadded` date NOT NULL default '0000-00-00', `unitname` varchar(40) NOT NULL default '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-
Trying to learn about functions. Before I call a user-created function, I have to read that function correct? So if I have a file called "functions.php" that lists a bunch of functions, do I have to put include ../functions.php at the beginning of *every* page that I will be calling a function? Or can I include the functions.php in just the index.php page? That seems a little tedious I guess, but I want to do what the standard is for reading-in the user-created functions. Because php's built in functions are somehow read without having an include file, so is there a way to treat my created functions the same way? Thanks!
-
I am about to take the plunge and learn to write some functions to make my coding easier. However, what I can't seem to find in any of the tutorials is *where* do I store these functions and when do I run them? DO I have a file called functions.php and then put an include line in every single php page I have? I that was the case, it would kind of negate the advantgae of having a function - so I think I am not "getting" something. I figured I would just ask the experts :-)
-
ok thanks. I use the same process page for different forms (just different if statements to direct to correct section), so I may need to use sessions.
-
If I have a form, and I have aform processing page like process.php and let's say I want to redirect back to the form if there is an error (i.e. passwords don't match). How can I redirect back to the form and retain the contents of the other fields, so the user doesn't have to type it all over again? BTW I know I can do this with java on the actual form.php page, but was wondering if there was a PHP solution)
-
"SELECT table1.field as field1, table2.field as field2 FROM ........" Is there any way to do that and still use the wildcard *? I have many fieldnames to selct from both tables and don't want to have to write them all out...
-
if I join two tables and one of the fieldnames is the same in both tables, how do I echo out the correct one? as an example, $query = "SELECT * FROM food, more_food "; $results = mysql_query ($query) or die (mysql_error()); while ($row = mysql_fetch_assoc ($results)) { Now the following "made sense", but it doesn't work. How do i speciy the variable from the correct table if the ieldnames are the same in both tables? echo "the type of apple is $row['food.apple'];
-
Great, thanks guys.
-
Hey now it says equal! Thanks. But why does that work. Was there an invisible carriage return in one?
-
I want to compare something in the database with a POSTed string to see if they are equal: $query = "SELECT * FROM `testbase` WHERE `id` = '".$id."' "; $result = mysql_fetch_array(mysql_query($query)) or die(mysql_error()); echo $result['t3']; echo "<br>"; echo $_POST['t3']; When I do that I get this: WBC 7 Hg 7 INR: 1.4 Cx: WBC 7 Hg 7 INR: 1.4 Cx: They look the same right? But when I do this, if($result['t3'] == $_POST['t3']) { echo "they are equal" } else { echo "Not equal" } I get Not equal. But they sure look equal!! Any ideas??
-
My server is 3 hours behind in another time zone. Does anyone know how I can adjust this code so that $d is +3 hours ahead? $d= date("Y-m-d H:i:s"); Echo $d;
-
I apologize I could not undertand how to use the first link: for($count=0;$count<$fields;$count++) { $field = mysql_fetch_field($result,$count); echo "<p>$field->name $field->type ($field->max_length)</p>"; and apply that to my code. what is "field ->type"?? If I have $row['f13'] how do I see what data type that is? Yoir send link: mysql_field_type(data,field_offset) What is a field offset? I do not know what number to start at.
-
$query = "SELECT * FROM `people` WHERE `s_status` = 'a' order by $srt"; $results = mysql_query ($query) or die (mysql_error()); while ($row = mysql_fetch_assoc ($results)) { echo $row['f13'] . "this field type is"."?????"; Where the ???? are in the code above, what do I put there to echo the filed type (i.e. "varchar" or "Date", etc?
-
Oh is that all? That's easy. Thanks!
-
I have names called f1_name, f2_name all the way to 17 (I get these from a queried database). I want to write a for loop so I don't have to write them all out in a form. Here is my code. Look at this array: $row['f1_name'] <?php for ($f=1;$f<18;$f++){ ?> <td bgcolor="#FFFFFF">F<?php echo $f;?></td> <td > <input name="f<?php echo $f.'_name';?>" type="text" size="20" value="<?php echo $row['f1_name']; ?>" /> </td> </tr> <?php } ?> How do I fix that so that the For-loop inserts the correct number for $row['fx_name'] (where x is $ff)? Hope that's clear! :-)