Jump to content

Recommended Posts

Best Way to Approve User-added Date

 

I’ve got a PHP system that uses SMF to handle the user login etc and so that I have a forum as well. I’ve got as far as users being able to login to the page this allows the user to add a review for an object on the object page using an HTML form and I use $_GET to get an ID from the URL and this displays data for the object of that ID so http://www.mywebpage.com/object.php?id=1 displays data for that object from a table called Objects. I have two tables that I want to display data from based on a common column. Here’s an example of the tables and their rows:

 

Objects (ID, Object, ObjectInfo)

Reviews (ID, Object, Username,Review)

 

I know that I can use LEFT JOIN to display data from the tables based on the common columns however it seems that I can’t get LEFT JOIN to work in the query when I use WHERE to get the ID of the Object. Basically I want the Object data to be displayed at the top of the page and the reviews are called in a loop because users can add reviews and I only want to display reviews for that object hense why I have a column in the two tables called Object. Here’s an example of how the code looks so far:

 

<?php

include ’header.php’;

$id = $_GET[‘id’];

$sql = mysql_query(“SELECT * FROM Objects WHERE id = $id”);

$row = mysql_fetch_array($sql);

$object = $row[‘object’];

$objectInfo = $row[‘objectInfo’];

echo $object;

echo $objectInfo;

while($row = mysql_fetch_array($sql))

{

// Here I want to display reviews that relate to the ID of the object

}

Once I figure this out I want to know what is the best way to approve user-added data. When the user adds a review I use a form that inserts the data into an approve table so that I can check for errors etc. I’ve set-up a page that selects all the data from the approve table and displays the data as values in a form so that I can submit the form and it will execute a script that adds the values into the reviews table but this is just too much because now I’m using a form to get data from the users and then I’m using a script to insert that into the approve table and now I’m trying to use a form and using the data as values in the form so that I can execute a script to insert that into the reviews table. Is there not an easier way to do this? I prefer to keep the forms and scripts separate. Let me show you what I mean…

 

So just below the loop in the above code I use an SMF global to check that the user is logged in by using if($context[‘user’][‘is_guest’]) and if they are I echo an HTML form and I’ve also used SMF globals to get the username and the object by calling $object as set previously in the code. If the user isn’t logged in then there will be a login form displayed at the top of the page as this has been included and it’s all working I’m just trying to give you a clear idea of what I’m trying to do and you can tell me if I’m going about this professionally:

 

if($context[‘user’][‘is_guest’])

{

echo “You must be logged in to add a review.”;

}

else

{

echo “<form action=\”insert.php\” method=\”post\”>\n”;

echo “<input type=\”hidden\” name=\”object\” value=\””.$object”\”>\n”;

echo “<input type=\”hidden\” name=\”username\” value=\””.$context[‘user’][‘name’].”\”>\n”;

echo “Review: <input type=\”text\” name=\”review\”>\n”;

echo “<input type=\”submit\” value=\”Submit\” />\n”;

}

include ’footer.php’;

?>

And here’s the add.php script used to process the form:

 

<?php

include ‘db.php’;

$object = $_POST[‘object’];

$username = $_POST[‘username’];

$review = $_POST[‘review’];

mysql_query(“INSERT INTO approvals (object,username,review) VALUES (‘$object’,’$username’,’$review’)”);

?>

This all works okay but I’m stuck on what to do next in order to approve the data and transfer to the reviews table and delete the approved data from the approvals table. If anyone has any tips on how to improve my code or any ideas on what to do next please do try to respond asap. I’m really stuck right now and I didn’t get any sleep last night because of this. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/183592-best-way-to-approve-user-added-data/
Share on other sites

Okay I've now used 2 queries. The first one is exactly the same as in the code above and the second is called in the while loop and that retreives all data from the reviews table when the object = review. Is it okay to use 2 queries in one PHP file in this manner? It seems to be the only working method because of the WHEN statement in the first query disables me from succesfully joining the tables using LEFT JOIN.

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.