-
Posts
1,842 -
Joined
-
Last visited
Posts posted by marcus
-
-
Ok, I'm having trouble exploding text from my file facts.txt
[code]
<?
$r = rand(1,1);
$f = explode("*",facts.txt);
echo $f[$r];
?>
[/code]
what am i doing wrong? -
Ok, those pages don't exist, so please stop linking us to them.
-
you need to define $line before you use it first.
[code]
<html>
<head>
<title>Mailing Data From a File</title>
</head>
<body>
<?php
$line = file("Grades.txt");
$i = 0;
$num = 0;
$cnt = 0;
while ($line[$i] != -2) {
$first = $line[$i];
$i++;
$last = $line[$i];
$i++;
while ($line[$i] != -1) {
$num = $num + $line[$i];
$cnt++;
$i++;
}
$num = $cnt > 0 ? $num / $cnt : 0;
echo "$last, $first, $num
";
$i++;
$cnt = 0;
$num = 0;
}
?>
<?php
$email = $_POST[user_email];
$to = "$email";
$subject = "Grades";
$headers = "From: The PHP Master <youremail>";
mail($to, $subject, $line, $headers);
?>
</body>
</html>
[/code] -
[code]
<?php
$connection = mysql_connect(host,dbuser,dbpass);
$db = mysql_select_db(dbname,$connection);
$sql = "SELECT * FROM dbtable1 WHERE dbtable1.id=$_GET[id];";
$result = mysql_query($sql);
$sql2 = "SELECT * FROM dbtable2 WHERE dbtable2.id=$_GET[id];";
$result2 = mysql_query($sql2);
$result3 = mysql_fetch_assoc($result);
$result4 = mysql_fetch_assoc($result2);
?>
welcome to <?=$result3[username];?>'s profile.
email: <?=$result4[email];?>
[/code]
just use $result3[dbtable] to get info from the first table in your database just change dbtable with your database fields, and the same for $result4[dbtable], just change dbtable to your field in your dbtable1. -
[code]
<?php
include("http://weather.noaa.gov/cgi-bin/fmtbltn.pl?file=forecasts/marine/coastal/an/anz254.txt");
?>[/code] -
just do
[code]
$sql = "INSERT INTO dbtable (`email`) VALUES ('$email@berkeley.edu');";
$result = mysql_query($sql);
[/code] -
store all the emails in a file and separate each on by a |
then do this
[code]
<?php
$to1 = explode("|", "filename.txt");
$to = $to1;
$youremail = your@email.com;
$subject= yoursubject;
$msg = yourmessage;
$headers='From: '.$youremail."\r\n".'MIME-Version: 1.0'."\r\n".'Content-type: text/html; charset=iso-8859-1'."\r\n";
mail($to,$subject,$msg,$headers);
?>
[/code] -
um, could you send me a PM with the URL?
-
you do have the php.ini file right? with register_globals= On right?
-
if no member of that id is valid it will just create blank fields
-
just keep the php.ini file like that for now
-
[code]
<?php
$connection = mysql_connect(localhost,dbuser,dbpass);
$db = mysql_select_db(dbname,$connection);
$sql = "SELECT * FROM user
WHERE user.id='$_GET[id];'";
$result = mysql_query($sql);
$result2 = mysql_fetch_assoc($result);
$user = $result2[username];
?>
<?
if($_GET[id] == false){
echo "No user specify";
}else {
?>
<h3>Welcome to <?=$user?>'s profile.</h3><br>
<? } ?>
[/code] -
you're connecting to the db right?
-
you need register globals on
make a file called php.ini
and make the file include this: register_globals= On -
Well I wanted to know if it was possible to make a png file use php?
-
Where could I find a tutorial on this?
-
[code]
<?php
$get = $_GET[id];
$sql = "SELECT * FROM dbtable WHERE user.id='$get';";
$result=mysql_query($sql);
$result2=mysql_fetch_assoc($result);
?>
Welcome to <?=$result2[username]?> profile.
[/code]
For everything else $result2[DBFIELD];
change dbfield to a field in your DB, whether it's username, email, website, or whatever -
[code]
if ($result) {
echo "Table Created!";
}
else print "Error";
[/code]
change to
[code]
if ($result) {
echo "Table Created!";
}else{
print "Error";
};
[/code] -
Is it possible to include PHP in an image file, like PNG, GIF, JPG, JPEG, BMP... etc...?
Like if I wanted to echo a number in an image, but keep the extension png, gif, jpg etc... -
no problem
-
you should define the cookie value for the other one as well, make it false.
setcookie("login", "false", time()-3600); -
or if you arent using mysql for this
[code]
<?php
$pass = thepassyouwant;
$user = theuseryouwant;
$password = $_POST[password];
$username= $_POST[username];
if($password == $pass && $username == $user){
echo "login right";
setcookie("login","yes",time()+3600);
}else{
echo "wrong login";
};
?>
[/code]
then for pages that require login
[code]
<?php
if($_COOKIE[login] == yes){
echo "stuff you want them to see";
}else{
echo "not logged in or bad auth";
};
?>
[/code] -
probably best if you used a working login script
you can use mine if you want
[code]
<?php
$connection = mysql_connect(host, dbuser, dbpass;
$db = mysql_select_db(dbname, $connection);
$sql = "SELECT * FROM dbtable
WHERE username='$_POST[username]'
AND password='$_POST[password]'";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
if ($num > 0) { // ### USER AND PASSWORD ARE CORRECT
$id = mysql_fetch_assoc($result);
setcookie("login", "yes", time()+3600);
echo "login correct"
}else{ // ### USER OR PASSWORD IS INCORRECT
echo "wrong";
}
?>
[/code]
then on pages if it requires authorization
[code]
<?php
if($_COOKIE[login] == yes){
echo "stuff they can see";
}else {
echo "bad auth";
};
?>
[/code] -
works, thanks ^^
explode() help needed
in PHP Coding Help
Posted
Would I have to do
[code]
<?
$file = fopen("facts.txt","r");
$f = explode("*",$file);
$r = rand(1,1);
echo $f[$r];
?>
[/code]