Jump to content

Query performs, but gives blank screen


peter_anderson

Recommended Posts

Hi,

 

I've created a script where the user inputs the number they want to buy and it saves their details to the DB.

 

However, it is performing the query and adding it to the DB, but NOT showing the content.

 

What's wrong with it?

 

<?php

//load DB and CONFIG
require_once("./config.php");

ini_set('display_errors',1); 
error_reporting(E_ALL);

//load theme
$html = file_get_contents("./theme.html");

//start classes
$db = new db();

//connect to DB
//attempt it
$sql = new mysqli(db::$config['host'], db::$config['user'], db::$config['pass'], db::$config['db']);
//check for ERR
	if (mysqli_connect_errno()) {
	    printf("Connect failed: %s\n", mysqli_connect_error());
    	exit();
	}
	//

//replace valued variables on tpl
//note: you MUST use this if you wish to use PHP on your template!!!!!!
$html = str_replace('{sitename}', $sitename, $html);
$html = str_replace('{copyright}', $copyright, $html);

//get details
$name = $_POST['name'];
$email = $_POST['email'];
$security = $_POST['security'];
$address = $_POST['address'];
$paypal = $_POST['paypal'];
$eventname = $_POST['event'];
$adult_tix = $_POST['at'];
$concession_tix = $_POST['ct'];
$adult = $_POST['adult'];
$concession = $_POST['concession'];

//calculate cost
$cost1 = $adult_tix * $adult;
$cost2 = $concession_tix * $concession;
$cost = $cost1 + $cost2;

//insert details into DB
	$query3 = "INSERT INTO orders (id, name, email, address, security, paypal, eventname, adult_tix, concess_tix, cost, paid)
VALUES ('', '$name', '$email', '$address', '$security', '$paypal', '$eventname', '$adult_tix', '$concession_tix', '$cost', '')";

//perform query
$result = $sql->query($query3);

//auto-change shit
$return = '<p><strong>Processing Complete!</strong></p>
<p>We have now saved your order to our database.</p>
<p>Please click the button below to pay for your order.</p>
<p><form target="PayPal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="business" value="'.$paypal.'">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="'.$eventname.' Ticket Purchase">
<input type="hidden" name="item_number" value="TIX_rydTicket_3827yu">
<input type="hidden" name="amount" value="'.$cost.'">
<input type="hidden" name="currency_code" value="'.$ccode.'">
<input type="hidden" name="shipping" value="">
<input type="hidden" name="shipping2" value="">
<input type="hidden" name="handling" value="">
<input type="hidden" name="return" value="'.$server.'/ocomplete.php">
<input type="hidden" name="cancel_return" value="">
<input type="hidden" name="undefined_quantity" value="0">
<input type="hidden" name="receiver_email" value="'.$paypal.'">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="1">
<input type="image" name="submit" src="http://images.paypal.com/images/x-click-but01.gif" style="position:absolute;left:436px;top:873px;z-index:16" alt="Make payments with PayPal, its fast, free, and secure!">
</form>
</p>';

//content
$content = '<p><strong>Processing Order....</strong></p>
<p style="text-align: center;"><img src="images/loading.gif" alt="Loading....." /></p>
<p style="text-align: left;">Thank you for your order!</p>
<p style="text-align: left;">We are now processing it, and you will be redirected to payment in a few minutes.</p>

<script type="text/javascript"> 
window.onload = function () { 
  setTimeout(function () { 
    var div = document.getElementById(\"inner\"); 
    div.innerHTML = '.$return.'";  
  }, 10000); 
} ';
	return $content;


//set page title
$html = str_replace('{pagename}', 'Processing your order.....', $html);

//replace for the content
$html = str_replace('{content}', $content, $html);

//provide content - packs up all the above changes and adds it to your theme. important!!!!
echo $html;

?>

 

Thanks

Link to comment
Share on other sites

all i could find is that you are entering a blank data into id tab.. which probably is auto increment+primary if it is it shouldn't even be in your query other then that idk.. I dont see any code that has to return any data from mysql?

 

umm.. also $return  can use $return as a variable i always think any how u call em.. reserved keywords like return cannot be used as variables cuz of the mixups but i dont know really..

Link to comment
Share on other sites

This is your problem

		return $content;

 

Why do you have a return in the middle of your script outside of any function or construct where it would make sense? Not sure what you expect to happen here, but according to the manual: http://us.php.net/manual/en/function.return.php

 

If called from within a function, the return() statement immediately ends execution of the current function, and returns its argument as the value of the function call. return() will also end the execution of an eval() statement or script file.

 

So, once the script hits that return command it stops executing any more code - including the echo at the end to display the page.

Link to comment
Share on other sites

This is your problem

		return $content;

 

Why do you have a return in the middle of your script outside of any function or construct where it would make sense? Not sure what you expect to happen here, but according to the manual: http://us.php.net/manual/en/function.return.php

 

If called from within a function, the return() statement immediately ends execution of the current function, and returns its argument as the value of the function call. return() will also end the execution of an eval() statement or script file.

 

So, once the script hits that return command it stops executing any more code - including the echo at the end to display the page.

 

Thanks for that :)

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.