Archive for the ‘Question and Answer’ Category

What’s Wrong With My Php Script?

Username:
Password:

mySearch.php
<?php
if (isset($_POST['submit'])) {
if ( ($_POST['username'] == 'myUsername') && ($_POST['password'] == 'myPassword') ) {
header ("Location: http://www.mysite.com/search.html");
}
else {
echo "

The submitted username and password do not match those on file!Go back and try again.

“;
}
}
else {
echo “

Please make sure you enter a username and a password!Go back and try again.

“;
}
}
?>
/*the user logs in, if successful they will go to the search page*/

What’s Wrong With My Php Script?

Username:
Password:

mySearch.php
<?php
if (isset($_POST['submit'])) {
if ( ($_POST['username'] == 'myUsername') && ($_POST['password'] == 'myPassword') ) {
header ("Location: http://www.mysite.com/search.html");
}
else {
echo "

The submitted username and password do not match those on file!Go back and try again.

“;
}
}
else {
echo “

Please make sure you enter a username and a password!Go back and try again.

“;
}
}
?>
/*the user logs in, if successful they will go to the search page*/

I Need The Php Script To Calculate The Input Data From A Form And (-) Or (+) The Result… Please Help!!!?

(HTML-Form)

Unit 2 Project

Name:

Age:

(PHP)
$_POST["Age"]) {
$result = $_POST["retierment"] – $_POST["Age"];
echo $_POST["Name"] ,
} else if ($_POST["Age"] < $_POST["retierment"]) {
$result = $_POST["retierment"] – $_POST["Age"];

age

,

the number of years until you reach retirement age is:

Why Is This Php Script Not Working?

Username:
Password:

//test.php

i wish to redirect the user to my search engine if their login was successful.
thanks a bunch.

Please Help Me Connecting To Mysql Database Using Php.?

Hi guys,
I have designed a very simple guestbook using a mysql database and php to link to my website but am having problems getting it going. Am fairly new to this kind of programming so I am sure its something simple ….. Basically …..
I have a mysql database called MRCADB
& a table within called GUESTBOOK
I have 3 php pages:
GUESTBOOK.PHP
—————————-

Test Sign Guestbook
Name :
Email :
Comment :
View Guestbook

[THAT SEEMS TO WORK FINE & OFFER A PAGE TO ENTER THE MESSAGE ETC]
ADD GUESTBOOK.PHP
————————————
<?php
$host="localhost"; // Host name
$username="myusername"; // Mysql username
$password="mypassword"; // Mysql password
$db_name="mrcadb"; // Database name
$tbl_name="guestbook"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
mysql_select_db("$db_name")or die("cannot select DB");
$datetime=date("y-m-d h:i:s"); //date time
$sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')";
$result=mysql_query($sql);
//check if query successful
if($result){
echo "Successful";
echo "
“;
echo “View guestbook“; // link to view guestbook page
}
else {
echo “ERROR”;
}
mysql_close();
?>
and then finally:
VIEWGUESTBOOK.PHP
————————————-

View Guestbook | Sign Guestbook

ID :
Name :
Email :
Comment :
Date/Time :


————————————–…
Im sure that seems fairly straight forward to you php geniuses!
I have linked the GUESTBOOK.PHP page to my index and when you click onto the link it comes up with the form to add to the guestbook – as I expected.
When I try adding to the guestbook I get an error message that reads “CANNOT SELECT DB”
Further – if I try to view ADDGUESTBOOK.PHP or VIEWGUESTBOOK.PHP I get the same message.
It is obvious that it cannot select the database …. i’m just not sure why! Am I right in thinking that it is connecting to mysql but not finding the database within?
I have set up the mysql on my web server etc – it must just be something small! Aggggghhhhhhhh! Any idea’s?!
Ta in advance! :S
PS … I know that I have used some capitals etc in this message. In my script everything is lowercase so please dont offer that as an answer! :)

How To Build Price List Using Php Mysql And (ajax)?

New to programing.
Database name is rugs
Tables in database are; id (auto increment), size, price 1, price 2, price 3, price 4, price 5, and rug category.
What i need to do is when you click on a rug size it will use ajax to display the different prices on the same page for the clicked rug.
I’ve made a script that displays the rug sizes in a link format
echo “” . $row['size'] . ““;
I got the Javascript / Ajax from w3c from this example;

http://www.w3schools.com/php/php_ajax_database.asp

I cant get the getusers.php to work correctly. How can i get my JavaScript to grab the auto incremented id of every link and post it in the url, so that the getuser.php can collect the auto incremented id and process it.

Php: Writing To Files Using Forms?

Can someone show me a simple PHP script that will use a form with:
* One input field
* A submit button
The submit button sends the contents of that input box to a file. (overwrite).
In new to PHP, iv found help on writing to a file and achieved this: http://www.tizag.com/phpT/filewrite.php
And use of forms and PHP: http://www.w3schools.com/PHP/php_forms.a…
I hope these help you, help me! Thank you in advance :]

Php: Writing To Files Using Forms?

Can someone show me a simple PHP script that will use a form with:
* One input field
* A submit button
The submit button sends the contents of that input box to a file. (overwrite).
In new to PHP, iv found help on writing to a file and achieved this: http://www.tizag.com/phpT/filewrite.php
And use of forms and PHP: http://www.w3schools.com/PHP/php_forms.a…
I hope these help you, help me! Thank you in advance :]

Need A Php Expert For Some Theory Help! I Do Not Want Explicit Code, Just Some Ideas On How To Go About It.?

Here is what I have so far. I populate a table dynamically from my database and include check boxes. I need to be able to modify the text fields, then have only the checked rows updated in my db. I am stuck on how to determine which boxes are checked, and then how to post the correct rows to my modify script. I can modify with sql and delete with sql, just do not know how to transfer the data from an html table by checked rows to my other page. Any help would be greatly appreciated. Here is my code. I am not loooking for specific code examples, that would be cheating. I just need to know if what I am doing is possible and some ideas on where to go with it. NOTE: I commented out the session so it will not affect someone trying to view the table.


<?php
// Starting my session
// session_start();
// if (isset($_SESSION['user'])) {
//
// $msg= "You are logged in as $_SESSION[user]";
// }
// else {
// header("Location: login.html");
// }
// Variable for output
$displayBlock = "";
// Variables for db name, connection, and table name
$db_name= "student_surveydb";
$mainTable= "survey_table";
$connection= mysql_connect("localhost", "root", "")
or die(mysql_error());
// Defining bgcolor variable
$bgcolor= 'beige';
// connecting to db
$db= mysql_select_db($db_name, $connection) or die(mysql_error());
// Assigning select statement to variable.
$sql= "SELECT * FROM $mainTable ORDER BY studentID";
// Assigning result
$result= mysql_query($sql, $connection) or die(mysql_error());
$idarray = array("0");
$firstArray= array("first name");
$lastArray= array("last name");
$genArray= array("gender");
$majArray= array("major");
$comArray= array("comments");
$emailArray= array("email");
// While loop to loop through array of results, assigning values as it goes.
while ($row = mysql_fetch_array($result)) {
$id= $row['studentID'];
array_push($idarray, "$id");
$firstName= $row['studentFirst'];
array_push($firstArray, "$firstName");
$lastName= $row['studentLast'];
array_push($lastArray, "$lastName");
$gender= $row['gender'];
array_push($genArray, "$gender");
$major= $row['major'];
array_push($majArray, "$major");
$comments= $row['comments'];
array_push($comArray, "$comments");
$email= $row['email'];
array_push($emailArray, "$email");
$fullName= "$firstName $lastName";
$num= 1;
// Assigning output as table.
$displayBlock .= "

$id <INPUT TYPE= \"text\" SIZE= \"6\" NAME= \"gender\" VALUE= '$gender' <INPUT TYPE= \"text\" SIZE= \"12\" NAME= \"major\" VALUE= '$major' <INPUT TYPE= \"text\" SIZE= \"22\" NAME= \"comments\" VALUE= '$comments' <INPUT TYPE= \"text\" SIZE= \"22\" NAME= \"email\" VALUE= '$email'

“;
$num++;
}
$num= 0;
?>

<!–

–>

Modify ID Student First Student Last Gender Major Comments E-mail Address

Return to Admin Page.


</FORM

In Php, The True And False Is Going Backwards. What’s Up With That?

My code:
config.php

The code does work, because I tried echoing data from the database inside the IF statement. When I change the password in the function to an incorrect password, the script skips the IF statement, when it’s actually supposed to show it.
Why is that? I’ve tried the following:
if(connectDB())
if(!connectDB())
if(connectDB() == true)
if(connectDB() == false)
Everything is going opposite. When it’s true, it says it’s false and vice versa… I must be doing something wrong, but I’ve had this happen in the best several times with variables, sessions, cookies, POST & GET data, what is it?