Philip
Staff Alumni-
Posts
4,665 -
Joined
-
Last visited
-
Days Won
20
Everything posted by Philip
-
Okay, if you take out that loop - does it do anything odd? Like this: <?php $body = "We have received the following information:\n\n"; /*foreach($fields as $a => $b) { $body .= sprintf("%20s: %s\n",$b,$_REQUEST['$a']); }*/ ?> And that works okay? if so, can you print_f($fields)?
-
In POST, you need to send the data, not attach it to the url: xmlHttp.open("POST",edit_company_ajax.php+"?flag="+flag+"&user="+user_id,true); xmlHttp.send(null); To this: xmlHttp.open("POST","edit_company_ajax.php",true); xmlHttp.send("flag="+flag+"&user="+user_id);
-
point to a particulatr record in a recordset..
Philip replied to chelnov63's topic in PHP Coding Help
OR, if you want to keep all of the data, <?php $rs_brass = mysql_query("SELECT * FROM the_brass"); // do a loop to gather all results for($i=0;$row_brass = mysql_fetch_array($rs_brass);$i++) { // save data into large array $array[$i] = $row_brass["image"]; // If it is row 3 (item #4, remember it starts with 0) if($i == 3) echo $row_brass['image']; } print_r($array); // show full array ?> -
That is the correct syntax... $body = "We have received the following information:\n\n"; foreach($fields as $a => $b) { $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } The only thing I can think of, would be to put single quotes around $a in the $_REQUEST... but the script shouldnt print itself (you are saying it's printing the code, correct?)
-
[SOLVED] Simple question with listbox default value
Philip replied to patheticsam's topic in PHP Coding Help
You need to put SELECTED in the options tag, not the select tag. <?php echo " <select name=select> <option value=option1 SELECTED>Option 1</option> <option value=option2>Option 2</option> <option value=option3>Option 3</option> <option value=option4>Option 4</option> <option value=option5>Option 5</option> </select> "; } ?> I would do this: <?php // Create an array of all of the possible values $selectArray = array( 'option1' => 'Option 1', 'option2' => 'Option 2', 'option3' => 'Option 3', 'option4' => 'Option 4', 'option5' => 'Option 5', ) // Start the option list. echo '<select name="select">'; // loop through the array foreach($selectArray as $value => $title) { // Create an option echo '<option value="',$value,'"'; // Check to see if the value is the one that was found in tthe database if($value==$data['field1']) echo ' SELECTED'; // Finish creating the option echo '>',$title,'</option>'; } // Close out the option list echo '</select>'; ?> -
Always put single quotes around values: mysql_query("INSERT INTO `foodsys`.`foods` (`food_id`, `name`, `type`, `price_reg`, `price_large`, `image`, `description`) VALUES('', $name , $type, $price_reg, $price_large, $newname, $description)")or die(mysql_error()); To: mysql_query("INSERT INTO `foodsys`.`foods` (`food_id`, `name`, `type`, `price_reg`, `price_large`, `image`, `description`) VALUES ('', '$name' , '$type', '$price_reg', '$price_large', '$newname', '$description')")or die(mysql_error());
-
Umm, why would you want to automatically submit nothing? If you're wanting to submit something with POST via PHP - look into curl.
-
Displaying only so many items in a row of a table
Philip replied to PHPTOM's topic in PHP Coding Help
<?php // settings: $number_of_rows = 6; $number_of_columns = 4; // start table echo '<table><tr>'; // count number of elements, and divide by columns to get row count for($i=0; $i/$number_of_columns<$number_of_rows; $i++) { // if new row if($i%$number_of_columns==0) echo '</tr><tr>'; // show box. echo '<td>',$i,'</td>'; } echo '</tr></table>'; ?> That'll make: 0123 4567 ... -
No, it's not. The mysql_fetch_assoc($query); needs to be in a loop - every time you call that, it pulls the current row from the database as an array. Right now, it's pulling the first row, and you're trying to do a loop on an array with one item in it. Try on: <?php while($row = mysql_fetch_assoc($query)) { $myComment = new CommentOb($row['id']); array_push($commentArray, $myComment); } ?>
-
This needs to be in a loop for it to pull more than the first row: $row = mysql_fetch_assoc($query);
-
Add a while statement: <?php $query = mysql_query("SELECT id FROM comment WHERE pollId = '$inPollId' ORDER BY id DESC ") or die("Could not get comments"); while($row = mysql_fetch_assoc($query)) echo $row['id']; ?> BTW, you don't need to do "echo print_r" - select one or the other. Echo will print "Array", and print_r will show the structure of the array.
-
It really depends on what cms you're using. Typically, you can visit their forums, and they have a bunch of help over there specific to the cms you're using.
-
[SOLVED] Textarea info put into separate rows
Philip replied to shakingspear's topic in PHP Coding Help
What happens when you echo $_POST['textarea']; -
[SOLVED] Using PHP to highlight the current page in a list
Philip replied to biwerw's topic in PHP Coding Help
If I understand the question correctly, this would be one approach, I have simplified the navigation part. <?php // Get our GET $pageID = $_GET['id']; // Define our array of allowed $_GET values, and their page titles $pass = array( 'page1' => 'Page 1', 'page2' => 'Page 2', 'page3' => 'Page 3', 'page4' => 'Page 4', ); // If the page is allowed, include it: if(array_key_exists($_GET['id'], $pass)) { include_once('work/' . $pageID . '.php'); } // If there is no $_GET['id'] defined, then serve the homepage: elseif (!isset($_GET['id'])) { include('home.php'); } // If the page is not allowed, send them to an error page: else { // This send the 404 header header("HTTP/1.0 404 Not Found"); // This includes the error page include ('error.php'); } ?> <ul class="nav"> <?php // For all of the array items, foreach($pass as $key => $value) { // Show the basic structure echo '<li><a href="index.php?id=',$key,'" title="',$value,'"'; // And if it is the current page (if the GET var is the same as the one in the loop) // We should show id=current. if($pageID == $key) echo ' id="current"'; // Finish showing basic structure echo '>',$value,'</a></li>'; } ?> </ul> If you're including the page that they are trying to load, (i.e. page1, page2, etc), you can call $pageID. -
MySQL doesn't have a built in class. MySQLi does, as it was aimed at improving MySQL & making it more OOP style
-
[SOLVED] PHP Command Problem / MySQL Tabels Not Updating
Philip replied to kneifelspy's topic in PHP Coding Help
relase is a reserved word in mysql. Use backticks (`) to escape your column/table names. http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html -
[SOLVED] Simple question with SELECT query!
Philip replied to patheticsam's topic in PHP Coding Help
Don't use AND in the order by, simply use a comma SELECT `date`,` start_time` FROM `table1` WHERE `id`='$id' ORDER BY `date`, `start_time` -
print '<td width=120 class=rowheading>Username:</td><td class=row3><input type=text name=login class=fieldtext490 value=\"".$row['username']."\"></td>'; Should be print '<td width=120 class=rowheading>Username:</td><td class=row3><input type=text name=login class=fieldtext490 value="'.$row['username'].'"></td>'; You have multiple rows that are like that, so take a look at them again.
-
input_text($element_name, $values, $size) to input_text($element_name, $values, $size=''){
-
<html> <body> <?php include('conn.php'); if(isset($_POST['Submitted'])) { session_start(); change to <?php session_start(); ?> <html> <body> <?php include('conn.php'); if(isset($_POST['Submitted'])) { I dunno how I missed that
-
Can you echo out $_SESSION['cart'][$food_id]['quantity'] for me? I'm thinking you're trying to increment nothing. $_SESSION['cart'][$food_id] might exist, but whats the value for ['quantity']
-
Are you setting these ($_SESSION['cart'][$food_id]['quantity']) to 0 when initializing them?
-
[SOLVED] Keeping a cookie refreshed and/or active for substantial time?
Philip replied to chadrt's topic in PHP Coding Help
I saw an article on it recently, I'll have to see if I can pull it up. It might just be a myth - but it makes sense that it would be a bit of a boost, especially for heavy traffic servers. -
[SOLVED] PHP FORM | w/immediate field validation | need help!
Philip replied to passam's topic in PHP Coding Help
If you're wanting something instant, than use javascript. Otherwise, you can do it with PHP, with something like: <?php if(isset($_POST)) { // form validation // set any errors here. if(!isset($error)) { // submit form (or email it) } } if(!isset($_POST) || isset($error)) { // if form hasn't been submitted, or there was an error if(isset($error)) echo $error.'<br />'; ?> FORM HERE <?php } ?> Like haku said, if you did the javascript approach, make sure to do server side validation. Client side may be convenient, but not secure. -
[SOLVED] Keeping a cookie refreshed and/or active for substantial time?
Philip replied to chadrt's topic in PHP Coding Help
The cookies normally aren't destroyed as soon as the browser is closed. However, if the browser settings are set to do so, they will be destroyed (example: Google's Chrome - Incognito mode). I'm going to guess in your case, that the time (6min) is too short. It is actually faster to close php and do straight html, than to echo html inside of php. (less to parse)