Jump to content

Recommended Posts

I have a MySQL database created.  I also have a website powered by WordpressMU up and running.  I am somewhat familiar with php, but no expert. The site is www.ex-brief.com

 

Here is what I am trying to accomplist, I know it will take a combination of an HTML form, and some php scripts to make this work, but for some reason I can not get it to all come together.

 

What I want is this:

 

I want people to be able to enter information on their ex, including name, city, state, wether they had a positive or negative experience and a comment and photo.  Obviously all this info will be saved in the database, which needs to be searchable by any combination of the variables (name, city, etc.).  I would like each profile to have a unique ID number and for users to be able to flag them for inappropriate content which will send a notice to the admin who can edit or delete the profile.  I would like people to be able to add comments as well (comments should get a date stamp) that have also dated this person.  Also if you have selected them a your ex I want there to be a link to their ex-profile page in the your user profile.

 

Anyone help me out here?  thanks.

Link to comment
https://forums.phpfreaks.com/topic/142024-design-question/
Share on other sites

I thought as much.

 

Database is setup, has a table with the required fields, except I do not know how to save images that go with this information in the database.

 

I want to create a page with a search form, I think I can handle writing an HTML form to call the php search file.

 

Not 100% sure on how to do the php file that will perform the search.  I need it to be able to search with the form info supplied by the user, which will be as little as 1 piece of info or more, to return the results in order of relevance.

 

And not sure on how to call up the results and display them. 

 

The really tricky part I probably will not be able to figure out is the flagging system, and how to make these appear in users profiles if users select these people as "exes".

 

I guess I am just totally lost.

 

Seemed easy at first but has gotten very complicated.  Help on any parts will be appreciated.  thanks!

 

 

Link to comment
https://forums.phpfreaks.com/topic/142024-design-question/#findComment-743739
Share on other sites

I agree.  As I stated a few times, I am not a PHP expert.  I know how to do all the basic scripts, but getting them to work exactly how I want them seems to be where I fall short.  I will create what I can then come back to see if you can help me tweak the scripts. 

 

 

Also not trying to sound rude, but if I knew what I was doing I would not be here bothering everyone.  It would be hard to have a PHP Help board if everyone on it already knew all the answers...there would be no questions, LOL!

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/142024-design-question/#findComment-743828
Share on other sites

It would be hard to have a PHP Help board if everyone on it already knew all the answers...there would be no questions, LOL!

 

Yeah, I understand that. But the usual line of questions is allot more specific and narrowed down some.

 

Maybe if you break this one big problem down into smaller pieces. ie; 'How do I upload images and save the file names into a database?'

Link to comment
https://forums.phpfreaks.com/topic/142024-design-question/#findComment-743833
Share on other sites

ok, I have completed most of what I need to make this all work, a little fuzzy on the rest.  Here is what I have (code displayed also):

 

1) Form To Input Data Into Database (bare bones, not styled)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
  <title></title>
</head>
<body>
<form action="insert.php" method="post">
First Name: <input name="first" type="text"><br>
Last Name: <input name="last" type="text"><br>
City: <input name="city" type="text"><br>
State: <input name="state" type="text"><br>
<br>
  <input type="submit">
</form>
</body>
</html>

 

2) PHP Script to Add Information From Form To Database

 

<?php

include("dbinfo.inc.php");

$first=$_POST['first'];
$last=$_POST['last'];
$city=$_POST['city'];
$state=$_POST['state'];


mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO contacts VALUES ('','$first','$last','$city','$state')";
mysql_query($query);

if($query) {
echo "Ex Brief Submitted Successfully.";
} else {
echo "The Ex Brief was not processed.  Please review the information you entered for accuracy.";
}

mysql_close();


?>

 

3) PHP Script to Display Results from Database on webpage

 

<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts";
$result=mysql_query($query);

$num=mysql_numrows($result); 

mysql_close();

echo "<b><center>Database Output</center></b><br><br>";

?>
<table border="0" cellspacing="2" cellpadding="2">
<tr> 
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">City</font></th>
<th><font face="Arial, Helvetica, sans-serif">State</font></th>
</tr>

<?
$i=0;
while ($i < $num) {
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$city=mysql_result($result,$i,"city");
$state=mysql_result($result,$i,"state");
?>

<tr> 
<td><font face="Arial, Helvetica, sans-serif"><? echo "$first $last"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$city"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$state"; ?></font></td>
<?
++$i;
} 
echo "</table>";


?>

 

 

Now I am very vague on how to write a search script to allow users to search the database and have the results of the search on the webpage.  I guess some guidance and suggestions on how to make all this work the best would be great thanks!

Link to comment
https://forums.phpfreaks.com/topic/142024-design-question/#findComment-743949
Share on other sites

ok, I have completed most of what I need to make this all work, a little fuzzy on the rest.  Here is what I have (code displayed also):

 

1) Form To Input Data Into Database (bare bones, not styled)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
  <title></title>
</head>
<body>
<form action="insert.php" method="post">
First Name: <input name="first" type="text"><br>
Last Name: <input name="last" type="text"><br>
City: <input name="city" type="text"><br>
State: <input name="state" type="text"><br>
<br>
  <input type="submit">
</form>
</body>
</html>

 

2) PHP Script to Add Information From Form To Database

 

<?php

include("dbinfo.inc.php");

$first=$_POST['first'];
$last=$_POST['last'];
$city=$_POST['city'];
$state=$_POST['state'];


mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO contacts VALUES ('','$first','$last','$city','$state')";
mysql_query($query);

if($query) {
echo "Ex Brief Submitted Successfully.";
} else {
echo "The Ex Brief was not processed.  Please review the information you entered for accuracy.";
}

mysql_close();


?>

 

3) PHP Script to Display Results from Database on webpage

 

<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts";
$result=mysql_query($query);

$num=mysql_numrows($result); 

mysql_close();

echo "<b><center>Database Output</center></b><br><br>";

?>
<table border="0" cellspacing="2" cellpadding="2">
<tr> 
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">City</font></th>
<th><font face="Arial, Helvetica, sans-serif">State</font></th>
</tr>

<?
$i=0;
while ($i < $num) {
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$city=mysql_result($result,$i,"city");
$state=mysql_result($result,$i,"state");
?>

<tr> 
<td><font face="Arial, Helvetica, sans-serif"><? echo "$first $last"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$city"; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo "$state"; ?></font></td>
<?
++$i;
} 
echo "</table>";


?>

 

 

Now I am very vague on how to write a search script to allow users to search the database and have the results of the search on the webpage.  I guess some guidance and suggestions on how to make all this work the best would be great thanks!

 

I have a code script but for some reason all I get is a blank page when I break it into 2 files, as is in 1 file it just returns to the exact page in the web browser, its not displaying any results....or anything for that matter.

 

<h2>Search</h2>
<form name="search" method="post" action="<?=$PHP_SELF?>">
Seach for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="first">First Name</option>
<Option VALUE="last">Last Name</option>
<Option VALUE="city">City</option>
<Option VALUE="state">State</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>

<?
//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";

//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}

// Otherwise we connect to our Database
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM contacts WHERE upper($field) LIKE'%$find%'");

//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo $result['first'];
echo " ";
echo $result['last'];
echo "<br>";
echo $result['city'];
echo "<br>";
echo $result['state'];
echo "<br>";
echo "<br>";
}

//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}

//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
}
?> 

 

 

So I need to get the search script working, and I need to tweak/tie all this together....thats where I am lacking knowledge.  Any advice would be greatly appreciated.  Thanks!

Link to comment
https://forums.phpfreaks.com/topic/142024-design-question/#findComment-744022
Share on other sites

Hi

 

This has gotta be a joke right?

 

Let me get this right, you are going to allow people to post pictures of other people including personal details without that persons consent and then allow people to comment on that person?

 

I just hope you have very deep pockets.

 

L8rs

Link to comment
https://forums.phpfreaks.com/topic/142024-design-question/#findComment-746403
Share on other sites


$first=$_POST['first'];
$last=$_POST['last'];
$city=$_POST['city'];
$state=$_POST['state'];

This portion is just adding overhead and unncessary. Just use the $_POST['var'] itself in the query construction statement.

 

<?php
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts";
$result=mysql_query($query);

while ($row = mysql_fetch_object($result)) {
    echo '<td>' . $row->first . '</td>';
    echo '<td>' . $row->last . '</td>';
    echo '<td>' . $row->city . '</td>';
    etc...
}
mysql_free_result($result);
?>

One problem you may have having with your scripts is the use of "short tags" for the php opening tag. Use "<?php"  not just "<?"  It's bad practice and a bad habit to get in to.

 

Try using the above modified section as a better method for your search code, less overhead and less hassle to mess with than your method.

 

 

In your 3rd block of code, you are utilizing an mysql_fetch_array(), which is going to cause you some issues if it's only returning one thing or nothing. Again, might want to use the mysql_fetch_object() function instead as you won't run in to those issues.

 

You also might want to nest your results displays inside of the check for whether you got any results or not. Just makes more logical sense from a code stance.

Link to comment
https://forums.phpfreaks.com/topic/142024-design-question/#findComment-747935
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.