PHP - Strange Outcoming Using ?action= In A Hyperlink
I'm making a simple shopping cart. I have a strange issue when I add a product to the cart - the correct id registers ("1"), but the size registers as "0" when it should be "sizel". Can anyone see why is this happening?
<?php if (isset ($_GET['action']) && $_GET ['action'] == add || size) { $id = intval($_GET['id']); $_SESSION['cart'][] = $id; $size = intval($_GET['size']); $_SESSION['cart'][] = $size; } $cart = $_SESSION['cart']; if (!$cart) { echo "No product in cart."; } elseif ($cart) { foreach ($_SESSION['cart'] as $id) { echo $id; } foreach ($_SESSION['cart'] as $size) { echo $size; } } ?> Code: [Select] <A href="index.html?action=add&id=1&size=sizel">Add to cart</A> Similar TutorialsHi I am building a class to manage site users (Via a CMS). In order to complete this I am building a delete/remove user function/method. Things are going ok (I think), but I am confused about what to put in the action tag of the form being used to process the data. Before coding my method, I referred to a script that someone showed me which does something similar in functionality: it deletes photos previously uploaded to a folder, and also removes the associated information from the database. I used this script as the framework for the code that I am working with. Eveything seems to be working fine - EXCEPT - when I click on the 'delete users' button, nothing happens. The first thing that I examined for error was the action attribute within my form. The value of the action attribute is: action = "<? php htmlentities($_SERVER["PHP_SELF"]) ?>" This format has worked for previous forms. I compared this to the action attribute within the script that I was using as a guide. It's value is set as follows: action = "remove_photo.php?<?php echo "action='godel' ";?> In this instance, remove_photo.php is the file that is being used to both process and display the form. The reference script works perfectly but it uses a procedural approach . For my application, I am using a more object oriented approach, so both my opening and closing form tag elements are stored in a seperate file to the class file that processes it. I am new to OO but relatively comfortable with the paradigm so far (my other methods etc are working fine). I therefore suspect that the reason for my script's inability to process is due to the action attribute setting (I cannot be 100% sure of course!). I am going to therefore apply the action attribute settings used successfully in the reference script, to the application that I am building. However, the trouble is, I don't understand it I don't like it when something works, but I can't see the logic behind why it does. I am not concerned about the form id or method attrbutes. I understand what is going on there - and why they are set as they are. However, the action attribute is very difficult to understand for the following reasons: 1/ There is no variable/method/entity/object/ANYTHING called 'godel' elsewhere in the reference script. For this reason I thought that it might not be needed, so removed the bit of code within PHP tags concerning it: <?php echo "action='godel' ";?> - When I did this - the script didn't work. In fact - nothing at all would process. This was a similar result to what was happening with the script I am building. 2/ I then put the PHP line back in, but replaced 'godel' with 'something'. I saved and processed the form. - it worked. 3/ I then tried it again replacing 'godel' with an empty string i.e: ' '. - it worked. Has anyone come across forms being processed in a similar way before? If so, please could you explain what is happening here. I can't find anything relating to this type of occurence online.... I am going to place the php tags in the file I am building, to see if it has the desired effect. If it does, I will obviously keep it. But not understanding what is happening, or why it is happening is very annoying!! Thanks echo(" <form method = \"get\" action = \"DeleteApp.php?pname=\" . $Applications['Name'] . \"> <input value='Delete' type='submit' /> </form> "); Why is this redirecting to: DeleteApp.php?. Instead of what you can obviously see what it's supposed to redirect to. I know that PHP is server-side, but I wondered whether anyone had a similar issue that they got around... here's my problem... I've made a psycho-analysis tool for Facebook where it runs your Facebook friends through a database of words to get their psychological preferences (that all works)... I then have a link so that users can tell their friends about the service (it's free, so I want to get it to spread virally) but I'm having a few issues with the link... At the moment, it all works from a Facebook point of view, but when they click on the link, it takes them to an almost-blank page with a bit of code on it. I know what this code is and why it's there, but I'd like to hide it behind a branded page, ideally with Ajax. When I tried to use Ajax for it, it wouldn't accept the URL that was sent. The link has to have a URL sent to Facebook like this: Code: [Select] https://graph.facebook.com/feed?access_token=149324721793321|HarGd6ioqoroENE9gv2758rfeYY&message=I%27ve+just+psycho-analysed+my+Facebook+friends+using+Manteya%27s+Facebook+Friend+Checker+%28http%3A%2F%2Fwww.manteya.com%2Ffacebook-friend-checker%29+so+that+I+can+communicate+better+with+you.&id=100001925276042 but for obvious reasons, you can't post it as an Ajax variable by using the: Code: [Select] http://www.url.com/test.php?id=$variable; Is there a way I can get around the problem? I guess the issue is that Facebook needs the detail in the URL, but PHP won't let me send it like this. I have thought about uploading the URL to a database and shortening the URL, then posting that, which would then re-direct, but that's a messy way around I'm sure you smart people have done something like this before. To see my existing (almost) working example, visit http://www.manteya.com/ffc Thanks, Neil I have an action that will take a long time to finish, so how can I run this action in background? So I will not have to wait it ends... Hello everyone from a php newbie, I have a option selections box and need to select an action depending on the results. Its for an insert script for items into a Database and depending on the chosen option it add the picture to the DB table The selection options are <select name="extension" style="font-size:18px"><option value="pdf">PDF</option><option value="zip">ZIP</option><option value="powerpoint">PowerPoint</option></select> the Swtich is switch $_POST['extention']{ case 'zip': echo $insert_image = $_POST['extension'].'winzip.gif'; break; case 'powerpoint': echo $insert_image = $_POST['extension'].'ppt.gif'; break; default: echo $insert_image = $_POST['extension'].'products/pdf.gif'; } Would someone please tell me if this is correct syntax? Or have i got it horribly wrong! Thank you for your a help Charlie im making this tool to clean up some data from a sql database, i made a php code to list what i need, thats player name,lvl and id from table_A, the problem is i want to delete from table_A and from table_B all the results from php code , they have in common the id and as a condition the lvl must be lower then 10, it seems i cant make it delete from table_B also,please help me!! a button of the end of the page to delete all that includes same id from both tables is what im looking for! Code: [Select] <table<?php echo $tableSet; ?>> <tr> <td width="*" align="center">Rank</td> <td width="*" align="center"><font color="#000000">Name</td> <td width="*" align="center"><font color="#000000">money</td> <td width="*" align="center"><font color="#000000">id</td> <td width="*" align="center"><font color="#000000">lvl</td> </tr> <?php $rank = mysql_query('SELECT name,money,id,level FROM table_A WHERE level < 10 ' .' ORDER by level desc LIMIT '.$limit.';'); $i=1; while ($row = mysql_fetch_array($rank)) { echo '<tr><td align="center">'.$i.'.</td> <td align="center"><font color="#0000FF">'.$row['name'].'</td> <td align="center"><font color="#0000FF">'.$row['money'].'</td> <td align="center"><font color="#0000FF">'.$row['id'].'</td> <td align="center"><font color="#FF0000">'.$row['level'].'</td> </tr> '; $i++; } ?>this is showing which player names goes to id(from table_A) i need to delete from table_a where the ids shown are lower then lvl 10(the ones result from code above) and same ids from table_b (the rank is just to show me ho is highest lvl) Hi everyone I am trying to pass a php variable ($R1 = 1) in to action script flash 8. After this variable is in flash 8 I want the action script to do a if statement that says if the php variable is = 1 then display layer or object. However i am not sure how to do this any help would be great thanks Freid001 PS if this is not possible to do with php and action script please say thanks When I click the save changes button, I want the user to be brought back to profile.php. Right now they are being brought to editprofile.php. I currently have the form action set to editprofile.php . When the I change it to profile.php my fields won't update. Any thoughts as to where I went wrong? Here is the editprofile.php code. <form action='editprofile.php' method="POST" id="form"> Hello I am trying to get an action status based on e.g attackers_1 troops. Unfortunately I get nothing when I die the $strikeaction var here is my function and method I use to call it. Code: [Select] <?php function getStrikeAction($id){ $q = "SELECT * FROM `accountinfo_db` WHERE `id` = '$id'"; $res = mysql_query($q) or die(mysql_error()); $player = mysql_fetch_array($res); if($player['siegetech']>=1){ $strikeaction=($player['attackers_1'] * $player['siegetech'] * 120); $strikeaction+=($player['attackers_2'] * $player['siegetech'] * 1200); $strikeaction+=($player['attackers_3'] * $player['siegetech'] * 80); }else{ $strikeaction=($player['attackers_1'] * 120); $strikeaction+=($player['attackers_2'] * 1200); $strikeaction+=($player['attackers_3'] * 80); } $id = $player['id']; $q = "UPDATE `accountinfo_db` SET `strikeaction` = '$strikeaction' WHERE `id` = '$id'"; $res = mysql_query($q) or die(mysql_error()); return $stikeaction; } ?> Code: [Select] <?php echo getStrikeAction($player['id']);?> Im having some problems with my PHP program... Im trying to get the imformation send to my inbox, but when i push the submit button; i get no email and the "thank you message" is incomplete.. (see attachement: thankUmessage.png) I have to say, im not really a PHPfreak , I understand this language a little.. I hope someone can help me first the codes: HTML: (see attachement: form.png) Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>contactformulier</title> <style type="text/css"> <!-- body,td,th { font-family: Arial, Helvetica, sans-serif; font-size: 13px; color: #FFFF00; } body { background-color: #CCCCCC; } .style2 {font-size: 16px} --> </style> <script type="text/javascript"> <!-- function MM_validateForm() { //v4.0 if (document.getElementById){ var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments; for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]); if (val) { nm=val.name; if ((val=val.value)!="") { if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@'); if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n'; } else if (test!='R') { num = parseFloat(val); if (isNaN(val)) errors+='- '+nm+' must contain a number.\n'; if (test.indexOf('inRange') != -1) { p=test.indexOf(':'); min=test.substring(8,p); max=test.substring(p+1); if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n'; } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; } } if (errors) alert('The following error(s) occurred:\n'+errors); document.MM_returnValue = (errors == ''); } } //--> </script> </head> <body> <form id="form1" name="form1" method="post" action="contactafhandeling.php"> <table width="400" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC" bgcolor="#000000"> <!--DWLayoutTable--> <tr> <td height="39" colspan="6"><div align="center" class="style2">Contact formulier<br /> </div></td> </tr> <tr> <td height="21"><div align="right">Aanhef:</div></td> <td width="4" rowspan="7"> </td> <td colspan="4" valign="top"> <select name="aanhef" id="aanhef"> <option value="dhr" selected="selected">Dhr.</option> <option value="mvr">Mvr.</option> </select> </td> </tr> <tr> <td width="72" height="20"><div align="right">Voorletters:</div></td> <td width="42" valign="top"><div align="left"> <input name="voorletters" type="text" id="voorletters" size="5" maxlength="40" /> </div></td> <td width="120" valign="top"><div align="center">Achternaam: </div></td> <td colspan="2" valign="top"><div align="left"> <input name="achternaam" type="text" id="achternaam" size="20" maxlength="40" /> </div> <div align="left"></div> </td> </tr> <tr> <td height="20"><div align="right">Adres:</div></td> <td colspan="2" valign="top"><div align="left"> <input name="adres" type="text" id="adres" size="20" maxlength="40" /> </div> <div align="center"></div> <div align="left"></div></td> <td width="79" valign="top"><div align="center">Postcode:</div></td> <td valign="top"><div align="right"> <input name="postcode" type="text" id="postcode" size="10" maxlength="7" /> </div></td> </tr> <tr> <td height="20"><div align="right">Woonplaats:</div></td> <td colspan="4" align="right" valign="top"><div align="left"> <input name="woonplaats" type="text" id="woonplaats" size="20" maxlength="40" /> </div> <div align="left"></div> <div align="left"></div> <div align="left"></div></td> </tr> <tr> <td height="20"><div align="right">Tel:</div></td> <td colspan="4" valign="top"><div align="left"> <input name="tel" type="text" id="tel" size="20" maxlength="10" /> </div></td> </tr> <tr> <td height="20"><div align="right">Email:</div></td> <td colspan="4" valign="top"> <div align="left"> <input name="email" type="text" id="email" size="40" maxlength="40" /> </div></td> </tr> <tr> <td height="20"><div align="right">Interesses:</div></td> <td colspan="4" valign="top"><div align="left"> <label></label> <label> <input type="checkbox" name="badkamer" id="badkamer" /> Badkamermeubels</label> <label> <br /> <input type="checkbox" name="kantoor" id="kantoor" /> Kantoormeubels</label> <label> <br /> <input type="checkbox" name="kasten" id="kasten" /> Kasten</label> <label><br /> <input type="checkbox" name="keukens" id="keukens" /> Keukens <br /> </label> <label> <input type="checkbox" name="tafels" id="tafels" /> Tafels</label> <br /> </div></td> </tr> <tr> <td height="21" colspan="5" valign="top"><input type="reset" name="reset" id="reset" value="Reset" /></td> <td width="83" height="21" valign="top"><input name="verzenden" type="submit" id="verzenden" onclick="MM_validateForm('voorletters','','R','achternaam','','R','tel','','RisNum','email','','RisEmail');return document.MM_returnValue" value="Verzenden" /></td> </tr> </table> </form> </body> </html> Looks like: afbeelding 1.png Then the PHP code: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Contactafhandeling</title> </head><body> <? $aanhef = $_POST['aanhef']['dhr']; $aanhef = $_POST['aanhef']['mvr']; $voorletters = $_POST['voorletters']; $achterNaam = $_POST['achterNaam']; $adres = $_POST['adres']; $postcode = $_POST['postcode']; $tel = $_POST['tel']; $email = $_POST[email]; $interesses = $_POST['badkamer']['kantoor']['kasten']['keukens']['tafels']; $formsent = mail('sven_jcvd@hotmail.com', 'Gegevens afkomstig van contactformulier.html', "Naam: $aanhef $voorletters $achterNaam\r\n Adres: $adres\r\n Postcode: $plaatst\r\n Telefoonnummer: $tel\r\n Emailadres: $email\r\n Interesse in: $interesses", "From: $email\r\nBounce-to: sven_jcvd@hotmail.com"); if ($formsent) { echo "<p>Beste $achternaam,<br><br> Bedankt voor uw bericht, we zullen zo snel mogelijk contact met u opnemen.\n\r Met vriendelijke groet, JPS</p>"; } else { echo "<p>Sorry, er gaat iets fout met het formulier, probeer het later nog eens a.u.b.</p>"; } ?> </body> </html> Hi,
I'm using an example below regarding a whole URL. I'm looking for some conditional PHP that will display certain content depending on if the URL contains the word 'liz' if not, display else.
$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; if($host == 'liz-4.website.com') I've heard multiple recommendations when a form needs to post to itself. Some say use PHP_SELF, others say leave it blank (even though it doesn't validate), etc. Please provide the best practice, and reasons why. Thank you
echo("<form method='post' action='{$_SERVER['PHP_SELF']}'>"); echo("<form method='post' action=''>"); Hi all, I my making a site which to be easier i have made a querystring statement, but the issue is that when accessing /?action= shows index and ?action=register shows register great!, when accessing root / of the site or index.php and displays Undefined index: action , when clearly i have defined action with $id, so why is php saying it is not. I know there is the option for error_reporting(0), but i want to know why this is happening. Edit: the script is, and runs fine other than the error! Code: [Select] <?php $id = "action"; $string = $_GET["$id"]; if ($string == "register") { echo 'register'; } else { echo 'index'; } ?> Many Thanks how do I put a get id into this form, or use $myvar?: Code: [Select] <form action='read2.php?id=' method="post" name='myForm' id="myForm"></form> Hey guys Just a quick question: How to embed hyperlink into a database cell? Basically I echo out a table on the user interface of my site and there's an URL in one of the cells I want the user to access it by clicking on it, without copying and pasting the URL into the URL bar of the browser I tried updating the cell in phpmyadmin using <a href = http://www.example.com>http://www.example.com</a> but didn't work out, the resulting cell only had the text format Any help would be appreciated Thanks. Hi, I'm creating a PHP application to handle my SQL server and I've run into a bit of a problem; I have two files atm: mainClass.php and testSite.php My mainClass.php looks like this: Code: [Select] class mainClass { private $host = 'localhost'; public function createDb($user,$pass,$dbName) { $con = mysql_connect($host, $user, $pass); if (!$con){ die('Could not connect: '.mysql_error()); } $sql = "CREATE DATABASE `$dbName`;"; if (!mysql_query($sql)){ die('Error 1: '.mysql_error()); } mysql_close(); } }and testSite.php looks like this: Code: [Select] <!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <h1>testSite for my PHP app</h1> <?php function __autoload($className){ require_once "./classes/{$className}.php"; } $test = new mainClass(); ?> <form name='createDb' method='post' action=''> User: <input type='text' name='user'><br> Password: <input type='password' name='pass'><br> dbName: <input type='text' name='dbName'><br> <input type='submit' value='Create DB'> </form> </body> </html> What I'm asking is if it is possible to make the form-action from testSite.php run the createDb function from mainClass.php I have pretty much no idea how to do it but I tried like this: Code: [Select] <form name='createDb' method='post' action="<?php $test->createDb($_POST['user'],$_POST['pass'],$_POST['dbName']); ?>"> User: <input type='text' name='user'><br> Password: <input type='password' name='pass'><br> dbName: <input type='text' name='dbName'><br> <input type='submit' value='Log in'> </form>But that just made the whole form disappear so now I'm completely lost, any help greatly appreciated. PS: I'm doing this to get better at PHP so please don't come with advice like "use a framework" or "there already are applications that handles this", I know there is. My question is, when someone make same html form with action that goes on same php file on my server, so i need to know, can my site be hacked in that way ? I mean if i have form that goes on file /sources/add_user.php and when someone make same html form that goes on www.my-site.com/sources/add_user.php and in that way to add users on my baze ? Hi guys, I want to create a piece of script that takes my users to a website based of there input in a form. Basiaclly what they input into a text field will become part of the URL used in action at the top of the form. So it would look like this: http://www."their input from form".mydomain.com does anyone have any suggestions on how to accomplish this? Thanks is there anyway to hide the action URL from html form example: <form name="afrom" action="hide.php" method="post"> so it end up from the user side: <form name="afrom" action="" method="post"> Thanks! It has been brought to my attention that $_SERVER['PHP_SELF']; can be easily hacked. In this code... Code: [Select] <form id="login" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Do I even need anything in the Action attribute if I am redirecting the form to itself?! Please advise... Debbie |