DarkPrince2005 Posted September 21, 2009 Share Posted September 21, 2009 I am trying to use the get function in php. I am setting the variables in the hyperlink url. But how would i set the content of a textfield into the url? eg. <div class="events"> <input type="hidden" name="elected_id2" value="<?php echo "$_POST[elected_id]"; ?>"> Cell: <input type='text' size="15" name='cell'><br /> <center>[b]<a href="vote1.php?elected_id=<?php echo "$_GET[elected_id]"; ?>&cell=<?php echo "$_GET[cell]"; ?>"><img src="images/nextbut.gif" value="vote"></a>[/b]</center> </div> Quote Link to comment Share on other sites More sharing options...
Bricktop Posted September 21, 2009 Share Posted September 21, 2009 Hi DarkPrince2005, The $_GET function, like you say, grabs the content of a URL and stores it into a defined variable. So, if my URL was: http://www.somedomain.com/script.php?&name=bob&id=100 I could use the following PHP to store the two values into variables: $name = $_GET['name']; $id = $_GET['id']; However, putting the contents of a textfield into a URL would not work for a number of reasons, if you want to pass the contents of a text field you must use the $_POST function. I hope this helps. Quote Link to comment Share on other sites More sharing options...
DarkPrince2005 Posted September 21, 2009 Author Share Posted September 21, 2009 I am basically doing a form for a mobi site, and most phones don't like the input type="image" or submit, so i'm trying to create a work around Quote Link to comment Share on other sites More sharing options...
trq Posted September 21, 2009 Share Posted September 21, 2009 Sorry but your question and latter response (along with your code) don't make much sense. Exactly what are you trying to do? Quote Link to comment Share on other sites More sharing options...
Bricktop Posted September 21, 2009 Share Posted September 21, 2009 Hi DarkPrince2005, What do you mean about phones not liking Submit? Do you mean that when a phone user clicks the submit button the script goes wrong? If so, it may be down to the way you are checking for a $_POST request. A lot of people check for post with "isset" or if($_POST['blah'] == 'blah'] but these methods can cause problems, it's best to check for a $_POST request with: if($_SERVER['REQUEST_METHOD'] == 'POST') Not sure if this would help but it might be worth considering if you are having problems with your Submit code. Quote Link to comment Share on other sites More sharing options...
DarkPrince2005 Posted September 21, 2009 Author Share Posted September 21, 2009 create pages and forms that don't make use of input types... basically set all captured data into a hyperlink and post it that way... Come on thorpe, you've givin e loads of good advice in the past. Quote Link to comment Share on other sites More sharing options...
DarkPrince2005 Posted September 21, 2009 Author Share Posted September 21, 2009 hmmmm? Bricktop.... here's my code, it's a little messy at current. <?php mysql_connect("localhost","root","") or die (mysql_error()); mysql_select_db("dbase"); //voting entry exec after user registered----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- if (isset ($_POST['register'])){ $sql1=mysql_query("insert into voters values ('','$_POST[elected_id3]','$_POST[name]','$_POST[cell2]',now())"); $sql2=mysql_query("select * from elected where elected_id like '$_POST[elected_id3]'"); $row=mysql_fetch_assoc($sql2); $count1=$row[vote_count]+1; mysql_query("update elected set vote_count=$count1 where elected_id like '$_POST[elected_id3]'"); include "inc/header.html"; echo "<div id='container1'> <div class='events-link2'><a href='events.php'><img src='images/eventsbut.gif'></a><br /><a href='vote.php'><img src='images/votebut.gif'></a><br /><a href='terms.php'><img src='images/termsbut.gif'></a></div> <div align='center' class='events'><table cellpadding='0' cellspacing='0' border='0' width='178'><tr><td><div class='padding'><p>"; echo "<div align='center'><p>Thank you for Voting! Your details have been entered into the draw to win 1 of 8 R300 Fashion vouchers.<br /><br /></p></div></td></tr></div>"; include "inc/foot.html"; exit(); } //check if user exists in database and check if cellphone number is valid-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- if (isset ($_POST['cell']) && $_POST['cell'] != ""){ $query = mysql_query("select * from voters where mobile like '$_POST[cell]'"); $row=mysql_fetch_assoc($query); $num = mysql_num_rows($query); if ($num != 0){ mysql_query("insert into voters values('','$_POST[elected_id2]','$row[name]','$row[mobile]',now())"); $sql2=mysql_query("select * from elected where elected_id like '$_POST[elected_id2]'"); $row=mysql_fetch_assoc($sql2); $count1=$row[vote_count]+1; mysql_query("update elected set vote_count=$count1 where elected_id like '$_POST[elected_id2]'"); include "inc/header.html"; echo "<div id='container1'> <div class='events-link2'><a href='events.php'><img src='images/eventsbut.gif'></a><br /><a href='vote.php'><img src='images/votebut.gif'></a><br /><a href='terms.php'><img src='images/termsbut.gif'></a></div> <div align='center' class='events'><table cellpadding='0' cellspacing='0' border='0' width='178'><tr><td><p>"; echo "<div align='center' class='padding'><p>Thank you for Voting! Your details have been entered into the draw to win 1 of 8 R300 Fashion vouchers.<br /><br /></p></div></td></tr>"; include "inc/foot.html"; exit(); } else{ $cell_number = preg_replace("/[^0-9]/", "", $_POST["cell"]); if (strlen($cell_number) == 10) { if (substr($cell_number, 0, 1) == "0") { //form if user isn't in database---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- $cell_number = "27" . substr($cell_number, 1); include "inc/header.html"; ?> <div id="container1" align="left"> <div class="events-link2"><a href="events.php"><img src="images/eventsbut.gif"></a><br /><a href="vote.php"><img src="images/votebut.gif"></a><br /><a href="terms.php"><img src="images/termsbut.gif"></a></div><div class="events"><table cellpadding='0' cellspacing='0' border='0' width='178'><tr><td><form action='<?php $PHP_SELF; ?>' method='post'><input type='hidden' name='register' value='1'><input type='hidden' name='elected_id3' value='<?php echo "$_POST[elected_id2]"; ?>'> Name: <input type='text' name='name'><br /> Cell: <input type='text' name='cell2' value='<?php echo "$_POST[cell]"; ?>'><br /> <input type='image' src='images/nextbut.gif' name='submit' value='Vote'></form><br /><br /></td></tr></div> <?php include "inc/foot.html"; } else { include "inc/header.html"; echo "<div id='container1'> <div class='events-link2'><a href='events.php'><img src='images/eventsbut.gif'></a><br /><a href='vote.php'><img src='images/votebut.gif'></a><br /><a href='terms.php'><img src='images/termsbut.gif'></a></div> <div align='center' class='events'><table cellpadding='0' cellspacing='0' border='0' width='178'><tr><td><div class='padding'>Invalid Cellphone number<br /><br /></div></td></tr>"; include "inc/foot.html"; }//end if }else { include "inc/header.html"; echo "<div id='container1'> <div class='events-link2'><a href='events.php'><img src='images/eventsbut.gif'></a><br /><a href='vote.php'><img src='images/votebut.gif'></a><br /><a href='terms.php'><img src='images/termsbut.gif'></a></div> <div align='center' class='events'><table cellpadding='0' cellspacing='0' border='0' width='178'><tr><td><div class='padding'>Invalid Cellphone number<br /><br /></div></td></tr>"; include "inc/foot.html"; }//end if?> <?php exit(); }} else if(isset ($_POST['cell']) && $_POST['cell'] == "") { include "inc/header.html"; ?><div id="container1" align="left"> <div class="events-link2"><a href="events.php"><img src="images/eventsbut.gif"></a><br /><a href="vote.php"><img src="images/votebut.gif"></a><br /><a href="terms.php"><img src="images/termsbut.gif"></a></div><div class="events"><?php echo "<table cellpadding='0' cellspacing='0' border='0' width='178'><tr><td>Invalid Cellphone number<br /><br /></td></tr><tr><td>";?> <form action="<?php $PHP_SELF; ?>" method='post'><input type="hidden" name="elected_id2" value="<?php echo "$_POST[elected_id]"; ?>"> Cell: <input type='text' size="15" name='cell' value="<?php echo "$_POST[cell]"; ?>"><br /><center><input type="image" src="images/nextbut.gif" value="Next >"></center></form> <?php echo "</div> <table cellpadding='0' cellspacing='0' width='100%' style='margin-top:15px;'>"; include "inc/foot.html"; include "inc/analytics.php"; exit(); } if (isset ($_POST['elected_id']) && $_POST['elected_id'] !=""){ include "inc/header.html"; ?> <div id="container1" align="left"> <div class="events-link2"><a href="events.php"><img src="images/eventsbut.gif"></a><br /><a href="vote.php"><img src="images/votebut.gif"></a><br /><a href="terms.php"><img src="images/termsbut.gif"></a></div><div class="events"><form action="<?php $PHP_SELF; ?>" method='post'><input type="hidden" name="elected_id2" value="<?php echo "$_POST[elected_id]"; ?>"> Cell: <input type='text' size="15" name='cell'><br /><center><input type="image" src="images/nextbut.gif" value="Next >"></center></form></div><?php } else { //create voting list and display entries randomly-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- include "inc/header.html"; echo "<div id='container1'> <div class='events-link2'><a href='events.php'><img src='images/eventsbut.gif'></a><br /><a href='vote.php'><img src='images/votebut.gif'></a><br /><a href='terms.php'><img src='images/termsbut.gif'></a></div> <div class='events'><div class='padding'>Scroll down to view picture of the finalists from our exciting shows.<br /><br /> Select your favourite and vote from the 26th October to the 8th of November & 1 of 8 R300 Fashion Vouchers Could be yours.<br /><br /> Watch this space for updates.</div><div align='center' class='vote'><br /> "; $sql = mysql_query("select * from elected where day_no not like '-1' order by rand()"); $num = mysql_num_rows($sql); if ($num > 0){ while ($row = mysql_fetch_array($sql)){ ?> <form action="<?php $PHP_SELF; ?>" method='post'> <table cellpadding="0" cellspacing="0" width="178"> <tr> <td align="center"><?php echo "<img src='$row[img_path]' align='center'>"; ?></td> </tr> <tr> <td align='center'><input type='hidden' name='elected_id' value="<?php echo "$row[elected_id]"; ?>"><input type='image' src="images/vote.gif" value='Vote'><br /><br /></td> </tr> </form> <?php } echo "</div> <table cellpadding='0' cellspacing='0' width='100%' style='margin-top:15px;'>"; include "inc/foot.html"; include "inc/analytics.php"; } else{ echo "<div align='center' class='vote'> <table cellpadding='0' cellspacing='0' width='178'> <tr> <td align='center'></td> </tr> <tr> <td align='center'><br /><br /></td> </tr> </div>"; include "inc/foot.html"; include "inc/analytics.php"; }} ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
trq Posted September 21, 2009 Share Posted September 21, 2009 create pages and forms that don't make use of input types... basically set all captured data into a hyperlink and post it that way... Come on thorpe, you've givin e loads of good advice in the past. Yeah, and if you'd post a decent description I might be able to help again. Explain the steps you are trying to make. Your code makes little sense as it is completely invalid. Quote Link to comment Share on other sites More sharing options...
DarkPrince2005 Posted September 21, 2009 Author Share Posted September 21, 2009 the page layout is basically detrmined by if statements. the firts screen gives you a bunch of images to vote on, after selecting an image it goes to the second page and asks you for your cellphone number. the third screen checks if it's a valid cellphone number and depending on that either checks the database or displays a form if it's not in the database Quote Link to comment Share on other sites More sharing options...
trq Posted September 21, 2009 Share Posted September 21, 2009 the page layout is basically detrmined by if statements. the firts screen gives you a bunch of images to vote on, after selecting an image it goes to the second page and asks you for your cellphone number. the third screen checks if it's a valid cellphone number and depending on that either checks the database or displays a form if it's not in the database That doesn't describe any problem. Quote Link to comment Share on other sites More sharing options...
DarkPrince2005 Posted September 21, 2009 Author Share Posted September 21, 2009 Most cellphones dont like the submit button or image... Quote Link to comment Share on other sites More sharing options...
Bricktop Posted September 21, 2009 Share Posted September 21, 2009 What do you mean by that though DarkPrince2005? Does the button appear? Does it not show? Does it not submit? Does it return an error message? Quote Link to comment Share on other sites More sharing options...
DarkPrince2005 Posted September 21, 2009 Author Share Posted September 21, 2009 it doesn't submit and returns an error... "Request Invalid" Quote Link to comment Share on other sites More sharing options...
Bricktop Posted September 21, 2009 Share Posted September 21, 2009 Even with the code I posted above? if($_SERVER['REQUEST_METHOD'] == 'POST') Quote Link to comment Share on other sites More sharing options...
DarkPrince2005 Posted September 21, 2009 Author Share Posted September 21, 2009 how would i incorporate that into my code? Quote Link to comment Share on other sites More sharing options...
Bricktop Posted September 21, 2009 Share Posted September 21, 2009 Change every occurence of code similar to: if (isset ($_POST['elected_id']) && $_POST['elected_id'] !="") to if($_SERVER['REQUEST_METHOD'] == 'POST') Quote Link to comment Share on other sites More sharing options...
DarkPrince2005 Posted September 21, 2009 Author Share Posted September 21, 2009 if($_SERVER['REQUEST_METHOD'] == 'POST')? How would I check what value is posted? Quote Link to comment Share on other sites More sharing options...
Bricktop Posted September 21, 2009 Share Posted September 21, 2009 Just looked through your code and notice it's full of if(isset.... statements! This is going to be tough, because of the way the code is structured it would need to be completely re-written to work with the if($_SERVER['REQUEST_METHOD'] == 'POST') method of checking for a POST request. Also, none of your POSTed data is being validated or sanitised, these values are being directly entered into your MySQL query so it's best to perform some validation/sanitisation on these values. Not sure of the best way to proceed with this, anyone else have any better ideas other than rewriting all the code? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.