MySQL Forums
Forum List  »  PHP

i need some help with php + html forms...
Posted by: Rashid Nash
Date: April 20, 2006 02:52PM

hey
i just started learning mysql and php last wed.
and i just built my 1st project
its all good till i got stuck and now need some help

here's some code that i hope will explain....
i have 4 php files
2 normal php files
and 2 files that have the code to display the forms and page

its a 2 page website (main page and service page)


***********1st file (main_page_forms.php)**********

.....

function m_p((&$PHP_SELF, $First_name, $Last_name, $Address, $Post_code ...){

here i have a couple of these
<input type="text" name="First_name" size="27" value = "<? echo $First_name;?>"></td>
and 4 buttons
like this

<form name ="otherbuttons" action="<?php echo ($PHP_SELF)?>"METHOD=POST>
<input name="Service_details" type="submit" style="color: #FF0000" value="Service Details"></td>
<td width="70" height="27">
<input type="submit" value="Save" name="save"></td>
<td width="314" height="27">
<input type="submit" value="Search" name="search">
<input name="clear" type="reset" onClick="MM_goToURL('parent','testing5.php');return document.MM_returnValue" value="Clear"></td>
}



*******2nd file is the main page itslef (main_page.php)**********

include("main_page_forms.php");
include("dbinfo.inc.php");
.....

if($_GET['Cust_id']){// this will display the search results

$Cust_idd= $_GET['Cust_id'];
mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die( "Unable to select database");

$sql = ("SELECT `Cust_id` , `First_name` , `Last_name` , `Address` , `Post_code` , `Phone_number` , `Mobile_number` , `Number_plate` , `Car` , `Model` , `Year` , `Mot_exp`
FROM `customer`
WHERE 1 AND `Cust_id` = '$Cust_idd' ");

$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$Cust_id = $myrow[Cust_id];
$First_name = $myrow[First_name];
$Last_name = $myrow[Last_name];
$Address = $myrow[Address];
$Post_code = $myrow[Post_code];
$Phone_number = $myrow[Phone_number];
$Mobile_number = $myrow[Mobile_number];
$Number_plate = $myrow[Number_plate];
$Car = $myrow[Car];
$Model = $myrow[Model];
$Year = $myrow[Year];
$Mot_exp = $myrow[Mot_exp];

$_SESSION['Cust_id'] = $Cust_id;
$temp = main_page_wv(&$PHP_SELF , $First_name , $Last_name , $Address , $Post_code , $Phone_number , $Mobile_number , $Number_plate , $Car , $Model , $Year , $Mot_exp);
$result2 = mysql_query("SELECT `Cust_id` , `History_id` , `Serv_date` , `Short_desc` , `Mot` , `Serv_details` , `Part_charge` , `Labor` , `Mot_charge`
FROM `service`
WHERE 1 AND `Cust_id` = '$Cust_id'");
$howmanyrows2=mysql_num_rows($result2);
$myrow2 = mysql_fetch_array($result2);


do { //print the history for the current user

echo "<a href=\"".$PHP_SELF."?History_id=".$myrow2["History_id"]."\">".$myrow2["Serv_date"]." - ".$myrow2['Short_desc']."</a><br>";
echo "<br />\n";

} while ($myrow2 = mysql_fetch_array($result2));

}else if($_POST[search]){ //if clicked on the search button

extract($_POST);
mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die( "Unable to select database");


$result = mysql_query(" SELECT `Cust_id` , `First_name` , `Last_name` , `Address` , `Post_code` , `Phone_number` , `Mobile_number` , `Number_plate` , `Car` , `Model` , `Year` , `Mot_exp`
FROM `customer`
WHERE 1 AND `First_name`
LIKE '$First_name' OR `Last_name`
LIKE '$Last_name' OR `Post_code`
LIKE '$Post_code' OR `Number_plate`
LIKE '$Number_plate'");

$howmanyrows =mysql_num_rows($result);

if ($howmanyrows == 1){

$myrow = mysql_fetch_array($result);
do {
$Cust_id = $myrow[Cust_id];
$First_name = $myrow[First_name];
$Last_name = $myrow[Last_name];
$Address = $myrow[Address];
$Post_code = $myrow[Post_code];
$Phone_number = $myrow[Phone_number];
$Mobile_number = $myrow[Mobile_number];
$Number_plate = $myrow[Number_plate];
$Car = $myrow[Car];
$Model = $myrow[Model];
$Year = $myrow[Year];
$Mot_exp = $myrow[Mot_exp];
main_page_wv(&$PHP_SELF , $First_name , $Last_name , $Address , $Post_code , $Phone_number , $Mobile_number , $Number_plate , $Car , $Model , $Year , $Mot_exp);

$result2 = mysql_query("SELECT `Cust_id` , `History_id` , `Serv_date` , `Short_desc` , `Mot` , `Serv_details` , `Part_charge` , `Labor` , `Mot_charge`
FROM `service`
WHERE 1 AND `Cust_id` = '$Cust_id'");
$howmanyrows2=mysql_num_rows($result2);
$myrow2 = mysql_fetch_array($result2);


do { //print the history for the current user

echo "<a href=\"".$PHP_SELF."?History_id=".$myrow2["History_id"]."\">".$myrow2["Serv_date"]." - ".$myrow2['Short_desc']."</a><br>";
echo "<br />\n";

} while ($myrow2 = mysql_fetch_array($result2));


} while ($myrow = mysql_fetch_array($result));
$_SESSION['Cust_id'] = $Cust_id;


}else if (($myrow = mysql_fetch_array($result))and ($howmanyrows >1)) {


main_page_wv(&$PHP_SELF , $First_name , $Last_name , $Address , $Post_code , $Phone_number , $Mobile_number , $Number_plate , $Car , $Model , $Year , $Mot_exp);

echo "Search Results :<br /><br /> ";

do {

echo "<a href=\"".$PHP_SELF."?Cust_id=".$myrow["Cust_id"]."\">".$myrow["First_name"]." ".$myrow['Last_name']." "." - ".$myrow['Address']." - ".$myrow['Post_code']." - ".$myrow['Car']." - ".$myrow['Model']."</a><br>";
echo "<br />\n";

} while ($myrow = mysql_fetch_array($result));



}else{ //nothing found

main_page_wv(&$PHP_SELF , $First_name , $Last_name , $Address , $Post_code , $Phone_number , $Mobile_number , $Number_plate , $Car , $Model , $Year , $Mot_exp);

echo "Sorry but nothing is found!";


}
}else if($_POST[Service_details]){

and here a couple of validation things to make sure all items have been entered
and the last one i want it to load (service_details.php) !!
i can't find a function to do that!
}}






******3rd file is the service page forms(service_page_forms.php)******

function service_page(&$PHP_SELF , $Serv_date,$Short_desc,.....)

and a few inputs like
<td width="283" colspan="2"><input type="text" name="Serv_date" size="20"value = <? echo $Serv_date;?>></td>

and forms...
<form action="<?php echo ($PHP_SELF)?>"METHOD=POST>
<input type="submit" name="Save" value="Save">
<input name="p_invoice" type="submit" onClick="MM_callJS('javascript:print()')" value="Print Invoice">
<input name="clear2" type="reset" onClick="MM_goToURL('parent','servicedetails2222.php');return document.MM_returnValue" value="Clear"></td>
<td height="50" width="134">
<input name="mainpage" type="submit" onClick="MM_goToURL('parent','testing5.php');return document.MM_returnValue" value="Main Page"></td>
}



**************4th file is the Service page itself(service_page.php)***************

include ("service_page_forms.php");

deals with the service page buttons...





in the 2nd file as you can see if i click on the search button and 2 items are found then i display the results as a link to the main page with ?custid=id! and i got another if statement at the top to load the page to load the main page using the custid! once the page is loaded tho non of the button work!!(except the clear!!)
and this is the problem i have!

i hope this makes sense!!

and thanks in advance for any help

Options: ReplyQuote


Subject
Written By
Posted
i need some help with php + html forms...
April 20, 2006 02:52PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.