Jump to content

Another noob, anothe problem...


garcon

Recommended Posts

Hi, just started learning php and I've created a little practice website which has 5 "venues" you can post reviews for. You need to sign up to post a review but you don't need to login (so no sessions etc.). There's fields for email/password on the add review form. This is the last script I need to get working then my little site is finished.... When I try to post a review the server returns nothing for this page not even the HTML, previously this has been because I've done something like miss a semi-colon, but I've scoured this script and can't see anything like that. So I guess my questions..

 

 

1. Is there a simple and comprehensive guide out there for installing php/mysql on my home machine

2. Will the above allow me to step through the php line by line so I can debug?

3. Is it just an idiotic mistake like a missing semi-colon in the code below that I can't see?

 

<?php
//connection
include("connect.php");

//create header escape string thing
$returntoform = "Location: add_review.php?id=" . $_POST["venue_id"];

if(isset($_POST["submit"]) {

if(empty($_POST["email"]) || empty($_POST["password"]) ||
	empty($_POST["title"]) || empty($_POST["body"])) {
	echo "Form not completed.";
	header($returntoform);
	exit;
	}

//check user details	 
$email = $_POST["email"];
$password = $_POST["password"];

$sql = "SELECT user_id, password FROM user WHERE email='$email'";
$result = mysql_query($sql);

if(!$result) {
	echo "email address not found!";
	header($returntoform);
	exit;
	}

$user = mysql_fetch_object($result);	
if($user->password != $password) {
	echo "Password incorrect!";
	header($returntoform);
	exit;
	}

$user_id = $user->user_id;
$title = $_POST["title"];
$body = $_POST["body"];
$venue_id = $_POST["venue_id"];

//email and password, OK. Insert review
$sql = "INSERT INTO `review` (venue_id, post_date, title, body, user_id)
		 	 VALUES ('$venue_id', CURRENT_TIMESTAMP, '$title', '$body', '$user_id')";
$result = mysql_query($sql);

if(!$result) {
echo "Failed to add review!";
} else {
			 echo "Thankyou for your review. Please click <a href=\"venue.php?id=";
			 echo $venue_id;
			 echo "\">here</a> to return to the venue's page and see your review.";
	}
}
?>

Link to comment
Share on other sites

"1. Is there a simple and comprehensive guide out there for installing php/mysql on my home machine"

 

what operating system? many people have good luck with XAMP on Windows, MAMP on Macs. You probably don't want to compile Apache, PHP and MySQL yourself unless you have to.

 

"2. Will the above allow me to step through the php line by line so I can debug?"

 

No. Most people use a PHP-friendly text editor. I use BBEdit on Mac, don't know what they use on Windows. There may be some IDE's out there that will allow you to step through/execute PHP line-by-line, but I'm not familiar with them.

 

"3. Is it just an idiotic mistake like a missing semi-colon in the code below that I can't see?"

 

No errors displayed? Just a blank page? Turn on error_reporting before anything else in the script:

 

error_reporting(E_ERROR | E_WARNING | E_PARSE);

Link to comment
Share on other sites

You're going to have problems with the code you posted, because it is outputing text to the screen before the header function is called. If you have error reporting on this will show an error, and it will stop the header from working.

 

yep i agree can use the ob_start() and end page ob_flush()

but really shouldnt unless really need to....

Link to comment
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.