PDA

View Full Version : A new user to php.



jolicious
05-22-2008, 04:44 AM
Hi everyone, I'm a new user to PHP. I'm learning how to use Dreamweaver, PHP and MS SQL for my final year project. However, there is a problem with MS SQL as my laptop is using XP home edition thus it is unable to install IIS. So currently
I'm using Apache for my web server. I am unfamiliar with Apache and my supervisor has not touched apache for almost 6 years thus he is unable to guide
me with it. I understand that you need to install Apache before PHP for it to work properly. However before installing Apache, I've already installed dreamweaver. Will any problem occur if I do this ? Also are there additional steps need to allow dreamweaver to work properly with apache ? I'm new to this thus I don't really understand much of the lingo for PHP and Dreamweaver. So please bear with my questions thank you.

tech_support
05-22-2008, 07:04 AM
Try xampp (http://www.apachefriends.org/en/xampp.html) if you want everything in one without having to install everything seperately and configuring.

jolicious
05-22-2008, 07:19 AM
Thanks for the link. However I'll need to change from Apache to IIS as my school project requires it. Will any complications arise from switching over ?

tech_support
05-22-2008, 11:56 AM
There shouldn't be, unless you're developing/coding scripts specific to Apache or IIS.

jolicious
05-26-2008, 01:42 AM
Thanks for the reply. Is there any websites you can suggest for learning how to use php and apache as I want to know how to connect to the apache database. I've search the net for information and they give me information on how to connect to mySQL database only.

thetestingsite
05-26-2008, 01:58 AM
Apache is not a database server, but instead a web server. This is why you are not getting any results when searching.

Just found that the apache group has a database project; but php does not have a built-in way of connecting to it. You could probably use odbc_connect (http://php.net/odbc_connect) for it though.

jolicious
05-26-2008, 02:10 AM
Oh. Sorry I'm alittle new here so I'm learning as I go. Does MS SQL works with dreamweaver or am I stuck with MySQL? If MS SQL does work on dreamweaver, does it work without IIS as my laptop can't install it. Thank you for helping me out with those questions.

kuau
05-26-2008, 07:02 AM
I am a newbie too but this is what I know about it.

Dreamweaver is the editor software you use on your local computer to create and edit the html and php files that may or may not interact with data in a MySQL database located on a web server running on Apache.

Dreamweaver can also be used to edit asp files that may or may not interact with data in a MS SQL database running on a Windows server using IIS.

They are 2 different environments and as far as I know are incompatible. You would choose one or the other.

jolicious
05-26-2008, 07:11 AM
Alittle complicated but I think I understand. Anyway Thanks for everything. If anything pops up, I'll post again.

jolicious
05-27-2008, 12:34 AM
Hi, sorry to disturb all of you again. There is a function I would like to create that checks the text in the form and ensure that the text are appropriate for the corresponding information. For example, when a user fills out the information asking for your telephone number and the user types in a letter, the function would detect it and will not submit the file and display an error next to the textbox with the wrong information. Is it easier to start out with the filter function or do I need to use other functions?

fileserverdirect
05-27-2008, 01:13 AM
This is farily easy to do, I could show you how, but is your form's html already done? Or do you need to start from scatch?
:)

jolicious
05-27-2008, 01:23 AM
I've already done the form codes. Its quite messy but it will do fine for now. If you want I could post the codes here. Thanks for your help.

fileserverdirect
05-27-2008, 01:31 AM
Yea, please. Also have you made any php emailing script to process your form?
:)

jolicious
05-27-2008, 02:15 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>FYP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="confirmation.php" enctype="multipart/form-data" method= "post">
<p align="center">Name:
<input type="text" name="name" />
</p>
<p align="center">Admin No.:

<input type="text" name="admin" />
</p>
<p align="center">Gender:
<select name="gender">
<option value="male" selected>Male</option>
<option value="female">Female</option>
</select>
</p>
<p align="center">Address:
<textarea name="address" cols="40"></textarea />
</p>
<p align="center">Home Phone:
<input type="text" name="hometel" />
</p>
<p align="center">Mobile Phone:
<input type="text" name="hp" />
</p>
<p align="center">Contact Email:
<input type="text" name="email" />
</p>
<p align="center">Course:
<select name="course"></select>
</p>
<p align="center">Acad Year:
<input type="text" name="year" />
</p>
<p align="center">Path:
<select name="path">
<option value="1">B1</option>
<option value="2">B2</option>
<option value="3">B3</option>
</select>
</p>
<p align="center">Project Title:
<textarea name="title" cols="40"></textarea>
</p>
<p align="center">Project Supervisor:
<select name="supervisor">
<option value="KC" selected>Mr. Stephen Liew K C</option>
<option value="ng">Mr. Steven Ng</option>
</select>
</p>
<p align="center">
<input name="submit" type="submit" />
</p>
</form>
</body>
</html>

There are the codes for my form. There is a confirmation page but that is not finish yet. For the emailing scripts, I don't need them for now as I need to show my supervisor the confirmation page shows up after submitting. I have not connect to the database yet as I have yet to install MS SQL. After all this is done I might have to integrate them into Joomla.

fileserverdirect
05-28-2008, 02:39 AM
Try this:


<?php
session_start();
function checkphone() {
$phone = $_POST['hometel'];
if (!preg_match('/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/', $phone)) {
echo '<font color="red"><b>Your telephone number is invalad</b></font>';
}
else
{
foreach($_POST as $variable => $value)
{
$_SESSION[$variable] = $value;
}
header("location: conformation.php");
}

}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>FYP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="button.php" enctype="multipart/form-data" method= "post">
<p align="center">Name:
<input type="text" name="name" />
</p>
<p align="center">Admin No.:

<input type="text" name="admin" />
</p>
<p align="center">Gender:
<select name="gender">
<option value="male" selected>Male</option>
<option value="female">Female</option>
</select>
</p>
<p align="center">Address:
<textarea name="address" cols="40"></textarea />
</p>
<p align="center">Home Phone:
<input type="text" name="hometel" /> <br>
<?php checkphone();?>
</p>
<p align="center">Mobile Phone:
<input type="text" name="hp" />
</p>
<p align="center">Contact Email:
<input type="text" name="email" />
</p>
<p align="center">Course:
<select name="course"></select>
</p>
<p align="center">Acad Year:
<input type="text" name="year" />
</p>
<p align="center">Path:
<select name="path">
<option value="1">B1</option>
<option value="2">B2</option>
<option value="3">B3</option>
</select>
</p>
<p align="center">Project Title:
<textarea name="title" cols="40"></textarea>
</p>
<p align="center">Project Supervisor:
<select name="supervisor">
<option value="KC" selected>Mr. Stephen Liew K C</option>
<option value="ng">Mr. Steven Ng</option>
</select>
</p>
<p align="center">
<input name="submit" type="submit" />
</p>
</form>
</body>
</html>


--Just change your form action to whatever the page that it is on.
--You can custimize the looks later, this is just a basic framework of it.
--Change all of your $_POST[...]; on your confrimation page to $_SESSION[...]; and add session_start(); to it too.
:)

jolicious
05-29-2008, 01:14 AM
Thanks for the code. Could you teach me how the following code works as i would like to learn more about it. I tried using your code but after applying the code, the words your telephone number is invalid shows up before the form is submitted. Also I would like to know about session_start() too.

function checkphone() {
$phone = $_POST['hometel'];
if (!preg_match('/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/', $phone)) {
echo '<font color="red"><b>Your telephone number is invalid</b></font>';
}
else
{
foreach($_POST as $variable => $value)
{
$_SESSION[$variable] = $value;
}
header("location: conformation.php");
}


I've also create a confirmation page. But using the echo $_session, I can't get it to display anything. When i try it gives me a blank page. If its too much please tell me as I won't mind. I'm very new to this as this is my first time touching php, dreamweaver adn MS SQL.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>confirmation page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
session_start();



<div align="center">

<p>Name: echo $_SESSION["name"] <br />
Admin No.: echo $_SESSION["admin"] <br />
Gender: echo $_SESSION["gender"] <br />
Address: echo $_SESSION["address"] <br />
Home Phone: echo $_SESSION["hometel"] <br />
Handphone: echo $_SESSION["hp"] <br />
Contact Email: echo $_SESSION["email"] <br />
Course: echo $_SESSION["course"] <br />
Acad Year: echo $_SESSION["year"] <br />
Path: echo $_SESSION["path"] <br />
Project title: echo $_SESSION["title"] <br />
Project Supervisor: echo $_SESSION["supervisor"] <br />

</p>

<p>
<input type="submit" name="Submit" value="Submit">
</p>
<p>
<input name="button" type=button onClick=window.history.back() value=Back back>
</p>


</div>
?>

</body>
</html>

fileserverdirect
05-29-2008, 06:08 PM
Ok I will break it down for you:
function checkphone() { is the start of a function called checkphone.

$phone = $_POST['hometel']; this is assigning $phone to the hometel value just submitted.
if (!preg_match('/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/', $phone)) { this is the hard part to get, the stuff inside preg_match is a pattern.:
^: is the start of the line, [0-9] are optional characters, {3} is the amount it is repeated. etc... and the "!" before means "if it is not equal to".

echo '<font color="red"><b>Your telephone number is invalid</b></font>'; } is the code that is outputed when it is invalid.
else { foreach($_POST as $variable => $value) { is stating that if the phone nuber is valid, then turn all of the posted variables into varibales.
$_SESSION[$variable] = $value; this sets each variable to a session.
header("location: conformation.php"); this relocates you to conformation.php.
---
session_start() is how you introduce a page to a session. put this on each page the requires $_SESSION, like conformation.php. if you want to end a session and destroy all session varibles use session_destroy();
---
You can't put html in php on your conformation page :)
Try this
:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>confirmation page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
session_start();



<div align="center">

echo '<p>Name: '.$_SESSION["name"].' <br />';
echo 'Admin No.: '.$_SESSION["admin"].' <br />';
echo 'Gender: '.$_SESSION["gender"].' <br />';
echo 'Address: '.$_SESSION["address"].' <br />';
echo 'Home Phone: '.$_SESSION["hometel"].' <br />';
echo 'Handphone: '.$_SESSION["hp"].' <br />';
echo 'Contact Email: '.$_SESSION["email"].' <br />';
echo 'Course: '.$_SESSION["course"].' <br />';
echo 'Acad Year: '.$_SESSION["year"].' <br />';
echo 'Path: '.$_SESSION["path"].' <br />';
echo 'Project title:'.$_SESSION["title"].' <br />';
echo 'Project Supervisor: '.$_SESSION["supervisor"].' <br />';
echo '
</p>

<p>
<input type="submit" name="Submit" value="Submit">
</p>
<p>
<input name="button" type=button onClick=window.history.back() value=Back back>
</p>


</div>';
?>

</body>
</html>

There could be a problem, try it out and tell me what happens.

jolicious
06-01-2008, 12:45 AM
Sorry for the late reply. I've tried the code you've gave me but also gives me an error where nothing shows up.

fileserverdirect
06-01-2008, 02:44 PM
Sorry, I missed two key errors:
1. session_start(); should be before any outputted text...
2. <div align="center"> should be echo '<div align="center">';
Full code:


<?php
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>confirmation page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php



echo'<div align="center">';

echo '<p>Name: '.$_SESSION["name"].' <br />';
echo 'Admin No.: '.$_SESSION["admin"].' <br />';
echo 'Gender: '.$_SESSION["gender"].' <br />';
echo 'Address: '.$_SESSION["address"].' <br />';
echo 'Home Phone: '.$_SESSION["hometel"].' <br />';
echo 'Handphone: '.$_SESSION["hp"].' <br />';
echo 'Contact Email: '.$_SESSION["email"].' <br />';
echo 'Course: '.$_SESSION["course"].' <br />';
echo 'Acad Year: '.$_SESSION["year"].' <br />';
echo 'Path: '.$_SESSION["path"].' <br />';
echo 'Project title:'.$_SESSION["title"].' <br />';
echo 'Project Supervisor: '.$_SESSION["supervisor"].' <br />';
echo '
</p>

<p>
<input type="submit" name="Submit" value="Submit">
</p>
<p>
<input name="button" type=button onClick=window.history.back() value=Back back>
</p>


</div>';
?>

</body>
</html>

;)

jolicious
06-02-2008, 12:24 AM
Thanks you for the code. I've would like to ask if I left 1 option for the form blank as I don't know what I should include inside the option, would it disrupt the confirmation page? Because I've tried your code and it displays the words like Name:, Gender:, etc but it does not show the information typed into the form. I'm grateful for all of your help.

fileserverdirect
06-04-2008, 12:50 AM
So Sorry for the late post, I was busy these past couple days...
--
I combined your form page and conformation page into one, this now works without session varables and it's easier to understand, and it will be easier to implicate MySQL in the furture.


<?php

function checkphone() {
global $tel;
$phone = $_POST['hometel'];
if (!preg_match('/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/', $phone)) {
$tel = '<font color="red"><b>Your telephone number is invalad</b></font>';

}
else
{

$GLOBALS['message'] = "true";

}
$GLOBALS['tel'] = $tel;
}

if($_POST['submit'])
{
checkphone();
}
if(!$message){
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>FYP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="button.php" enctype="multipart/form-data" method= "post">
<p align="center">Name:
<input type="text" name="name" />
</p>
<p align="center">Admin No.:

<input type="text" name="admin" />
</p>
<p align="center">Gender:
<select name="gender">
<option value="male" selected>Male</option>
<option value="female">Female</option>
</select>
</p>
<p align="center">Address:
<textarea name="address" cols="40"></textarea />
</p>
<p align="center">Home Phone:
<input type="text" name="hometel" /> <br>
<?php echo $tel; ?>
</p>
<p align="center">Mobile Phone:
<input type="text" name="hp" />
</p>
<p align="center">Contact Email:
<input type="text" name="email" />
</p>
<p align="center">Course:
<select name="course"></select>
</p>
<p align="center">Acad Year:
<input type="text" name="year" />
</p>
<p align="center">Path:
<select name="path">
<option value="1">B1</option>
<option value="2">B2</option>
<option value="3">B3</option>
</select>
</p>
<p align="center">Project Title:
<textarea name="title" cols="40"></textarea>
</p>
<p align="center">Project Supervisor:
<select name="supervisor">
<option value="KC" selected>Mr. Stephen Liew K C</option>
<option value="ng">Mr. Steven Ng</option>
</select>
</p>
<p align="center">
<input name="submit" type="submit" />
</p>
</form>
<?php
} else {

echo'<div align="center">';
echo '<p>Name: '.$_POST["name"].' <br />';
echo 'Admin No.: '.$_POST["admin"].' <br />';
echo 'Gender: '.$_POST["gender"].' <br />';
echo 'Address: '.$_POST["address"].' <br />';
echo 'Home Phone: '.$_POST["hometel"].' <br />';
echo 'Handphone: '.$_POST["hp"].' <br />';
echo 'Contact Email: '.$_POST["email"].' <br />';
echo 'Course: '.$_POST["course"].' <br />';
echo 'Acad Year: '.$_POST["year"].' <br />';
echo 'Path: '.$_POST["path"].' <br />';
echo 'Project title:'.$_POST["title"].' <br />';
echo 'Project Supervisor: '.$_POST["supervisor"].' <br />';
?>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
<p>
<input name="button" type=button onClick=window.history.back() value=Back back>
</p>
</div>
<?php }?>
</body>
</html>

Have any Questions? :)

jolicious
06-04-2008, 03:08 AM
Sorry for disturbing you when you are so busy. There are several questions I would like to ask about the code you have provided. First would be the <?php }?> located somewhere at the bottom of the code. I would like to know about the function about that. Second would be that the confirmation does not show up after clicking submit. I've tried changing it to a confirmation page I've done using $_post to get the input from the form and it works but the telephone verification does not work when I do this. Could it be due to me using firefox ? Lastly are there any good websites for learning php beside w3school? I feeling kinda bad asking you all this questions when you are busy.

fileserverdirect
06-04-2008, 07:51 PM
Hi, I was just away for a while, and did not get your post, thats what I meant by "busy" :)
--


First would be the <?php }?> located somewhere at the bottom of the code. I would like to know about the function about that.

You can include html output outside of <?php ?> as long as whatever was started, so somthimge like:


<?php
if($var == "true")
{
?>
Some HTML to show is $var is equal to "true"
<?php
}
?>

This would be valid.
---

Second would be that the confirmation does not show up after clicking submit.
It everything works fine on my webserver. http://klein-onlineblog.com/dynamicdrive/New%20user%20to%20php/button.php See if it works for you there. It should not have anything to do with firefox or IE, because php is serer-side. Can you provide a link to your page online, and what version of php do you have?
:)

jolicious
06-05-2008, 01:17 AM
I'm using php version 5.2.6 and apache version 2.2. I've tried the form on your page and it works well but is there a confirmation page on your website ? I've tried filling out and it gives me invalid phone number. Also I do not know how to bring my form online. I'm using local host and dreamweaver to test out the codes. I need to use MS SQL
as the database. I'm now learning how to use MS SQL and connecting to the form.

fileserverdirect
06-05-2008, 08:53 PM
Not sure by what you mean "Confirmation". After you enter a corrrect phone number (Ex: 555-555-5555), It will submit the page and all the values will appear. Thats the confirmation page code that you suppliped me with earlier. You could put somthing like: "Please confirm that this info is true, if not, please go back to the form and correct it." Or do you mean somthing like a confirmation email that confirms that the user is human. (you could use CAPTCHA). So what exactly do you mean. :)

jolicious
06-06-2008, 12:12 AM
Oh. Sorry for not being clear. Apparently I was typing in the wrong type of phone number. Thus I was not able to view the page where it ask you to check i f the information you have given was correct. The codes are working fine. Edit: I've changed to function code alittle so that it accepts phone number from my country. Also I also try creating a function for checking email from the code you have gave me. Will the following code work in my program ?

<?php


function checkemail() {
global $mail;
$elmail = $_POST['email'];
if (!preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email)) {
$mail = '<font color="red"><b>Your Email is invalid</b></font>';

}
else
{
$GLOBALS['message'] = "true";
}
$GLOBALS['mail'] = $mail;
}

if($_POST['submit'])
{
checkmail();
}
if(!$message){
?>

fileserverdirect
06-07-2008, 12:56 AM
Hi, sorry for the phone number mix-up but I can see one error with your code:
$elmail = $_POST['email']; should be $email = $_POST['email'];.
Also, your preg_match should look like:
“/^([a-zA-Z0-9])+([a-zA-Z0-9\.\\+=_-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/” - not tested
This is not totally fool-prof. Something like 1@1.qqq would pass through. You would need to go a lot more complex to catch stuff like that.
--
Your original post stated something like "Why doesn't it work on my local machine". Local machine can't do everything, they are not designed to be a web server. Find a free online php hosting site and test it online.
--
A couple posts ago you mechined the database "MS SQL". This is not the best database to work with. "My SQL" is much much much easier to work with, and it is free, and versitile. I also recomend getting "phpMySQL" , a free My SQL Management software... :)

jolicious
06-10-2008, 12:26 AM
Sorry for the slow reply, my internet was down for a few days. Thanks for the correction. For the database, I'm not sure if I'm allowed to use MySQL or any other. I've just send an email to my supervisor asking him if I can use MySQL for my project. I'll try hosting my project online after I'm done with the problem above regrading the database. For the email verification, I'll upgrade it while doing the project and as I learn more about PHP.

jolicious
06-11-2008, 01:35 AM
I would like to ask about the following codes :
$email = $_POST['email']; Would it cause an error if both of them have the same name ?
Also is there any other codes I need to add if I were to include the email and telephone verification codes in my form ? I've tried adding both of them into my code and it would not show the confirmation page. After removing the email verification codes, the form would work perfectly fine. Also my supervisor sent me a reply. Due to a typo error, I need to use MS Access instead of MS SQL or MySQL

fileserverdirect
06-13-2008, 11:44 PM
Sorry, my email server was down and did not know you replied until now...
--


I would like to ask about the following codes :
PHP Code:
$email = $_POST['email'];

Would it cause an error if both of them have the same name ?


For one, $email = $_POST['email']; does not cause an error because you are setting the local variable $email to the previously posted variable email on the previous page, therefore $email on one page could be totally different on another.
--


Also is there any other codes I need to add if I were to include the email and telephone verification codes in my form ? I've tried adding both of them into my code and it would not show the confirmation page. After removing the email verification codes, the form would work perfectly fine.

Post your code online, and maybe I could debug it, and find out why it's not accepting your functions.
--


Also my supervisor sent me a reply. Due to a typo error, I need to use MS Access instead of MS SQL or MySQL


I am not quite sure about how to use MS Access with php documents, you could do a google search or whatever... :)

jolicious
06-15-2008, 03:17 AM
This is my current code including the email verification codes

<?php

function checkphone() {
global $tel;
$phone = $_POST['hometel'];
if (!preg_match('/^[0-9]{8}$/', $phone)) {
$tel = '<font color="red"><b>Your telephone number is invalad</b></font>';

}
else
{

$GLOBALS['message'] = "true";

}
$GLOBALS['tel'] = $tel;
}

if($_POST['submit'])
{
checkphone();
}
if(!$message){
?>

<?php


function checkemail() {
global $mail;
$email = $_POST['email'];
if (!preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9\.\\+=_-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/', $email)) {
$mail = '<font color="red"><b>Your Email is invalid</b></font>';

}
else
{
$GLOBALS['message'] = "true";
}
$GLOBALS['mail'] = $mail;
}

if($_POST['submit'])
{
checkmail();
}
if(!$message){
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>FYP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="project4.php" enctype="multipart/form-data" method= "post">
<p align="center">Name:
<input type="text" name="name" />
</p>
<p align="center">Admin No.:

<input type="text" name="admin" />
</p>
<p align="center">Gender:
<select name="gender">
<option value="male" selected>Male</option>
<option value="female">Female</option>
</select>
</p>
<p align="center">Address:
<textarea name="address" cols="40"></textarea />
</p>
<p align="center">Home Phone:
<input type="text" name="hometel" /> <br>
<?php echo $tel; ?>
</p>
<p align="center">Mobile Phone:
<input type="text" name="hp" />
</p>
<p align="center">Contact Email:
<input type="text" name="email" />
<?php echo $mail; ?>
</p>
<p align="center">Course:
<select name="course"></select>
</p>
<p align="center">Acad Year:
<input type="text" name="year" />
</p>
<p align="center">Path:
<select name="path">
<option value="1">B1</option>
<option value="2">B2</option>
<option value="3">B3</option>
</select>
</p>
<p align="center">Project Title:
<textarea name="title" cols="40"></textarea>
</p>
<p align="center">Project Supervisor:
<select name="supervisor">
<option value="Mr. Stephen Liew K C" selected>Mr. Stephen Liew K C</option>
<option value="Mr. Steven Ng">Mr. Steven Ng</option>
</select>
</p>
<p align="center">
<input name="submit" type="submit" />
</p>
</form>
<?php
} else {

echo'<div align="center">';
echo '<p>Name: '.$_POST["name"].' <br />';
echo 'Admin No.: '.$_POST["admin"].' <br />';
echo 'Gender: '.$_POST["gender"].' <br />';
echo 'Address: '.$_POST["address"].' <br />';
echo 'Home Phone: '.$_POST["hometel"].' <br />';
echo 'Handphone: '.$_POST["hp"].' <br />';
echo 'Contact Email: '.$_POST["email"].' <br />';
echo 'Course: '.$_POST["course"].' <br />';
echo 'Acad Year: '.$_POST["year"].' <br />';
echo 'Path: '.$_POST["path"].' <br />';
echo 'Project title:'.$_POST["title"].' <br />';
echo 'Project Supervisor: '.$_POST["supervisor"].' <br />';
?>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
<p>
<input name="button" type=button onClick=window.history.back() value=Back back>
</p>
</div>
<?php }?>
<?php }?>
</body>
</html>

fileserverdirect
06-15-2008, 02:29 PM
Here, try this:


<?php

function checkphone() {
global $tel;
$phone = $_POST['hometel'];
if (!preg_match('/^[0-9]{8}$/', $phone)) {
$tel = '<font color="red"><b>Your telephone number is invalad</b></font>';
$GLOBALS['tel'] = $tel; }
else{
$GLOBALS['showtel'] = "true";
}
}


function checkemail() {
global $mail;
$email = $_POST['email'];
if (!preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9\.\\+=_-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/', $email)) {
$mail = '<font color="red"><b>Your Email is invalid</b></font>';

$GLOBALS['mail'] = $mail; }
else
{
$GLOBALS['showmail'] = "true";
}
}

if($_POST['submit'])
{
checkphone();
checkemail();
}
if(!$showtel||!$showmail){
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>FYP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" method= "post">
<p align="center">Name:
<input type="text" name="name" />
</p>
<p align="center">Admin No.:

<input type="text" name="admin" />
</p>
<p align="center">Gender:
<select name="gender">
<option value="male" selected>Male</option>
<option value="female">Female</option>
</select>
</p>
<p align="center">Address:
<textarea name="address" cols="40"></textarea />
</p>
<p align="center">Home Phone:
<input type="text" name="hometel" /> <br>
<?php echo $tel; ?>
</p>
<p align="center">Mobile Phone:
<input type="text" name="hp" />
</p>
<p align="center">Contact Email:
<input type="text" name="email" /> <br>
<?php echo $mail; ?>
</p>
<p align="center">Course:
<select name="course"></select>
</p>
<p align="center">Acad Year:
<input type="text" name="year" />
</p>
<p align="center">Path:
<select name="path">
<option value="1">B1</option>
<option value="2">B2</option>
<option value="3">B3</option>
</select>
</p>
<p align="center">Project Title:
<textarea name="title" cols="40"></textarea>
</p>
<p align="center">Project Supervisor:
<select name="supervisor">
<option value="Mr. Stephen Liew K C" selected>Mr. Stephen Liew K C</option>
<option value="Mr. Steven Ng">Mr. Steven Ng</option>
</select>
</p>
<p align="center">
<input name="submit" type="submit" />
</p>
</form>
<?php
} else {

echo'<div align="center">';
echo '<p>Name: '.$_POST["name"].' <br />';
echo 'Admin No.: '.$_POST["admin"].' <br />';
echo 'Gender: '.$_POST["gender"].' <br />';
echo 'Address: '.$_POST["address"].' <br />';
echo 'Home Phone: '.$_POST["hometel"].' <br />';
echo 'Handphone: '.$_POST["hp"].' <br />';
echo 'Contact Email: '.$_POST["email"].' <br />';
echo 'Course: '.$_POST["course"].' <br />';
echo 'Acad Year: '.$_POST["year"].' <br />';
echo 'Path: '.$_POST["path"].' <br />';
echo 'Project title:'.$_POST["title"].' <br />';
echo 'Project Supervisor: '.$_POST["supervisor"].' <br />';
?>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
<p>
<input name="button" type=button onClick=window.history.back() value=Back back>
</p>
</div>
<?php }?>
</body>
</html>

:)

jolicious
06-17-2008, 11:56 PM
Thanks for the code and sorry for the slow reply. I would like to ask whats the difference between Globals and SuperGlobals and what do they do. Thanks

fileserverdirect
06-18-2008, 07:57 PM
Globals are variables that are universal throughout the script. So if $var was set inside a function, it could not be accessed by the outside script unless it was a global variable (or vica versa).
SuperGlobals are variables set by PHP itself. A SuperGlobal variable is something like $_SESSION['var']; or $_SERVER['PHP_SELF'];. You cannot create any new superglobals, but you can set them, like: $_COOKIE['time'] = "November 5 1985";. All superglobals start with $_ to Identify them as superglobals and not any ol' user defined variable.
Any other Questions? :)

jolicious
06-23-2008, 01:56 AM
Thank you for your wonderful explanation on globals and superglobals. I would like to ask afew questions. Can php and javascript work properly together ? And is there a function or way to retrieve the data after clicking the submit button when there is an invalid input ? I'm asking those questions as my supervisor suggested that I can use java to solve the problem but as I'm new to programming it would take quite awhile to learn java. I would like to know how to retrieve data from MS access via php too. I've been searching the web for quite awhile now but most of them I've found are using Visual Basic. Some websites states that ODBC connections are required to make a connection. What is the ODBC connections that is stated and how can I get them ?

Update:I've just came back from my oversea project attachment and now I'm doing my project on another computer with IIS installed into it. I'm manage to setup the IIS and dreamweaver to work together via internet tutorials. However a PHP notice is shown below the form when I run the form. This is the notice : PHP Notice: Undefined index: submit in C:\Inetpub\wwwroot\project5.php on line 28 PHP Notice: Undefined variable: showtel in C:\Inetpub\wwwroot\project5.php on line 33 PHP Notice: Undefined variable: tel in C:\Inetpub\wwwroot\project5.php on line 62 PHP Notice: Undefined variable: mail in C:\Inetpub\wwwroot\project5.php on line 69. No codes were add nor changed during this transition. Thank you for helping me out.
I've temperarily solved the above problem by using error_reporting(E_ALL ^ E_NOTICE). But is there any other way to solve it ?

jolicious
06-30-2008, 08:41 AM
Hi, I've managed to connect to MS Access via ODBC. However a new problem has occured. After clicking on the submit button on the confirmation page, the data from the form are supposed to be saved to the database. But each time I click on the submit button, an internal error 500 would occur. I've tried looking for the error and I feel that it could be due to the code not being able to caputure the data from the form.
Here is the code for the form:


<?php
error_reporting(E_ALL ^ E_NOTICE);
?>
<?php

function checkphone() {
global $tel;
$phone = $_POST['hometel'];
if (!preg_match('/^[0-9]{8}$/', $phone)) {
$tel = '<font color="red"><b>Your telephone number is invalad</b></font>';
$GLOBALS['tel'] = $tel; }
else{
$GLOBALS['showtel'] = "true";
}
}


function checkemail() {
global $mail;
$email = $_POST['email'];
if (!preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9\.\\+=_-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/', $email)) {
$mail = '<font color="red"><b>Your Email is invalid</b></font>';

$GLOBALS['mail'] = $mail; }
else
{
$GLOBALS['showmail'] = "true";
}
}

if($_POST['submit'])
{
checkphone();
checkemail();
}
if(!$showtel||!$showmail){
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>FYP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" method= "post">
<p align="center">Name:
<input type="text" name="name" />
</p>
<p align="center">Admin No.:

<input type="text" name="admin" />
</p>
<p align="center">Gender:
<select name="gender">
<option value="male" selected>Male</option>
<option value="female">Female</option>
</select>
</p>
<p align="center">Address:
<textarea name="address" cols="40"></textarea />
</p>
<p align="center">Home Phone:
<input type="text" name="hometel" /> <br>
<?php echo $tel; ?>
</p>
<p align="center">Mobile Phone:
<input type="text" name="hp" />
</p>
<p align="center">Contact Email:
<input type="text" name="email" /> <br>
<?php echo $mail; ?>
</p>
<p align="center">Course:
<select name="course"></select>
</p>
<p align="center">Acad Year:
<input type="text" name="year" />
</p>
<p align="center">Path:
<select name="path">
<option value="1">B1</option>
<option value="2">B2</option>
<option value="3">B3</option>
</select>
</p>
<p align="center">Project Title:
<textarea name="title" cols="40"></textarea>
</p>
<p align="center">Project Supervisor:
<select name="supervisor">
<option value="Mr. Stephen Liew K C" selected>Mr. Stephen Liew K C</option>
<option value="Mr. Steven Ng">Mr. Steven Ng</option>
</select>
</p>
<p align="center">
<input name="submit" type="submit" />
</p>

</form>

<?php

} else {


echo'<div align="center">';
echo '<p>Name: '.$_POST["name"].' <br />';
echo 'Admin No.: '.$_POST["admin"].' <br />';
echo 'Gender: '.$_POST["gender"].' <br />';
echo 'Address: '.$_POST["address"].' <br />';
echo 'Home Phone: '.$_POST["hometel"].' <br />';
echo 'Handphone: '.$_POST["hp"].' <br />';
echo 'Contact Email: '.$_POST["email"].' <br />';
echo 'Course: '.$_POST["course"].' <br />';
echo 'Acad Year: '.$_POST["year"].' <br />';
echo 'Path: '.$_POST["path"].' <br />';
echo 'Project title:'.$_POST["title"].' <br />';
echo 'Project Supervisor: '.$_POST["supervisor"].' <br />';
?>
<form action="databaseupdatingtestrun.php" enctype="multipart/form-data" method= "post">

<p>
<input type="submit" name="Submit" value="Submit">
</p>
<p>
<input name="button" type=button onClick=window.history.back() value=Back back>
</p>
</div>
<?php }?>
</form



</body>
</html>
And here is the code for submitting into the database:

<?php
error_reporting(E_ALL ^ E_NOTICE);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$name = $_POST['name'];
$admin = $_POST['admin'];
$gender = $_POST['gender'];
$address = $_POST['address'];
$hometel = $_POST['hometel'];
$hp = $_POST['hp'];
$email = $_POST['email'];
$course = $_POST['course'];
$year = $_POST['year'];
$path = $_POST['path'];
$title = $_POST['title'];
$supervisor = $_POST['supervisor'];
$odbc = odbc_connect('FYP', '', '') or die('Could not connect to ODBC database!');
$query = "INSERT INTO fyp (Name, AdminNumber, Gender, Address, Hometelephone, MobilePhone, Email, AcadCourse, Year, Path ,Projecttitle, ProjectSupervisor) VALUES ("$name", "$admin", "$gender", "$address", "$hometel", "$hp", "$email", "$course", "$year", "$path", "$title", "$supervisor")";
$result = odbc_exec($odbc, $query) or die (odbc_errormsg());
odbc_close($odbc);
?>
</body>
</html>

jolicious
06-30-2008, 09:35 AM
I've found the code thats producing the error its in the database submittion codes. The code thats give an error is :

<?php
error_reporting(E_ALL ^ E_NOTICE);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
echo "Your data is successfully submitted";
?>
<?php
$name = $_POST['name'];
$admin = $_POST['admin'];
$gender = $_POST['gender'];
$address = $_POST['address'];
$hometel = $_POST['hometel'];
$hp = $_POST['hp'];
$email = $_POST['email'];
$course = $_POST['course'];
$year = $_POST['year'];
$path = $_POST['path'];
$title = $_POST['title'];
$supervisor = $_POST['supervisor'];
$odbc = odbc_connect('FYP', '', '') or die('Could not connect to ODBC database!');
$input = "INSERT INTO fyp (Name, AdminNumber, Gender, Address, Hometelephone, MobilePhone, Email, AcadCourse, Year, Path ,Projecttitle, ProjectSupervisor) VALUES ("$name", "$admin", "$gender", "$address", "$hometel", "$hp", "$email", "$course", "$year", "$path", "$title", "$supervisor")";
$result = odbc_exec($odbc, $input) or die (odbc_errormsg());
odbc_close($odbc);
?>
</body>
</html>
If i change the " to ', it will submit an empty data input to my database. It seems it can't retreive the data from the form. Can anyone help me out on this code ?

fileserverdirect
06-30-2008, 03:20 PM
O.K. I am so sorry that I have not replyed to any of your posts this past week. I am currently on vacation right now and will be come for a few days but then I will be away again for about two more weeks. I am writing to you from a public library, so please do not take this personal :) . I may be able to reply to your upcoming posts, but it may take a while. ;)
-----
POST 1:

Can php and javascript work properly together ?
Yes, very well, it all depends on what your goal that your trying to reach
--

And is there a function or way to retrieve the data after clicking the submit button when there is an invalid input ? I'm asking those questions as my supervisor suggested that I can use java to solve the problem but as I'm new to programming it would take quite awhile to learn java. I would like to know how to retrieve data from MS access via php too. I've been searching the web for quite awhile now but most of them I've found are using Visual Basic. Some websites states that ODBC connections are required to make a connection. What is the ODBC connections that is stated and how can I get them ?

I am sorry that I cannot really help you with this part, I ownly know 1 database language and that's MySQL.
--

However a PHP notice is shown below the form when I run the form. This is the notice : PHP Notice: Undefined index: submit in C:\Inetpub\wwwroot\project5.php on line 28 PHP Notice: Undefined variable: showtel in C:\Inetpub\wwwroot\project5.php on line 33 PHP Notice: Undefined variable: tel in C:\Inetpub\wwwroot\project5.php on line 62 PHP Notice: Undefined variable: mail in C:\Inetpub\wwwroot\project5.php on line 69. No codes were add nor changed during this transition. Thank you for helping me out.
I've temperarily solved the above problem by using error_reporting(E_ALL ^ E_NOTICE). But is there any other way to solve it ?

Try using echo phpinfo(); in both enviorments and compare them and see what you need to switch on or off for this to work correctly.

----
POST 2\3:

In your second post you have one error that could be causing everything to mess up:
<form action="databaseupdatingtestrun.php" enctype="multipart/form-data" method= "post">

That should be this
<form action="databaseupdatingtestrun.php" enctype="multipart/form-data" method="post">

Try that and maybe that might solve the question on your Third post :)
Any more Questions? :)

jolicious
07-01-2008, 01:05 AM
Sorry for disturbing you on your vacation. I've tried deleting the empty space but the error is still there. I've tried using a simple code to test if the data can be captured but it still display as a black space.
This is the code :

<?php
echo "Your data is successfully submitted";
?>
<?php

echo '<p>Name: '.$_POST['name'].' <br />';

?>
Its ok if you are too busy. You have been really helpful and I thank you from the bottom of my heart.

fileserverdirect
07-01-2008, 03:11 PM
This:

echo '<p>Name: '.$_POST['name'].' <br />';

Should be this:

echo '<p>Name: '.$_POST["name"].' <br />';

or even:

echo "<p>Name: $_POST['name'] <br />";

Did this solve your problem? :)

jolicious
07-02-2008, 01:08 AM
Thanks for the code. It seems that it works but once I start trying to connect to the database, it gives me internal error 500. This is the code that I've used


$odbc = odbc_connect('FYP', '', '') or die('Could not connect to ODBC database!');
$start = "INSERT INTO babel (Name) Values ('$FName')";
$insert = odbc_exec($start,$odbc);

?>

fileserverdirect
07-02-2008, 03:34 PM
$FName = $_POST['FName'] should be $FName = $_POST['FName'];
This could be interfering with the next line therefore causeing the error... :)

jolicious
07-03-2008, 01:27 AM
Thanks for the input but the problem still remains. I've tried checking for permission and everything seems to be in order. The database IDs are also identical to those in the code. I'm not sure what is wrong with my program.

allahverdi
07-03-2008, 04:56 AM
jolicious, Can you copy your full code?

And i think you know, form method must be post. I mean:

<form method="post">
<input type="text" name="FName"/>
</form>

jolicious
07-03-2008, 06:28 AM
Sure. After clicking submit on the confirmation page, it would show page cannot be display when it is actually suppose to insert the data into the database.
this is the form's code:


<?php
error_reporting(E_ALL ^ E_NOTICE);
?>
<?php

function checkphone() {
global $tel;
$phone = $_POST['hometel'];
if (!preg_match('/^[0-9]{8}$/', $phone)) {
$tel = '<font color="red"><b>Your telephone number is invalad</b></font>';
$GLOBALS['tel'] = $tel; }
else{
$GLOBALS['showtel'] = "true";
}
}


function checkemail() {
global $mail;
$email = $_POST['email'];
if (!preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9\.\\+=_-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/', $email)) {
$mail = '<font color="red"><b>Your Email is invalid</b></font>';

$GLOBALS['mail'] = $mail; }
else
{
$GLOBALS['showmail'] = "true";
}
}

if($_POST['submit'])
{
checkphone();
checkemail();
}
if(!$showtel||!$showmail){
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>FYP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p align="center">Name:
<input type="text" name="username" />
</p>
<p align="center">Admin No.:

<input type="text" name="admin" />
</p>
<p align="center">Gender:
<select name="gender">
<option value="male" selected>Male</option>
<option value="female">Female</option>
</select>
</p>
<p align="center">Address:
<textarea name="address" cols="40"></textarea />
</p>
<p align="center">Home Phone:
<input type="text" name="hometel" /> <br>
<?php echo $tel; ?>
</p>
<p align="center">Mobile Phone:
<input type="text" name="hp" />
</p>
<p align="center">Contact Email:
<input type="text" name="email" /> <br>
<?php echo $mail; ?>
</p>
<p align="center">Course:
<select name="course">
<option value="ECC">ECC</option>
</select>
</p>
<p align="center">Acad Year:
<input type="text" name="year" />
</p>
<p align="center">Path:
<select name="path">
<option value="1">B1</option>
<option value="2">B2</option>
<option value="3">B3</option>
</select>
</p>
<p align="center">Project Title:
<textarea name="title" cols="40"></textarea>
</p>
<p align="center">Project Supervisor:
<select name="supervisor">
<option value="Mr. Stephen Liew K C" selected>Mr. Stephen Liew K C</option>
<option value="Mr. Steven Ng">Mr. Steven Ng</option>
</select>
</p>
<p align="center">
<input name="submit" type="submit" />
</p>

</form>

<?php
} else {
?>
<form action="datasubmit.php" method="post">
<?php

echo'<div align="center">';
echo '<p>Name: '.$_POST["username"].' <br />';
echo 'Admin No.: '.$_POST["admin"].' <br />';
echo 'Gender: '.$_POST["gender"].' <br />';
echo 'Address: '.$_POST["address"].' <br />';
echo 'Home Phone: '.$_POST["hometel"].' <br />';
echo 'Handphone: '.$_POST["hp"].' <br />';
echo 'Contact Email: '.$_POST["email"].' <br />';
echo 'Course: '.$_POST["course"].' <br />';
echo 'Acad Year: '.$_POST["year"].' <br />';
echo 'Path: '.$_POST["path"].' <br />';
echo 'Project title:'.$_POST["title"].' <br />';
echo 'Project Supervisor: '.$_POST["supervisor"].' <br />';
?>
<p>
<input type="submit" name="Submit" value="Submit">
</form>
</p>
<p>
<input name="button" type=button onClick=window.history.back() value=Back back>
</p>
</div>
<?php }?>

</body>
</html>



This is the data submittion codes:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$username = $_POST['username'];
$admin = $_POST['admin'];
$gender = $_POST['gender'];
$address = $_POST['address'];
$phone = $_POST['hometel'];
$hp = $_POST['hp'];
$email = $_POST['email'];
$course = $_POST['course'];
$year = $_POST['year'];
$path = $_POST['path'];
$title = $_POST['title'];
$supervisor = $_POST['supervisor'];
echo "Data has been submitted";

function Enter_New_Entry($username,$admin) {


$cnx = odbc_connect( 'FYP' , 'root', '' );
if (!$cnx) {
Error_handler( "Error in odbc_connect" , $cnx );
}
$SQL_Exec_String = "Insert Into fyp (name, admin, gender, address, hometel, hp, email, course, year, path, title, supervisor )
Values ('$username', '$admin', '$gender', '$address', '$phone', '$hp', '$email', '$course', '$year', '$path', '$title', '$supervisor')";

$cur= odbc_exec( $cnx, $SQL_Exec_String );
if (!$cur) {
Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
}

odbc_close( $cnx);
}
Enter_New_Entry($username,$admin);
?>

</body>
</html>

allahverdi
07-03-2008, 06:45 AM
Can you copy the error here too :D

I think your problem is in your db connection... But copy error here first :)

jolicious
07-03-2008, 08:23 AM
Is there a way to get an error report from IE ? After running the script, I get HTTP 500 internal server error. I heard there is a way to get a more detailed report but I don't know how.

allahverdi
07-03-2008, 08:57 AM
Does the script works? or no?

jolicious
07-03-2008, 09:18 AM
The codes for the form works but the code in for data submitting do not work. It would display "The page cannot be displayed and HTTP 500 - Internal server error ".

fileserverdirect
07-03-2008, 03:30 PM
Try using the die(); function to show errors. Like:


if(!$cnx = odbc_connect( 'FYP' , 'root', '' ))die("error with connection");

And allahverdi, he is using a local enviorment, so there could be some local interference.
And jolicious, I would EXTREAMLY RECOMEND uploading your page to a free php hosting service. Also a free MS SQL hosting. For php hosting, I recomend AwardSpace. As for MS SQL, Biz Host Net (http://free-sql.bizhostnet.com/step1.html) or just google it and see what more you can find... :)

allahverdi
07-03-2008, 04:06 PM
Ah, right. I haven't used ms sql. But i want ask. Is there something like mysql_error()? mssql_error()?

fileserverdirect
07-03-2008, 08:52 PM
Not Sure, you would have to look at php.net...

jolicious
07-04-2008, 01:19 AM
I'm really wish that I could use MySQL but problem is that my online will be used by my insitute on their website thus MS Access is required for this project. Will be alot of changes to be made if I switch to MySQL to host it online? Because after checking the code works online, I'll have to switch back to MS Access. If the code works, I'll try hosting it on the server running Joomla in the lab. Some of the information that will be included are classified thus I'm not allowed to host it online even for testing. The only way is to use the servers on my lab to test the codes.

fileserverdirect
07-04-2008, 03:34 PM
Will be allot of changes to be made if I switch to MySQL to host it online? No not much. MySQL is one hundred times easier than MS Access and OBDC(spell?) Connections. I learned alot about MySQL at http://www.phpeasystep.com/mysql.php . It will help you out ALOT.


The only way is to use the servers on my lab to test the codes.

That will also work, as long as you use a dedicated server and not a home desktop\laptop.
:)

jolicious
07-07-2008, 03:22 AM
Sorry for the slow reply, the internet was acting weird for the past few days.
I just found out that due to an error called " Data type mismatch in critearia expression' my data cannot be submitted. Do you know how to solve this problem ?

jolicious
07-08-2008, 03:00 AM
I solved the problem with data type mismatch in criteria expression. But a new problem has occurred. All the data becomes undefined and I get black data inserted into my database. After reading about, could it be due to register_globals being turned off or the maximum length of post data being excceded ? It seems that register_globals will be removed from php 6 and that its dangerous to have it turned on unless I know what I'm doing so is there any way around it if it must be turned on ? I've tried turning on register_globals and it manage to insert the name and admin number however after the that, everything is blank.

fileserverdirect
07-12-2008, 09:30 PM
I cannot help you If I don't see your code. There could be a very very small error in your code knowing you ;). Just post it up here and I will see what I can do... :)

jolicious
07-14-2008, 01:06 AM
Thanks for the reply. I've touched up on my codes and its working fine for now with globals turned on. Do you mind helping check the codes for any errors ? Also can you give some suggestions on how to improve on the registration form ? I'll post them here. Thanks.
Code for the form:


<?php
session_start()
?>
<?php
error_reporting(E_ALL ^ E_NOTICE);
?>
<?php

function checkphone() {
global $tel;
$phone = $_POST['hometel'];
if (!preg_match('/^[0-9]{8}$/', $phone)) {
$tel = '<font color="red"><b>Your telephone number is invalad</b></font>';
$GLOBALS['tel'] = $tel; }
else{
$GLOBALS['showtel'] = "true";
}
}


function checkemail() {
global $mail;
$email = $_POST['email'];
if (!preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9\.\\+=_-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/', $email)) {
$mail = '<font color="red"><b>Your Email is invalid</b></font>';

$GLOBALS['mail'] = $mail; }
else
{
$GLOBALS['showmail'] = "true";
}
}

if($_POST['submit'])
{
checkphone();
checkemail();
}
if(!$showtel||!$showmail){
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>FYP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p align="center">Name:
<input type="text" name="username" />
</p>
<p align="center">Admin No.:

<input type="text" name="admin" />
</p>
<p align="center">Gender:
<select name="gender">
<option value="Male" selected>Male</option>
<option value="Female">Female</option>
</select>
</p>
<p align="center">Address:
<textarea name="address" cols="40"></textarea />
</p>
<p align="center">Home Phone:
<input type="text" name="hometel" /> <br>
<?php echo $tel; ?>
</p>
<p align="center">Mobile Phone:
<input type="text" name="hp" />
</p>
<p align="center">Contact Email:
<input type="text" name="email" /> <br>
<?php echo $mail; ?>
</p>
<p align="center">Course:
<select name="course">
<option value="ECC">ECC</option>
</select>
</p>
<p align="center">Acad Year:
<input type="text" name="year" />
</p>
<p align="center">Path:
<select name="path">
<option value="1">B1</option>
<option value="2">B2</option>
<option value="3">B3</option>
</select>
</p>
<p align="center">Project Title:
<textarea name="title" cols="40"></textarea>
</p>
<p align="center">Project Supervisor:
<select name="supervisor">
<option value="Mr. Stephen Liew K C" selected>Mr. Stephen Liew K C</option>
<option value="Mr. Steven Ng">Mr. Steven Ng</option>
</select>
</p>
<p align="center">
<input name="submit" type="submit" />
</p>

</form>

<?php
} else {
?>
<form action="wow.php" method="post">
<?php

echo'<div align="center">';
echo '<p>Name: '.$_POST["username"].' <br />';
echo 'Admin No.: '.$_POST["admin"].' <br />';
echo 'Gender: '.$_POST["gender"].' <br />';
echo 'Address: '.$_POST["address"].' <br />';
echo 'Home Phone: '.$_POST["hometel"].' <br />';
echo 'Handphone: '.$_POST["hp"].' <br />';
echo 'Contact Email: '.$_POST["email"].' <br />';
echo 'Course: '.$_POST["course"].' <br />';
echo 'Acad Year: '.$_POST["year"].' <br />';
echo 'Path: '.$_POST["path"].' <br />';
echo 'Project title:'.$_POST["title"].' <br />';
echo 'Project Supervisor: '.$_POST["supervisor"].' <br />';


$_SESSION['username'] = $_POST["username"];
$_SESSION['admin'] = $_POST["admin"];
$_SESSION['gender'] = $_POST["gender"];
$_SESSION['address'] = $_POST["address"];
$_SESSION['hometel'] = $_POST["hometel"];
$_SESSION['hp'] = $_POST["hp"];
$_SESSION['email'] = $_POST["email"];
$_SESSION['course'] = $_POST["course"];
$_SESSION['year'] = $_POST["year"];
$_SESSION['path'] = $_POST["path"];
$_SESSION['title'] = $_POST["title"];
$_SESSION['supervisor'] = $_POST["supervisor"];
?>
<p>
<input type="submit" name="Submit" value="Submit">
</form>
</p>
<p>
<input name="button" type=button onClick=window.history.back() value=Back back>
</p>
</div>

<?php }?>

</body>
</html>

Code for the Data submittion:



<?php
session_start()
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$_SESSION['username'] = $username;
$_SESSION['admin'] = $admin;
$_SESSION['gender'] = $gender;
$_SESSION['address'] = $address;
$_SESSION['hometel'] = $hometel;
$_SESSION['hp'] = $hp;
$_SESSION['email'] = $email;
$_SESSION['course'] = $course;
$_SESSION['year'] = $year;
$_SESSION['path'] = $path;
$_SESSION['title'] = $title;
$_SESSION['supervisor'] = $supervisor;

echo "Data has been submitted";

function Enter_New_Entry($username,$admin,$gender,$address,$hometel,$hp,$email,$course,$year,$path,$title,$supervisor) {


if(!$cnx = odbc_connect( 'FYP' , 'root', '' ))die("error with connection");
$SQL_Exec_String = "Insert Into rank (username,admin,gender,address,hometel,hp,email,course,year,path,title,supervisor)
Values ('$username','$admin','$gender','$address','$hometel','$hp','$email','$course','$year','$path','$title','$supervisor')";

$cur= odbc_exec( $cnx, $SQL_Exec_String );
if (!$cur) {
Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
}

odbc_close( $cnx);
}
Enter_New_Entry($username,$admin,$gender,$address,$hometel,$hp,$email,$course,$year,$path,$title,$supervisor);
?>

</body>
</html>

jolicious
07-14-2008, 03:52 AM
Edit: Sorry about this, but I've just got a very big suprise from my supervisor. It seems that the "project" he gave me was like a warm up. This morning he told to discard everything and install MySQL, joomla! and start from scratch. Sorry to bother everyone with this.

fileserverdirect
07-15-2008, 12:49 AM
.....