1
Beginners - Learning PHP / Re: when i change a link on a form sql query wont work
« on: April 29, 2012, 02:39:39 PM »
i got it working, submitted the form to a page on my website first, which auto submitted the paypal link
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
<center><p> <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="derek.skybc3@gmail.com"> <?php paypal_items(); ?> <input type="hidden" name="currency_code" value="EUR"> <input type="hidden" name="amount" value="<?php echo $total; ?>"> <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but03.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form> </p></center>
<center><p>
<form action="index3.php" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="derek.skybc3@gmail.com">
<?php paypal_items(); ?>
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="amount" value="<?php echo $total; ?>">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click- but03.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
</p></center>
<center><p>
<form action="index3.php" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="derek.skybc3@gmail.com">
<?php paypal_items(); ?>
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="amount" value="<?php echo $total; ?>">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but03.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
</p></center>

<center><p>
<form action="index3.php" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="derek.skybc3@gmail.com">
<?php paypal_items(); ?>
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="amount" value="<?php echo $total; ?>">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click- but03.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
</p></center>
if (isset ($_POST['submit_x']) ) //////_x needs to be added to submit because it is a image button
{
$user_id = $_SESSION['user_id'];
$get = mysql_query("SELECT firstname, lastname, id FROM users WHERE id='$user_id '" ); // int means interger is only being passed for secuirty;
while ($get_row = mysql_fetch_assoc($get) ){
$firstname = $get_row['firstname'];
$lastname = $get_row['lastname'];
$persons_id = $get_row['id'];
$rented_movie = $name;
$date_rented = date("d F Y"); // function thats gets todays date
$d = date(" d ");
$d = $d +2; // adding 2 to todays date
$due_back = date("$d F Y "); // date rental is due back
$query = "INSERT INTO rentals VALUES('','$firstname $lastname','$persons_id','$rented_movie','$date_rented','$due_back' )"; //query that inserts data the users entered in the sign up form into the database
$query_run = mysql_query($query);
}
<center><p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="derek.skybc3@gmail.com">
<?php paypal_items(); ?>
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="amount" value="<?php echo $total; ?>">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but03.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
</p></center>
<?php
session_start();
$page = 'index2.php';
if(isset ($_GET['addrent']) ){
$quantity = mysql_query('SELECT id, quantity FROM movies WHERE id='.mysql_real_escape_string((int)$_GET['addrent']));
while($quantity_row = mysql_fetch_assoc($quantity) ){
if($quantity_row['quantity'] != $_SESSION['cart2_'.(int)$GET['addrent'] ])
{
$_SESSION['cart2_'.(int)$_GET['addrent']] +='1';
}
}
header('Location: '.$page);
}
if(isset ($_GET['addbuy']) ){
$quantity = mysql_query('SELECT id, quantity FROM movies WHERE id='.mysql_real_escape_string((int)$_GET['addbuy']));
while($quantity_row = mysql_fetch_assoc($quantity) ){
if($quantity_row['quantity'] != $_SESSION['cart2_'.(int)$GET['addbuy'] ])
{
$_SESSION['cart2_'.(int)$_GET['addbuy']] +='1';
}
}
header('Location: '.$page);
}
if(isset($_GET['remove']) ) {
$_SESSION['cart2_'.(int)$_GET['remove']]--;
header('Location: '.$page);
}
if(isset($_GET['delete']) ) {
$_SESSION['cart2_'.(int)$_GET['delete']]='0';
header('Location: '.$page);
}
function products() {
$get = mysql_query("SELECT image, id, name, description, rent FROM movies WHERE quantity > 0 ORDER BY id DESC "
);
if(mysql_num_rows($get) == 0){
echo "there are no products to display";
}else{
while($get_row = mysql_fetch_assoc($get) ){
$get_row['name'];
$get_row['description'];
$get_row['image'];
$get_row['rent'];
$name = $get_row['name'];
$description = $get_row['description'];
$image = $get_row['image'];
$rent_price = '€'.number_format($get_row['rent'], 2);
$add = '<a href="cart2.php?addrent='.$get_row['id'].'">Rent</a>';
$add1 = '<a href="cart2.php?addbuy='.$get_row['id'].'">buy</a>';
$picture = '<img src="'.$image.'" alt="">';
echo "<center><table width='85%' border='2' >
<tr><td>$picture </td> <td><h3>$name</h3> <pre>$description </pre> </td><td>Rent $rent_price </td> <td> $add $add1 </td></tr>
</table></center>";
}
}
}
function cart() {
$sub = "";
$sub2 = "";
$total="";
foreach($_SESSION as $name => $value){
if($value > 0) {
if(substr($name, 0, 6)=='cart2_'){
$id = substr($name, 6, (strlen($name)-6)); // allows is to take the exact number from cart_
$get = mysql_query('SELECT id, name, rent FROM movies WHERE id='.mysql_real_escape_string((int)$id) ); // int means interger is only being passed for secuirty;
while ($get_row = mysql_fetch_assoc($get) ){
$sub = $get_row['rent']*$value;
echo $get_row['name'].' x '.$value.'@ €'.number_format($get_row['rent'], 2).'= €'.number_format($sub,2).'<a href="cart2.php?remove='.$id.'">[-]</a> <a href="cart2.php?addrent='.$id.'">[+]</a> <a href="cart2.php?delete='.$id.'">[Delete]</a> <br/> ';
}
}
if(substr($name, 0, 6)=='cart2_'){
$id = substr($name, 6, (strlen($name)-6)); // allows is to take the exact number from cart_
$get = mysql_query('SELECT id, name, buy FROM movies WHERE id='.mysql_real_escape_string((int)$id) ); // int means interger is only being passed for secuirty;
while ($get_row = mysql_fetch_assoc($get) ){
$sub2 = $get_row['buy']*$value;
echo $get_row['name'].' x '.$value.'@ €'.number_format($get_row['buy'], 2).'= €'.number_format($sub2,2).'<a href="cart2.php?remove='.$id.'">[-]</a> <a href="cart2.php?addbuy='.$id.'">[+]</a> <a href="cart2.php?delete='.$id.'">[Delete]</a> <br/> ';
}
}
$total += ($sub+$sub2);
}
}
if($total==0){
echo "Your cart is empty";
}else{
}
?>
<center><form action="films5.php" method="POST">
<center>Browes Films: <select name="category"[color=red]onchange='this.form.submit()'[/color] ></center>
<option selected="selected">Choose a Genre...</option>
<option value="Added">All</option>
<option value="Action">Action</option>
<option value="Comedy">Comedy</option>
<option value="Drama">Drama</option>
<option value="Thiller">Thiller</option>
<option value="ScFi">ScFi</option>
</select>
</form>
<form action="films3.php" method="POST">
<input type="text" name="search_name" size="10" />
<input type="Submit" value="Search" name="search" />
</form></center>
[color=red]if( isset( $_POST['category'] )[/color] ){
$dropdownValue = $_POST['category'];
switch( $dropdownValue ){
case "Action" : $query = "SELECT name,description,image FROM movies WHERE genre ='Action' ORDER BY id DESC LIMIT $start,$per_page"; break;
case "Comedy" : $query = "SELECT name,description,image FROM movies WHERE genre ='Comedy' ORDER BY id DESC LIMIT $start,$per_page"; break;
case "Drama" : $query = "SELECT name,description,image FROM movies WHERE genre ='Drama' ORDER BY id DESC LIMIT $start,$per_page"; break;
case "Thiller": $query = "SELECT name,description,image FROM movies WHERE genre ='Thiller' ORDER BY id DESC LIMIT $start,$per_page"; break;
case "Added" : $query = "SELECT name,description,image FROM movies ORDER BY id DESC LIMIT $start,$per_page"; break;
case "ScFi" : $query = "SELECT name,description,image FROM movies WHERE genre ='SC-FI' ORDER BY id DESC LIMIT $start,$per_page"; break;
default : die( "You have entered something that isn't an option in my dropdown" );
}
}
if( isset( $_POST['search'] ) ){
$dropdownValue = $_POST['category'];
switch( $dropdownValue ){
case "Action" : $query = "SELECT name,description,image FROM movies WHERE genre ='Action' ORDER BY id DESC LIMIT $start,$per_page"; break;
case "Comedy" : $query = "SELECT name,description,image FROM movies WHERE genre ='Comedy' ORDER BY id DESC LIMIT $start,$per_page"; break;
case "Drama" : $query = "SELECT name,description,image FROM movies WHERE genre ='Drama' ORDER BY id DESC LIMIT $start,$per_page"; break;
case "Thiller": $query = "SELECT name,description,image FROM movies WHERE genre ='Thiller' ORDER BY id DESC LIMIT $start,$per_page"; break;
case "Added" : $query = "SELECT name,description,image FROM movies ORDER BY id DESC LIMIT $start,$per_page"; break;
case "ScFi" : $query = "SELECT name,description,image FROM movies WHERE genre ='SC-FI' ORDER BY id DESC LIMIT $start,$per_page"; break;
default : die( "You have entered something that isn't an option in my dropdown" );
}
}
$query_run = mysql_query($query);
, just changed the full path to just the image name(name.jpg) in the database and it worked, something so simply.Are you storing the entire path or just the filename?