Jump to content

Archived

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

ValdouaD

Centering forms on page

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Actually, it can be done quite easily using CSS. It has nothing to do with PHP.

Ken

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
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]{

Share this post


Link to post
Share on other sites
<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>

Share this post


Link to post
Share on other sites
Now I have this error:

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

×

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.