-
Posts
1,842 -
Joined
-
Last visited
Posts posted by marcus
-
-
4 days later
-
$fh = fopen($DOCUMENT_ROOT.$PHP_SELF,"r"); $found=false; $title=""; while(!feof($fh) && !found){ if(preg_match("/<title>(.*)<\\\/title>/",fget($fh,4096),$matches)){ $found=true; $title=$matches[1]; } } fclose($fh); if($found){ // Here title is correct } else{ // this page doesn't contain <title> }
-
I could imagine. It has to be possible.
Say:
32000 pounds.
Next day + 40% of that, for 20 years (no leap)
-
Turns out infinite. Anyway around this? I did a for statement before, same result.
-
Just do:
echo "<option value=\"viewguide.php?id=$record[id]\">$record[name]</option>\n";
-
I take a starting number, say, 35000. I want to have it so, the next day I get 40% of that number, and add it, but continue the process for 7300 days.
So:
Day 1: 35000
Day 2: 35000*.40+Day 1
Day 3: Day 2*.40+Day 2
Day 4: Day 3 * .40+ Day 3
for 7300 days.
-
When I want to do something like that I usually set a session variable on the sending page and then check if the session is set when the next page loads, then unset the variable when the page loads so they can't refresh...
They could just close the browser, you could also just set a cookie with an expiration of 2 hours, or a database time field.
Avoid Javascript whenever possible, or paranoid folks like me can't use your site because js is disabled
Just giving it an example, if you're just disabling the submit button, oh well, you could still use the site.
-
If you want to just disable the form just add some javascript.
<form name=name action=file.php method=post onSubmit="document.name.submit.disabled=true"> <input type=submit name=submit value="Send Password"> </form>
If you want to use pure php for this, just set a session and, if you want to limit the amount of time between for them to resend/change their password.
Say you set the session as $_SESSION[pw_time], and the value was time()
Just do this:
if($_SESSION[pw_time]){ $diff = time()-$_SESSION[pw_time]; if($diff < 7200){ //2 hours //no form }else { //form } }else { //form }
-
Just so something as so:
<?php if(!$_POST[ffor]){ echo "ffor has no value"; }else { //query } ?>
-
How many "wardrobe" pieces are actually being printed out, and how many do you actually have it in your field.
-
SMS can be sent via email by addressing the email to phonenumber@provider.com...you should be able to find the @provider.com part from google...for example, verizon is 123456789@vzw.com I think.
Remember that SMS is limited to 160 characters.
Some Verizon is:
ACCOUNT@vtext.com
-
The function mysql_real_escape_string, will escape all apostrophes, making the input value more secure.
To retrieve the data back to its normal state use stripslashes.
<?php $sql = "SELECT * FROM myTable"; $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($res); $msg = stripslashes($row[message]); echo "Message: $msg"; ?>
-
This isn't a PHP error. It's htaccess.
We could /try/ to help if you post your htaccess.
-
I made a file editor, the only problem is that, when I try to change the file contents it just added that content I changed it to the actual file content.
Say:
if file abc.php's content was:
hello
and i wanted to change the WHOLE file to say goodbye and when I hit save, it would make the contents:
hellogoodbye
CODE:
edit.php
<?php $loadcontent = $_GET['page']; if ( isset ( $_POST['savecontent'] ) && trim ( $_POST['savecontent'] ) != '' ) { $content = $_POST['savecontent']; $fp = @fopen ( $loadcontent, 'w' ); if ( $fp ) { fwrite ( $fp, $content ); fclose ( $fp ); } } else { $fp = @fopen ( $loadcontent, 'r' ); $content = htmlspecialchars ( fread ( $fp, filesize ( $loadcontent ) ) ); fclose ( $fp ); } ?> <form method=post action="change.php"> <input type=hidden name=filename value="<?=$_GET
?>"> savecontent <textarea name="theText" cols="70" rows="25"><?=$content;?></textarea> <br> <input type="submit" name="save_file" value="Save"> </form>
change.php
<? ob_start(); $filename = $_POST[filename]; $theText = $_POST[theText]; $theText = stripslashes($theText); $data = fopen($filename, "a"); fwrite($data,$theText); fclose($data); echo "File created or updated"; sleep(3); header("Location: edit.php?page=$filename"); ob_end_flush(); ?>
-
$insert = ("INSERT INTO news (title, date, content) VALUES ('$title', '$date', '$content')"); $add = mysql_query($insert) or die(mysql_error());
change to
$insert = "INSERT INTO `news` (`title`,`date`,`content`) VALUES('$title','$date','$content')"; $add = mysql_query($insert) or die(mysql_error());
You also want to make sure your variables actually have a value defined to them, so before you do the query, echo off the variables.
-
How would I go about, using AJAX and PHP to refresh the page once a new post has arrived?
TABLE: chat
fields: id, username, message
-
If you still want to do it like that, you can do:
$content = $_GET['content']; //$content = mysql_real_escape_string($content); //only if you're pre-connecting to a database if($content){ $content_new = "$content.htm"; if(file_exists($content_new)){ include "$content_new"; }else { echo "This file does not exist"; } }
-
Just do something, like:
$sql = "SELECT * FROM `table` WHERE `id` =#"; //# to the variable for their ID $res = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_assoc($res); echo "<select name=\"country\">\n"; $sql2 = "SELECT * FROM `countries`"; $res2 = mysql_query($sql2) or die(mysql_error()); if(mysql_num_rows($res2) > 0){ while($row2 = mysql_fetch_assoc($res2){ if($row[country] == $row2[country]){ $var = " SELECTED"; }else { $var = ""; } echo "<option value=\"$row2[country]\"$var>$row[country]</option>\n"; } }else { //your own countries } echo "</select>\n";
-
-
If the frames are on the same page you can do in your form.
<form name="name" action="page.php" method="post" target="framename">
-
Instead of
' . $row["field"] . '
Do either:
".$row['field']."
OR
$row[field]
-
Just a suggestion, but why don't you just store it in a cookie or session?
Make three cookies [or] sessions: uid (being the users unique id), topic (being the topic id), time_topicid (being just time()).
Name the cookies/sessions after the topic id.
Then just go to your forums, add something:
if($_COOKIE['TOPICID'] || $_SESSION['TOPICID']){ echo "Read: "; }else { echo "Unread: "; }
If the cookie/session doesn't exist while going to the topic just add it.
Then check the time, if the last post on that topic is greater than the time the person went to it, update the cookie/session to the new time. Within the IF statment posted above, you can add
$time = "SOME QUERY TO FIND THE LAST TIME POSTED ON THAT TOPIC"; if($_COOKIE['time_TOPICID'] < $time || $_SESSION['time_TOPICID'] < $time){ echo "Unread: "; }else { echo "Read: "; }
So basically the whole code would be:
if($_COOKIE['TOPICID'] || $_SESSION['TOPICID']){ if($_COOKIE['time_TOPICID'] < $time || $_SESSION['time_TOPICID'] < $time){ echo "Unread: "; }else { echo "Read: " } }else { echo "Unread :"; }
NOTE: It may not work since I just thought of it now.
EDIT: This could also save database space
-
The ';' isn't completely necassary in that situation.
Best to check if the variable isn't defined:
if (!$_GET['month']) && !$_GET['year'])) { $month = date('n'); $year = date('Y'); } else{ $month = $_GET['month']; $year = $_GET['year']; }
-
Get rid of the '$', you only need stg2.
Desperate now, anyone help me. SQL connecting.
in PHP Coding Help
Posted
Use PHP to connect to it, why would you need to use one of those methods?