Jump to content


Photo

Centering forms on page


  • Please log in to reply
9 replies to this topic

#1 ValdouaD

ValdouaD
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 08 June 2006 - 05:08 PM

I have a store locatior on my website. I want to have it all centered on the page buit I cant figure out how.
Below is my input area where the customer would either put in theor zip code or state.



<?
// Page 1, the form
echo "<div style=\"margin-left: 15pt;\"><form name=\"search\" action=\"spage2.php\" method=\"post\">
Search by Zip: <input type=\"text\" name=\"zipCode\"> (example: 01922)
<br>
Search by State: <input type=\"text\" name=\"state\"> <input type=\"submit\"> (example: NY for New York)
<br>
</form></div>";
?>


Here is the results area...which is on a differnt page. Here I have the same problem everything is flsuh left and I want it to be centered on the page like it was in its own table. Code is below:

<?
// Page two, search and display

$connect = mysql_connect("localhost", "XXXXX", "XXXXX");
$db = mysql_select_db("schylling_storelist", $connect);
$sql = "SELECT *
FROM STOREDATA
WHERE State = '".$_POST['state']."'
OR ZIP_Code = '".$_POST['zipCode']."'";
$result = mysql_query($sql);
$rows = mysql_num_rows($result);
if($rows > 0) {
echo "<table border=\"1\">
<th align=\"center\newstyle\">Name</th>
<th align=\"center\">City</th>
<th align=\"center\">State</th>
<th align=\"center\">Sales Phone</th>";

while($row=mysql_fetch_array($result)) {
echo "<tr>
<td align=\"center\" class=\"newstyle\">".$row['Name']."</td>
<td align=\"center\" class=\"newstyle\">".$row['City']."</td>
<td align=\"center\" class=\"newstyle\">".$row['State']."</td>
<td align=\"center\" class=\"newstyle\">".$row['Sales_Phone']."</td>
</tr>";
}
}
else {
echo "No results found";
} 

Is there an easy way to do this?

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 08 June 2006 - 05:22 PM

Firstly... multiposting is a big no no. Secondly, your question has nothing to do with php. Its a html problem.

[a href=\"http://www.w3schools.com\" target=\"_blank\"]Here[/a] is a nice html tutorial.

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 08 June 2006 - 05:31 PM

Actually, it can be done quite easily using CSS. It has nothing to do with PHP.

Ken

#4 ValdouaD

ValdouaD
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 08 June 2006 - 06:09 PM

Sorry about the double posting....my bad!

I was under the assumtion that if I used an html table and put all thatcode in the table it wouldnt work.
I have tried this and have gotten a lot of parser errors which I assumed was from the PHP code?



#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 08 June 2006 - 06:19 PM

i see no immediate parse errors in that block of code you provided (although, i wouldn't really recommend the style you used for echoing..it's technically correct). can you post the actual error and line number, and the code around the line number?
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 ValdouaD

ValdouaD
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 08 June 2006 - 06:33 PM

Here is the error I get when I place this into a table:

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /var/www/html/store_finder.php on line 247


Here is the code view
<div align="center">
  <center>
  <table border="1" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
    <tr>
      <td width="100%"><?
// Page 1, the form
echo "<div style=\"margin-left: 15pt;\"><form name=\"search\" action=\"spage2.php\" method=\"post\">
<p style="margin-left: 200">Search by Zip: 
<input type=\"text\" name=\"zipCode\" size="20"> (example: 01922)
<br>
Search by State: <input type=\"text\" name=\"state\" size="20"> 
<input type=\"submit\" size="20"> (example: NY for New York)
<br>
</p>
</form></div>";
?></td>
    </tr>
  </table>
  </center>
</div>
{

#7 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 08 June 2006 - 06:38 PM

<div align="center">
<center>
<table border="1" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
<tr>
<td width="100%"><?
// Page 1, the form
echo "<div style=\"margin-left: 15pt;\"><form name=\"search\" action=\"spage2.php\" method=\"post\">
<p style=[!--coloro:red--][span style=\"color:red\"][!--/coloro--]\[!--colorc--][/span][!--/colorc--]"margin-left: 200[!--coloro:red--][span style=\"color:red\"][!--/coloro--]\[!--colorc--][/span][!--/colorc--]">Search by Zip:
<input type=\"text\" name=\"zipCode\" size=[!--coloro:red--][span style=\"color:red\"][!--/coloro--]\[!--colorc--][/span][!--/colorc--]"20[!--coloro:red--][span style=\"color:red\"][!--/coloro--]\[!--colorc--][/span][!--/colorc--]"> (example: 01922)
<br>
Search by State: <input type=\"text\" name=\"state\" size=[!--coloro:red--][span style=\"color:red\"][!--/coloro--]\[!--colorc--][/span][!--/colorc--]"20[!--coloro:red--][span style=\"color:red\"][!--/coloro--]\[!--colorc--][/span][!--/colorc--]">
<input type=\"submit\" size="20"> (example: NY for New York)
<br>
</p>
</form></div>";
?></td>
</tr>
</table>
</center>
</div>


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#8 ValdouaD

ValdouaD
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 08 June 2006 - 06:43 PM

Now I have this error:

Parse error: parse error, unexpected T_LNUMBER, expecting ',' or ';' in /var/www/html/store_finder.php on line 252

#9 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 08 June 2006 - 06:59 PM

Why are you using PHP to echo that part of the table? It's all HTML. I don't see any PHP variables in that string at all.

Try:
<div align="center">
<center>
<table border="1" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
<tr>
<td width="100%">
<div style="margin-left: 15pt;"><form name="search" action="spage2.php" method="post">
<p style="margin-left: 200">Search by Zip:
<input type="text" name="zipCode" size="20"> (example: 01922)
<br>
Search by State: <input type="text" name="state" size="20">
<input type="submit" size="20"> (example: NY for New York)
<br>
</p>
</form></div>
</td>
</tr>
</table>
</center>
</div>

Ken

#10 ValdouaD

ValdouaD
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 08 June 2006 - 07:10 PM

Somebody wrote this code for me like 3 years ago and I have nver chagned it.
PHP is not my strong suit as you can see.

But thank to all of you I am happy with the way it works now.

Thanks so much! You guys and gals are great!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users