Archive for the ‘programming with php’ Category

How do you make a login system with PHP?

Please, no MySQL, I would like this to be connected to a txt file- I know this is less secure, but I don’t know MySQL at all, and I know there is a way to create a login system with just a txt file.

PS
An explanation of the code would be good as well, because I am not a great programmer (I am an eighth grader who took a two week course on java and php programming).

Download the free "Login script" from http://www.web2coders.com
It is more complete than the one described above, and it is commented.

PHP Programming Help!?

Ok, I’m doing an assignment for school that is really confusing me. I made an htm form that is supposed to leave a box for you to enter a grade letter, and after doing so, you will get a different result depending on the letter you typed. I made the PHP file, but no matter what grade I type, it gives me the same result every time, "Your grade is excellent!". I need help with making it give me different results depending on what I type, and I think the main problem is my call statement.

This is my html form (which is fine):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Letter Grades</title>
</head>

<body>
<form action="LetterGrades.php" method="get">
<p>Grade: <input type="text" name="Grade" />
<input name="Submit" type="submit" id="Submit" />
</p>
</form>
</body>
</html>

And this is my PHP file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Letter Grades</title>
</head>

<body>
<?php

function checkGrade($Grade) {
switch ($Grade) {
case "A":
echo "Your grade is excellent.";
break;
case "B":
echo "Your grade is good.";
break;
case "C":
echo "Your grade is fair.";
case "D":
echo "You are barely passing.";
case "F":
echo "You failed.";
default:
echo "You did not enter a valid letter grade.";
}
}
echo checkGrade("A");

?>
</body>
</html>

Could someone please help me?
Thanks, Frank! I think it’s a step in the right direction, but the only problem now is that it’s giving me the default answer everytime now, which is, "You did not enter a valid letter grade."

Do I need to define the A, B, C, D, F variables anywhere?
Ok, it works now, thank you, Frank!!! :D

I think you wrote a good script. The problem with this script i think will be at the last statement (echo checkGrade("A");).

Instead of you writing echo checkGrade("A"); I suggest you write
echo checkGrade("$Grade");
Ooh plus you haven’t linked the form with the php script
write something like:

<?php

function checkGrade($Grade) {
$Grade = $_GET['Grade'];
switch ($Grade) {
case "A":
echo "Your grade is excellent.";
break;
case "B":
echo "Your grade is good.";
break;
case "C":
echo "Your grade is fair.";
case "D":
echo "You are barely passing.";
case "F":
echo "You failed.";
default:
echo "You did not enter a valid letter grade.";
}
}
echo checkGrade("$Grade");

?>

Help With PHP Email Form – Attaching Files?

Hello
being a newbie in php programming field I would like to ask for assistance with e-mail form and attaching files. I have bought a template for website with included mailer form. The only problem with it is that it only allows to attach jpg files and i need word documents, pdf, and exel files as well as images to be attached and mailed.
Below is the script line from the form. Can someone please advise on how can i modify it in order to have word, exel, pdf and image files arrive to my email. Thank you

<? if($_POST) {
include(‘form_config.php’);
if(eregi(‘.jpg’,$_FILES[image][name])) {
$unid = uniqid();
move_uploaded_file($_FILES[image][tmp_name],’offer_uploads/’.$unid.’.jpg’);
$urla = "http://www.globalmeattraders.com/offer_uploads/$unid.jpg";

The code has been truncated, so it is difficult to tell you exactly what is going on…
But, it seems that the line:

if(eregi(‘.jpg’,$_FILES[image][name]… {

is checking whether the uploaded file is of the type .jpg
Whenever, a file is uploaded, the file info is stored in the $_FILES superglobal. You can access the type of the uploaded file using $_FILES[image][type].

So, in the above mentioned if condition, check what is happening. If it is just checking the file type, you can remove it and your code will allow other file extensions too.

Refer to the following link for more details:

http://www.php.net/manual/en/features.file-upload.php

php date function, how to calculate how many days user are in website?

i’m stuck with php programming..

I need calculate how many days user have been in site. (Flat file website)

Registered since: <?php echo "$info[4]"; ?><br />
It prints out this : 03 Jan 2007 08:22 am
[ date("d M Y h:i a"); ]

So how can i calculate how mani days user are in website?
I have tried this, but it’s wrong.

<?php $bDay = mktime($info[4]);
$cTime = time();
$vecums = $cTime-$bDay;
$day = floor($vecums/(60*60*24));
echo " $day days<br />";?>

Here’s a complete solution:

http://www.addedbytes.com/php/php-datediff-function/

I always wondered why PHP doesn’t have an actual DateDiff function…

PHP programming I need help and i know little about programming.?

I am new to programming all together. i know minimal HTML but i have an uncle who works for the Obama web site and he recommended I take up php instead of c and c++. Where should I start? Is there another language i should start with or should i get better at html?
I should mention that I was leaning towards C languages for the possibility of working with tmore stand alone programs. But my uncle pointed me towards web design which would probably be a whole lot more enjoyable (at least to me) And now I am curious about the aforementioned PHP as far as what to know before takng classes for PHP itself. Any prerequisite type stuff? all great answers so ar… very helpful thanks and please if anyone can lend a minute share your insight.
- jordanlaf

Depends on where you want to go with web design…

If you want to have a flexible career and be on the more entertaining side of life, then stick with PHP / MySQL. If you want more "stability"–insurance, benefits, etc.–then you will want to learn those other languages like C#, JAVA, etc., because the bigger shops use these technologies more so than PHP and the like.

…You can learn the (X)HTML 1.0 Strict and CSS 2.0 stuff any day of the week as this is not nearly as complicated as the aforementioned.

In the end, however, it truly matters not for the hammer is only as good as the carpenter who wields it.

What is Edi Mapping Software?

PHP PROGRAMMING FORM DISPLAY URGENT HELP NEEDED?

Hey everyone I have been having this problem all I want to do is query the database then put my variables into a form for example

Select size<br />
<select id=’ldkdk’ onmousedown=’show(this.value)’>
<option value=’$show’>$jjsjs</option>
</select>
<input type=’button’ onClick =’ksksk(jksjsks)’ >
<input type=’text’ id=’data’ size=’20′>
</form>

I am very annoyed as every time i put the variable into the form it turns into two or three forms depending on what data is chosen from the database and all i want is one form with an option to pick a something please can some one help me? I have already tried to exlode the variable but its not working
$qursize = "SELECT * FROM size WHERE caps = ‘$img’";

$resize = mysql_query($qursize) or die(mysql_error());

while($rs = mysql_fetch_array($resize))
{

$size = $rs[size];

$show = "$img,$size,";

$expls = explode(" ", $size);

echo"
<head>
<script type=’text/javascript’ src=’call_cart.js’></script>
<script type=’text/javascript’ src=’call_size.js’></script>
</head>
<body>
<div id=’outofstock’></div>

<form>
Select size<br />
<select id=’sizel’ onmousedown=’showstock(this.value)’>
<option value=’$show’>$expls[0]</option>
<option value=’$show’>$expls[1]</option>
<option value=’$show’>$expls[2]</option>
<option value=’$show’>$expls[3]</option>
<option value=’$show’>$expls[4]</option>

</select>
<input type=’button’ onClick =’showUser(sizel.value)’ >
<input type=’text’ id=’data’ size=’20′>
</form>
OR

$qursize = "SELECT * FROM size WHERE caps = ‘$img’";

$resize = mysql_query($qursize) or die(mysql_error());

while($rs = mysql_fetch_array($resize))
{

$size = $rs[size];

$show = "$img,$size,";

echo"
<head>
<script type=’text/javascript’ src=’call_cart.js’></script>
<script type=’text/javascript’ src=’call_size.js’></script>
</head>
<body>
<div id=’outofstock’></div>

<form>
Select size<br />
<select id=’sizel’ onmousedown=’showstock(this.value)’>
<option value=’$show’>$size</option>

</select>
<input type=’button’ onClick =’showUser(sizel.value)’ >
<input type=’text’ id=’data’ size=’20′>
</form>

and infact i am having a problem with the html form part of my php script itis with the display!

Your problem is caused by having it all inside the while loop. Also if your only calling data from one row you do not need a loop.

$row = mysql_fetch_array(mysql_query("SELECT * FROM size WHERE caps = ‘$img’"));

$size = $row[size];
$expls = explode(" ", $size);

echo"
<html>
<head>
<script type=’text/javascript’ src=’call_cart.js’></script>
<script type=’text/javascript’ src=’call_size.js’></script>
</head>
<body>
<div id=’outofstock’></div>
<form> Select size
<select id=’sizel’ onmousedown=’showstock(this.value)’>
<option value=’$show’>$expls[0]</option>
<option value=’$show’>$expls[1]</option>
<option value=’$show’>$expls[2]</option>
<option value=’$show’>$expls[3]</option>
<option value=’$show’>$expls[4]</option>
</select>
<input type=’button’ onClick =’showUser(sizel.value)’ >
<input type=’text’ id=’data’ size=’20′>
</form>
</body>
</html>

PHP programming with different pages based on different user logins…?

How do I program in php a login page that, based on the username/password, calls DIFFERENT php pages for each username? For instance, if you type in MARY/PASS123 in my_login.php, it should take you to mary.php, and if you type TOM/PASS789, it takes you to tom.php…

Basically, each login gets a different .php, but most answers I’ve seen just show how to get past the login page, not a differential of what type of page is returned after login passes. E.G., MARY/PASS123 and TOM/PASS789 would both take you to generic.php….

Thanks!

You would have to grab the username from the $_POST array, and then do a redirect after processing the login credentials with something like:

header("Location: ".$_POST['username'].".php");

Custom Application Development

Characteristics to Look Out for Judging Reliability – How to Choose Your Website Hosting Company?