Jump to content

Centering forms on page


ValdouaD

Recommended Posts

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.



[code] <?
// 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>";
?>[/code]


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:

[code]
<?
// 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";
}
[/code]

Is there an easy way to do this?
Link to comment
https://forums.phpfreaks.com/topic/11503-centering-forms-on-page/
Share on other sites

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 [code]<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>
[/code]{
<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=[b][!--coloro:red--][span style=\"color:red\"][!--/coloro--]\[!--colorc--][/span][!--/colorc--][/b]"margin-left: 200[b][!--coloro:red--][span style=\"color:red\"][!--/coloro--]\[!--colorc--][/span][!--/colorc--][/b]">Search by Zip:
<input type=\"text\" name=\"zipCode\" size=[b][!--coloro:red--][span style=\"color:red\"][!--/coloro--]\[!--colorc--][/span][!--/colorc--][/b]"20[b][!--coloro:red--][span style=\"color:red\"][!--/coloro--]\[!--colorc--][/span][!--/colorc--][/b]"> (example: 01922)
<br>
Search by State: <input type=\"text\" name=\"state\" size=[b][!--coloro:red--][span style=\"color:red\"][!--/coloro--]\[!--colorc--][/span][!--/colorc--][/b]"20[b][!--coloro:red--][span style=\"color:red\"][!--/coloro--]\[!--colorc--][/span][!--/colorc--][/b]">
<input type=\"submit\" size="20"> (example: NY for New York)
<br>
</p>
</form></div>";
?></td>
</tr>
</table>
</center>
</div>

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:
[code]<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>[/code]

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.