PHP/MySQL Programming

driveflexfuel

New Member
Messages
159
Reaction score
0
Points
0
I am offering 3000 credits for someone to create the following 5 forms/pages for me.

2 database Search pages

1 one with radio buttons labeled business and phone number the customer can click on which one they want to search by. default is phone

2 Search by state i have an image map where they can click on the state and it needs to display all resutls for that state on another page. Image map adds the variable page.php?state=california if you click california

1 form to Submit new business to database
after submission it has to display the information added on a new page and include the variable $comment_id="business" for a code that i will be adding

Form needs to have the following inputs
Business
Owner_name
phone
Address
City
State
Zipcode

I have not yet created the database but it will have
Database information

Business
Owner_Name
phone
Address
City
State
ZipCode


If you have any questions please feel free to ask here or message me on windows messenger email is liffesucks@hotmail.com
 
Last edited:

freecrm

New Member
Messages
629
Reaction score
0
Points
0
Made a start on the first one, but I need (or someone needs) to set the column variable depending on the radio buttons.... just ran out of time.

PHP:
<?php
mysql_connect($hostname, $username, $password);

$searchvar = "-1";
if (isset($_POST['searchfield'])) {
  $searchvar = (get_magic_quotes_gpc()) ? $_POST['searchfield'] : addslashes($_POST['searchfield']);
}

$selectcolumnvar = "PHONE";
if (isset($selectcolumn)) {
  $selectcolumnvar = (get_magic_quotes_gpc()) ? $selectcolumn : addslashes($selectcolumn);
}

mysql_select_db($database);
$query_SearchResults = sprintf("SELECT * FROM TABLE WHERE %s LIKE '%%%s%%' ORDER BY COMPANY ASC", $selectcolumnvar,$searchvar);
$SearchResults = mysql_query($query_SearchResults) or die(mysql_error());
$row_SearchResults = mysql_fetch_assoc($SearchResults);
$totalRows_SearchResults = mysql_num_rows($SearchResults);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="">
<p> Search for</p>
<p><input name="searchfield" type="text" id="searchfield"></p>
<p>in</p>
<p>
<label><input type="radio" name="RadioGroup1" value="Y">Business</label>
<br>
<label><input name="RadioGroup1" type="radio" value="phone number" checked>Phone Number</label>
</p>
<p>
<input type="submit" name="Submit" value="Search">
<br>
</p>
</form>
<p>&nbsp;</p>

<table>
  <tr>
    <td>BUSINESS</td>
    <td>OWNERNAME</td>
    <td>PHONE</td>
    <td>ADDRESS</td>
    <td>CITY</td>
    <td>STATE</td>
    <td>ZIPCODE</td>
  </tr>
  <?php do { ?>
  <tr>
    <td><?php echo $row_SearchResults['BUSINESS']; ?></td>
    <td><?php echo $row_SearchResults['OWNERNAME']; ?></td>
    <td><?php echo $row_SearchResults['PHONE']; ?></td>
    <td><?php echo $row_SearchResults['ADDRESS']; ?></td>
    <td><?php echo $row_SearchResults['CITY']; ?></td>
    <td><?php echo $row_SearchResults['STATE']; ?></td>
    <td><?php echo $row_SearchResults['ZIPCODE']; ?></td>
  </tr>
  <?php } while ($row_SearchResults = mysql_fetch_assoc($SearchResults)); ?>
</table>
</body>
</html>
 

VPmase

New Member
Messages
914
Reaction score
0
Points
0
Made a start on the first one, but I need (or someone needs) to set the column variable depending on the radio buttons.... just ran out of time.

PHP:
<?php
mysql_connect($hostname, $username, $password);

$searchvar = "-1";
if (isset($_POST['searchfield'])) {
  $searchvar = (get_magic_quotes_gpc()) ? $_POST['searchfield'] : addslashes($_POST['searchfield']);
}

$selectcolumnvar = "PHONE";
if (isset($selectcolumn)) {
  $selectcolumnvar = (get_magic_quotes_gpc()) ? $selectcolumn : addslashes($selectcolumn);
}

mysql_select_db($database);
$query_SearchResults = sprintf("SELECT * FROM TABLE WHERE %s LIKE '%%%s%%' ORDER BY COMPANY ASC", $selectcolumnvar,$searchvar);
$SearchResults = mysql_query($query_SearchResults) or die(mysql_error());
$row_SearchResults = mysql_fetch_assoc($SearchResults);
$totalRows_SearchResults = mysql_num_rows($SearchResults);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="">
<p> Search for</p>
<p><input name="searchfield" type="text" id="searchfield"></p>
<p>in</p>
<p>
<label><input type="radio" name="RadioGroup1" value="Y">Business</label>
<br>
<label><input name="RadioGroup1" type="radio" value="phone number" checked>Phone Number</label>
</p>
<p>
<input type="submit" name="Submit" value="Search">
<br>
</p>
</form>
<p>&nbsp;</p>

<table>
  <tr>
    <td>BUSINESS</td>
    <td>OWNERNAME</td>
    <td>PHONE</td>
    <td>ADDRESS</td>
    <td>CITY</td>
    <td>STATE</td>
    <td>ZIPCODE</td>
  </tr>
  <?php do { ?>
  <tr>
    <td><?php echo $row_SearchResults['BUSINESS']; ?></td>
    <td><?php echo $row_SearchResults['OWNERNAME']; ?></td>
    <td><?php echo $row_SearchResults['PHONE']; ?></td>
    <td><?php echo $row_SearchResults['ADDRESS']; ?></td>
    <td><?php echo $row_SearchResults['CITY']; ?></td>
    <td><?php echo $row_SearchResults['STATE']; ?></td>
    <td><?php echo $row_SearchResults['ZIPCODE']; ?></td>
  </tr>
  <?php } while ($row_SearchResults = mysql_fetch_assoc($SearchResults)); ?>
</table>
</body>
</html>

For that code to work you have to have PHP Level 2 or higher so make sure you have it and if not go to your account and request it.

I think this belongs in the marketplace...
It doesn't matter, its a programming question so its fine here or in the Marketplace.
 

driveflexfuel

New Member
Messages
159
Reaction score
0
Points
0
I have managed to create the search by state and the form to add to the database from a source I found on another forums but I still need the search form. I thank you for working on the code above and you will get credits for you hard work when this code is completed.

This is the code i am using if someone can tell me where i am going wrong it would be great. The form pops up with no errors but when I search it does not do anything you can view a sample page at www.djcustomdesign.com/database/search.php

Code:
<?php
        $db_server = "localhost";
        $database = "driveflexfuel_business";
        $db_user = "******";
        $db_pass = "******";
mysql_connect($db_server, $db_user, $db_pass);

$searchvar = "-1";
if (isset($_POST['searchfield'])) {
  $searchvar = (get_magic_quotes_gpc()) ? $_POST['searchfield'] : addslashes($_POST['searchfield']);
}

$selectcolumnvar = "PHONE";
if (isset($selectcolumn)) {
  $selectcolumnvar = (get_magic_quotes_gpc()) ? $selectcolumn : addslashes($selectcolumn);
}

mysql_select_db($database);
$query_SearchResults = sprintf("SELECT * FROM COMPANY WHERE %s LIKE '%%%s%%' ORDER BY BUSINESS ASC", $selectcolumnvar,$searchvar);
$SearchResults = mysql_query($query_SearchResults) or die(mysql_error());
$row_SearchResults = mysql_fetch_assoc($SearchResults);
$totalRows_SearchResults = mysql_num_rows($SearchResults);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="">
<p> Search for</p>
<p><input name="searchfield" type="text" id="searchfield"></p>
<p>in</p>
<p>
<label><input type="radio" name="RadioGroup1" value="Y">Business</label>
<br>
<label><input name="RadioGroup1" type="radio" value="phone number" checked>Phone Number</label>
</p>
<p>
<input type="submit" name="Submit" value="Search">
<br>
</p>
</form>
<p>&nbsp;</p>

<table>
  <tr>
    <td>BUSINESS</td>
    <td>OWNERNAME</td>
    <td>PHONE</td>
    <td>ADDRESS</td>
    <td>CITY</td>
    <td>STATE</td>
    <td>ZIPCODE</td>
  </tr>
  <?php do { ?>
  <tr>
    <td><?php echo $row_SearchResults['BUSINESS']; ?></td>
    <td><?php echo $row_SearchResults['OWNERNAME']; ?></td>
    <td><?php echo $row_SearchResults['PHONE']; ?></td>
    <td><?php echo $row_SearchResults['ADDRESS']; ?></td>
    <td><?php echo $row_SearchResults['CITY']; ?></td>
    <td><?php echo $row_SearchResults['STATE']; ?></td>
    <td><?php echo $row_SearchResults['ZIPCODE']; ?></td>
  </tr>
  <?php } while ($row_SearchResults = mysql_fetch_assoc($SearchResults)); ?>
</table>

The table name is company
The field names are all in lowercase and are
business
owner
address
city
state
zip
phone
 

gomarc

Member
Messages
516
Reaction score
18
Points
18
Change your table fields to uppercase:

BUSINESS
OWNERNAME
PHONE
ADDRESS
CITY
STATE
ZIPCODE


They need to match:

...

Code:
 ...
    <td><?php echo $row_SearchResults['BUSINESS']; ?></td>
    <td><?php echo $row_SearchResults['OWNERNAME']; ?></td>
    <td><?php echo $row_SearchResults['PHONE']; ?></td>
    <td><?php echo $row_SearchResults['ADDRESS']; ?></td>
    <td><?php echo $row_SearchResults['CITY']; ?></td>
    <td><?php echo $row_SearchResults['STATE']; ?></td>
    <td><?php echo $row_SearchResults['ZIPCODE']; ?></td>

...
 

driveflexfuel

New Member
Messages
159
Reaction score
0
Points
0
I want to thank all of you for your work on the coding everything is working great and credits have been handed out.
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
I want to thank all of you for your work on the coding everything is working great and credits have been handed out.

V Generous... :biggrin:

I'll see if I can get round to your others when I get a second or 3,600 of them!
 

gomarc

Member
Messages
516
Reaction score
18
Points
18
...
2 Search by state i have an image map where they can click on the state and it needs to display all resutls for that state on another page. Image map adds the variable page.php?state=california if you click california
...

If I understood correctly, you already have an image map where users can click on the state.

PHP:
<?php

/*
File name: by_state.php
Expecting something like : by_state.php?state=california
Note that 'california' is not the same as 'ca'
but california will match CaliFORnia.

Your MySql table must contain a field named STATE.

*/

if (isset($_GET['state']) ) {
    // Connect
        $db_server = "localhost";
        $database = "*******";
        $db_user = "********";
        $db_pass = "********";
       
    // Reverse magic_quotes_gpc/magic_quotes_sybase effects on those vars if ON.

        if(get_magic_quotes_gpc()) {
            $sstate = stripslashes($_GET['state']);
            
        } else {
            $sstate = $_GET['state'];

        }
        
    mysql_connect($db_server,$db_user,$db_pass);
    @mysql_select_db($database) or die( "Unable to select database");
    
    $query = sprintf("SELECT * from company WHERE `STATE` LIKE \"$sstate\" ORDER BY BUSINESS ASC");
    $result = mysql_query($query);
    $num = mysql_num_rows($result);
        
    mysql_close();
    
    if ($num < 1) {
         echo "No Business found in the State of " . $_GET['state'] . "\n";
    } else {
    // Build the table with results
?>        
    <table>
  <tr>
    <td>BUSINESS</td>
    <td>OWNERNAME</td>
    <td>PHONE</td>
    <td>ADDRESS</td>
    <td>CITY</td>
    <td>STATE</td>
    <td>ZIPCODE</td>
  </tr>
  <?php $i=0;
  while ($i < $num)  { ?> 
  <tr>
    <td><?php echo mysql_result($result, $i, 'BUSINESS');  ?></td>
    <td><?php echo mysql_result($result, $i, 'OWNERNAME'); ?></td>
    <td><?php echo mysql_result($result, $i, 'PHONE');     ?></td>
    <td><?php echo mysql_result($result, $i, 'ADDRESS');   ?></td>
    <td><?php echo mysql_result($result, $i, 'CITY');      ?></td>
    <td><?php echo mysql_result($result, $i, 'STATE');     ?></td>
    <td><?php echo mysql_result($result, $i, 'ZIPCODE');   ?></td>
  </tr>
  
  <?php 
  ++$i;
  }  ?>
</table>

<?php
    }
    }
?>
 
Last edited:

driveflexfuel

New Member
Messages
159
Reaction score
0
Points
0
Thanks for the code it works great. I now have all forms and everything is working correctly
 

gomarc

Member
Messages
516
Reaction score
18
Points
18
Thank you driveflexfuel. Added to your reputation. I guess this thread should be closed.
 
Top