Need help with textbox stuff

Discussion in 'PHP' started by Felverick, Apr 4, 2007.

  1. #1
    for some reason when i try to print the query results to a textbox it shows only the first part. it should print 123 main street and it only prints 123. i've included a screenshot and all my code. what is being echo'd is what should print in the textbox. I tried putting quotes around the variables. thanks alot!!
    <?php
    require_once ("asst3include.php");
    
    function SaveUserNameAndPassword($UserName,$Password)
    {
     echo "<input type=hidden name=\"f_UserName\" value=\"$UserName\">";
     echo "<input type=hidden name=\"f_Password\" value=\"$Password\">";
    }
    
    function GetUserNameAndPassword(&$UserName,&$Password)
    {
    $UserName=$_POST["f_UserName"];
    $Password=$_POST["f_Password"];
    }
    
    function OpenConnection($UserName,$Password)
    {
     $Host="spider.sl.on.ca";
     $DatabaseName=$UserName;
     $Connect=mysql_connect ($Host,$UserName,$Password);
    if ($Connect==false)
     {
      die('Could not connect: ' . mysql_error());
     }
      $DBName=mysql_select_db($DatabaseName);
    if ($DBName==false)
    {
      die('Could not select database: ' . mysql_error());
    } 
    }
    
    function CloseConnection()
    {
    $Close=mysql_close();
    if($Close==false) echo "problem";
    }
    function ExecuteLeftJoin()
    {  
    $Query="Select * From agent left join Listings on agent.AgentIDNum=Listings.AgentIDNum order by agent.AgentName";
    $QueryData=mysql_query ($Query);
    if ($QueryData==false) echo "didn't work"; 
    return $QueryData;
     
    }
    
    function DisplayAddRecord()
    {
    GetUserNameAndPassword(&$UserName,&$Password);
     echo "<form action=\"asst3main.php?\" method=\"post\">\n";
     WriteHeaders("Add New Record");
      DisplayPrompt("Agent Name");
      DisplayTextbox("f_AgentName",8,null,"T");
       
      DisplayPrompt("Comission Percent");
      DisplayTextbox("f_Comission",8,null,"T");
      
      DisplayPrompt("Address");
      DisplayTextbox("f_Address",8,null,"T");
      
      DisplayPrompt("Asking Price");
      DisplayTextbox("f_Price",8,null,"T");
      //probably wrong
      DisplayPrompt("Notes");
      DisplayTextbox("f_Notes",8,null,"T");
      //end wrong
       DisplayHR("L"); 
       DisplayButton("Submit","f_Save","Display All Data");
    SaveUserNameAndPassword($UserName,$Password);
      echo "</form>";
      WriteFooters();
    }
    
    
    
    function WriteNewRecordToTable()
    {
    GetUserNameAndPassword($UserName,$Password);
    OpenConnection($UserName,$Password);
    $Query="Select * from agent order by AgentIDNum DESC";
    $QueryData=mysql_query ($Query);
    if ($QueryData==false)
    {
    echo "Problem";
    }
    while ($row=mysql_fetch_array($QueryData))
    {
    $ctr+=1;
    }
    $ctr+=1;
    $Query2="insert into agent values ($ctr,\"$_POST[f_AgentName]\",$_POST[f_Comission])";
    $Query3="insert into listings values ($ctr,\"$_POST[f_Address]\",$_POST[f_Price],\"$_POST[f_Notes]\")"; 
    $QueryData2=mysql_query ($Query2);
    if ($QueryData2==false) echo "Problem";
    else echo "wrote to agent table";
    $QueryData3=mysql_query ($Query3);
    if ($QueryData3==false) echo "not issued";
    }
    
    function DisplayAllData()
    {
    WriteHeaders("Display Data Form");
    GetUserNameAndPassword($UserName,$Password);
    OpenConnection($UserName,$Password);
    echo "<table border=\"2\">";
    echo "<tr><th>AgentIDNum</th>";
    echo "<th>AgentName</th>";
    echo "<th>ComissionPercent</th>";
    echo "<th>Address</th>";
    echo "<th>AskingPrice</th>";
    echo "<th>Notes</th></tr>";
    $QueryData=ExecuteLeftJoin();
    while($row=mysql_fetch_array($QueryData))
    {
    echo "<tr><td>$row[AgentIDNum]</td>";
    echo "<td>$row[AgentName]</td>";
    echo "<td>$row[CommissionPercent]</td>";
    echo "<td>$row[Address]</td>";
    echo "<td>$row[AskingPrice]</td>";
    echo "<td>$row[Notes]</td></tr>";
    
    
    }
    DisplayHR("L");  
    WriteFooters();
    }
    
    function DisplayRetrieveRecord()
    {
    WriteHeaders("Retrieve Record Form");
    echo "<form action=\"asst3main.php?\" method=\"post\">\n";
    GetUserNameAndPassword($UserName,$Password);
    DisplayPrompt("Name");
      DisplayTextbox("f_PersonName",8,null,"T");
    DisplayPrompt("Address");
      DisplayTextbox("f_PersonAddress",8,null,"T");
      DisplayButton("Submit","f_find","Submit");
     SaveUserNameAndPassword($UserName,$Password);
      echo "</form>"; 
    WriteFooters();
    }
    
    function ShowFoundRecord()
    {
    WriteHeaders("Display New Record");
    GetUserNameAndPassword($UserName,$Password);
    OpenConnection($UserName,$Password);
    $Query="Select * From agent left join Listings on agent.AgentIDNum=Listings.AgentIDNum where agent.AgentName=\"$_POST[f_PersonName]\" order by agent.AgentName"; 
    $QueryData2=mysql_query ($Query);
    while ($QueryData2==false) echo "Not Found";
    $row=mysql_fetch_array($QueryData2);
    echo "$row[AgentIDNum]<br>\n";
    echo "$row[Address]<br>\n"; 
     DisplayPrompt("Agent Name");
      DisplayTextbox("f_AgentName",8,$row[AgentName],"T");
       
      DisplayPrompt("Comission Percent");
      DisplayTextbox("f_Comission",8,$row[CommissionPercent],"T");
      
      DisplayPrompt("Address");
      DisplayTextbox("f_Address",25,"$row[Address]","T");
      
      DisplayPrompt("Asking Price");
      DisplayTextbox("f_Price",8,$row[AskingPrice],"T");
      //probably wrong
      DisplayPrompt("Notes");
      DisplayTextbox("f_Notes",8,$row[Notes],"T");
    }
    
    function WriteFoundRecordDataToDisk()
    {
    
    }
    
    function AuthenticateForm()
    {
      WriteHeaders("Title of Record");
      echo "<form action=\"asst3main.php?\" method=\"post\">\n";
      echo "<h3>Please login to the admin account </h3>";
      DisplayPrompt("Username");
      DisplayTextbox("f_UserName",12,"MyUserName");
      DisplayPrompt("Password");
     
      echo "<input type=password name=\"f_Password\"size=12 value=\"MyPassword\"><br/><br/>";
      DisplayButton("Submit","f_Submit","Connect");
      
      DisplayHR("L");  
    echo "<input type=hidden name=\"f_MainMenu\" value=\"DisplayAddRecord\"><br/><br/>";
      echo "</form>";
      WriteFooters();
    }
    
    function MainMenuForm()
    {
    echo "<form action=\"asst3main.php?\" method=\"post\">\n";
    WriteHeaders("Title of Main Menu");
     GetUserNameAndPassword($UserName,$Password);
     OpenConnection($UserName,$Password);
    DisplayHR("L");  
    if (isset($_POST["f_Add"])) DisplayAddRecord(); 
    DisplayButton("Submit","f_Add","Add a Record");
    DisplayButton("Submit","f_Retrieve","Retrieve a Record");
    DisplayButton("Submit","f_Display","Display All Data");
     SaveUserNameAndPassword($UserName,$Password);
     CloseConnection();
     WriteFooters();
     echo "<input type=hidden name=\"f_nextform\" value=\"DisplayAddRecord\"><br/><br/>";
     echo "</form>";
    }
    if (isset($_POST["f_MainMenu"])) MainMenuForm();
    elseif (isset($_POST["f_Add"])) DisplayAddRecord();
    elseif (isset($_POST["f_Retrieve"])) DisplayRetrieveRecord();
    elseif (isset($_POST["f_Display"]))  DisplayAllData();
    elseif (isset($_POST["f_Save"])) WriteNewRecordToTable();
    elseif (isset($_POST["f_find"])) ShowFoundRecord(); 
    else
    AuthenticateForm();
    ?>
    Code (markup):

    INCLUDE FILE


    <?php
    function DisplayButton($Type,$Name,$Text)
    {
    echo "<input type=\"$Type\" name= \"$Name\" value= \"$Text\">";
    }
    
    function WriteHeaders($TitleBar,$Heading="Brian Northmore")
     {
      echo "<html>";
      echo "<title>$TitleBar</title>";
      echo "<h1>$Heading</h1>";
      echo "<body>";
     }
    
    function WriteFooters()
     {
      DisplayContactInfo("bnorthmore@cogeco.ca");
      echo "</body>";
      echo "</html>";
     }
    
    function DisplayPrompt($FormLabel)
    {
    echo $FormLabel;
    }
    
    function DisplayTextbox($Name,$Size,$Value=null,$IncludeBreaks='N')
    {
    
    if ($IncludeBreaks=='N')
    $Break="";
    elseif ($IncludeBreaks=='T')
    $Break="<br>";
    else
    $Break="<br>";
    echo "<Input type = text name = $Name Size = $Size Maxlength = \"25\" Value = $Value>$Break";
    
    }
    
    function DisplayHR($Align)
    {
    echo "<hr/ width=\"50%\" align=$Align color=\"black\">";
    }
    
    function DisplayContactInfo($Email)
    {
    echo "Questions? Comments? Concerns? Email me ";
    echo "<A HREF=\"mailto:$Email\">Brian</A>";
    }
    ?>
    Code (markup):

     

    Attached Files:

    Felverick, Apr 4, 2007 IP
  2. Felverick

    Felverick Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    svoled my own problem, was missing quotes in my include file. doh!
     
    Felverick, Apr 4, 2007 IP