kenrbnsn
Staff Alumni-
Posts
8,234 -
Joined
-
Last visited
Everything posted by kenrbnsn
-
Your best way of accomplishing this is via Javascript with AJAX. Ken
-
Did you try using sessions? Ken
-
Use sessions. At the start of your first script put <?php session_start(); ?> then right before the header() call, put <?php $_SESSION['url'] = $URL; $_SESSION['type'] = $type; ?> In the second script put <?php session_start(); $URL = $_SESSION['url']; $type = $_SESSION['type']; ?> Ken
-
You should always validate all user input. At the very least use the mysql_real_escape_string() on any user inputs that are strings and that will be used in a mysql query. Ken
-
Change <?php $run = mysql_query($constructx); ?> to <?php $run = mysql_query($constructx) or die("Problem with the query: $constructx<br>" . mysql_error()); ?> This should tell you the problem. Ken
-
How to output BLOB images through PHP to HTML ?
kenrbnsn replied to anevins's topic in PHP Coding Help
The quote symbols in this statement are wrong: <?php $query = "SELECT image FROM identification WHERE id = ‘$id’"; ?> You should be using single quotes: <?php $query = "SELECT image FROM identification WHERE id = '$id'"; ?> Ken -
What is a safer way to include an internal webpage to my site?
kenrbnsn replied to FalseProphet's topic in PHP Coding Help
Since you know the files that should be included in your script, the easiest way of doing this would be: <?php $allowed = array('list','of','permitted','files'); if (in_array($_GET['id'],$allowed) && file_exists("path/to/{$_GET['id']}") { include("path/to/{$_GET['id']}"); } else { // // abort mission... // } ?> Another way of circumventing the problem, is not to use the explicit file name in the parameter, but to use an index into an array that holds the allowed include files. Then you would have to check if the key exists in the file. Ken -
What is a safer way to include an internal webpage to my site?
kenrbnsn replied to FalseProphet's topic in PHP Coding Help
Please post the code you're using. Ken -
What do you mean?
-
The "@" suppresses error messages and shouldn't be used. Ken
-
How are you getting these strings? Please post your code. Ken
-
Nope. According to the PHP Manual entry on variables: Ken
-
Pull value from array w/ key variable function not working
kenrbnsn replied to barocky82's topic in PHP Coding Help
Change your query to <?php $query = "SELECT user_id, AVG($column_name) as my_avg FROM table GROUP BY user_id"; ?> Then in your code you can do <?php $average = $row[' my_avg']; ?> Ken -
when to use echo to display Functions or Definitions??
kenrbnsn replied to mac007's topic in PHP Coding Help
Functions should return a value to be used, they really shouldn't echo anything, try this instead: <?php function categories() { $tmp = array(); $tmp[] = '<table style="margin:20px;" width="100%">'; $tmp[] = '<tr>'; $tmp[] = '<td>'; $categories = mysql_query('select * from categories'); while ($rowCategory = mysql_fetch_array($categories)) { $tmp[] = "<a style='line-height:20px;' href='?category={$rowCategory['category_id']}'>{$rowCategory['category_name']}</a><br>"; } $tmp[] = '</td>'; $tmp[] = '</tr>'; $tmp[] = '</table>'; mysql_free_result($categories); return (implode("\n",$tmp) . "\n"); } ?> Then both echo examples should work. Ken -
when to use echo to display Functions or Definitions??
kenrbnsn replied to mac007's topic in PHP Coding Help
What does the function categories look like. Please put your code between tags. Ken -
Passing $string variable into mysql query
kenrbnsn replied to spangle1187's topic in PHP Coding Help
Oops, didn't see that. Ken -
Passing $string variable into mysql query
kenrbnsn replied to spangle1187's topic in PHP Coding Help
A query that looks like SELECT * FROM booking WHERE. 'clientName == 'Sam'' is not correct. Notice the "." after the WHERE and the single quote before the column name clientName and the extra single quote at the end. It should look like: SELECT * FROM booking WHERE clientName == 'Sam' You code to create the query is wrong. It should be <?php $input = "Sam"; $string = "clientName == '$input'"; $table_id = 'booking'; $query ="SELECT * FROM booking WHERE $string"; $test = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error()); ?> I added the "or die" clause for debugging purposes. Ken -
What's in the variable $raw_value? The explode() function returns an array. Please post your code between tags. Ken
-
What are you trying to accomplish with this code? Since we're seeing only a small snippet of the script, we can't suggest a (possibly) better way. Ken
-
This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=327588.0
-
Please post a few lines before this one. Ken
-
You don't have to use a foreach loop at all, just use the implode() function: <?php $letters = array('a','b','c'); echo implode('<br />',$letters); ?> Ken
-
Here's a simpler way (and cleaner way) of doing this: <?php $tst = array('address_L1'=>'Update Address','intro'=>'About You','profile_image'=>'Add Profile Image','Nickname'=>'Add A Nickname'); $tmp = array(); foreach ($tst as $item => $txt) { if (empty($User[$item])) { $tmp[] = "<li><a href='#'>$txt</a></li>"; } } if (!empty($tmp)) { // if $tmp is not empty a least one of the items tested was empty echo" <div id='items_todo'> <h3>Members Info</h3><br/> <ul>"; echo implode("\n",$tmp) . "\n"; echo"</ul> </div>"; ?> Ken
-
Trouble WITH fucTions //PLEASE HELP ME!!!!?? :)
kenrbnsn replied to phpJoeMo's topic in PHP Coding Help
Please see this reply in another similar topic. It explains everything much better. Ken -
Another way: <?php $two = strtotime('+2 weeks'); $date = time(); while ($date <= $two) { echo date('l, F j, Y',$date) . "<br>"; $date += 86400; //86400 seconds in a day } ?> Ken