57506

php ? url string not working with variable

Question:

I am using PHP to make different messages display (using ècho) depending on the ? attached to the URL, like this: http://somthing.com/page.php?something=1. I attached a variable called code to the end of the URL: http://somthing.com/page.php?code=1.

<?php $code; if(code == 1){ echo "Your account has been created."; } else if(code == 2){ echo "Thank you for your feedback."; if(isset($_POST["sent"])){ echo "You will receive an email at " . $_POST["youremail"] . "."; } } ?>

I declared the variable on line 1. No message is displaying. What am I doing wrong here? <a href="http://sarkelliancreed.comule.com/contact" rel="nofollow">Page the php is on.</a>

Answer1:

<ul><li>You should set $_GET['code'] to $code variable</li> <li>You should add $ sign when using a variable</li> </ul><hr />

<strong>Fixed Code:</strong>

$code = isset( $_GET['code'] ) ? $_GET['code'] : 0; if ( $code == 1 ) { echo "Your account has been created."; } else if ( $code == 2 ) { echo "Thank you for your feedback."; if ( isset( $_POST["sent"] ) ) { echo "You will receive an email at " . $_POST["youremail"] . "."; } }

Answer2:

You need to get data from $_GET

Something like this:

$code = $GET["code"];

Recommend

  • A few IBOutlets pointing to nil
  • Suspend the application
  • What are the best practices for having git clean history?
  • Could be Text orientation of JTextArea changed by keyboard shortcut?
  • Generating anchors with PyYAML.dump()?
  • Configure Spring's MappingJacksonHttpMessageConverter
  • How to autopopulate a field in SugarCRM form
  • how does System.Web.HttpRequest::PathInfo work?
  • How does this usort cmp function actually work?
  • Not able to aggregate on nested fields in elasticsearch
  • Stop Bash Script if Hive Fails
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • htaccess add www if not subdomain, if subdomain remove www
  • JSON response opens as a file, but I can't access it with JavaScript
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • Accessing IRQ description array within a module and displaying action names
  • Incrementing object id automatically JS constructor (static method and variable)
  • Display Images one by one with next and previous functionality
  • Upload files with Ajax and Jquery
  • Weird JavaScript statement, what does it mean?
  • How do you troubleshoot character encoding problems?
  • Do I've to free mysql result after storing it?
  • Why winpcap requires both .lib and .dll to run?
  • How to format a variable of double type
  • A cron job substitute?
  • json Serialization in asp
  • Acquiring multiple attributes from .xml file in c#
  • Free memory of cv::Mat loaded using FileStorage API
  • How to set the response of a form post action to a iframe source?
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • How can I remove ASP.NET Designer.cs files?
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • unknown Exception android
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal