Leftfield Posted February 9, 2011 Share Posted February 9, 2011 Hi all I'm new to PHP so i might ask easy stuff Here is my Scenario I click a button .. this work fine But in the php code that runs after the button is clicked i need to change the Website uri (link) to something like this after button postback index?name=value How am i gonna do this . I tried header function but it did not work well Any suggestion please Link to comment https://forums.phpfreaks.com/topic/227171-change-uri/ Share on other sites More sharing options...
BlueSkyIS Posted February 9, 2011 Share Posted February 9, 2011 Quote Any suggestion please tell us what happened when you tried header and post code. Link to comment https://forums.phpfreaks.com/topic/227171-change-uri/#findComment-1171869 Share on other sites More sharing options...
Leftfield Posted February 9, 2011 Author Share Posted February 9, 2011 Well nothing happened the uri stayed the same here is my code header('Location:index.php?name=Next'); What i want to do is pass that next value into my button value but the uri did not change Thanks Link to comment https://forums.phpfreaks.com/topic/227171-change-uri/#findComment-1171925 Share on other sites More sharing options...
Leftfield Posted February 10, 2011 Author Share Posted February 10, 2011 Does anyone have a awnser Link to comment https://forums.phpfreaks.com/topic/227171-change-uri/#findComment-1172194 Share on other sites More sharing options...
kenrbnsn Posted February 10, 2011 Share Posted February 10, 2011 You have to show us more of your code and exactly what you are trying to accomplish. Ken Link to comment https://forums.phpfreaks.com/topic/227171-change-uri/#findComment-1172199 Share on other sites More sharing options...
Leftfield Posted February 10, 2011 Author Share Posted February 10, 2011 Ok here is the code it runs on button click What i want to do is chage the uri on button click <form action="<?=$_SERVER['PHP_SELF'];?>" method="post"> <?php /* * Created on 2011/02/01 * Created by Marinus */ //Step 1 date validation// if(isset($_POST['submit'])) { $startDate = strtotime($_POST['startdate']); $endDate = strtotime($_POST['enddate']); if($startDate != false && $endDate != false){ $startDate = date("Y-m-d",$startDate); $endDate = date('Y-m-d',$endDate); SetDates($startDate,$endDate); } else { echo "Please select both dates!"; } } function SetDates($start,$end){ $connection = mysql_connect('*****', '*****', '******') ; mysql_select_db('OnlineBookings'); $query = //Hidin $result = mysql_query($query); $nonAvailableRooms = ""; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $nonAvailableRooms .="'". $row['Code'] ."',"; } if($nonAvailableRooms == "") { ShowAllRooms(); } else { Codes($nonAvailableRooms); } echo mysql_error(); } function Codes($findedCodes){ $findedCodes = substr($findedCodes, 0, -1); $query = "SELECT (Code),Description,Notes FROM Item WHERE code NOT IN ($findedCodes)"; $result = mysql_query($query); $i = 0; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $i++; echo "<div style='border:1px solid black'><a title=\"".$row['Notes']." href=\"rooms/".$row['Code'].".jpg\"><img height=120px width=140px src=\"rooms/".$row['Code'].".jpg\" border=0></a>"; echo "<br/>Room Code :{$row['Code']} <br> Room Description : {$row['Description']} <br/> <input id='chk_$i' type='checkbox' name='option$i' onclick='showValue(this);' value='{$row['Code']}'><br> Book this room. </div>" ; } if($i == 0){ echo "There is no available rooms."; } else { header('index.php?name=Next'); } } function ShowAllRooms() { $query = "SELECT * FROM item"; $result = mysql_query($query); $i = 0; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $i++; echo "<div style='border:1px solid black'><a href=\"rooms/".$row['Code'].".jpg\"><img height=120px width=140px src=\"rooms/".$row['Code'].".jpg\" border=0></a>"; echo "<br/>Room Code :{$row['Code']} <br> Room Description : {$row['Description']} <br/><input id='chk_$i' type='checkbox' name='option$i' onclick='showValue(this);' value='{$row['Code']}'>Book this room.<br> </div>" ; } header('index.php?name=Next'); } //Step 2 the code to run after dates is valid ?> So when all is validated i want the button to chage uri to header('index.php?name=Next'); and then change button value to Next or $_SELF or some vairable that i can run to change button click procedure todo step 2 <input id="Submit" type="submit" name="submit" value="<?php ?>"/></div> Hope someone can help me Thanks Link to comment https://forums.phpfreaks.com/topic/227171-change-uri/#findComment-1172200 Share on other sites More sharing options...
trq Posted February 10, 2011 Share Posted February 10, 2011 The header function is used to set http headers. You want to set the location header. header('Location: index.php?name=Next'); Also, the http states that the location header should be a complete uri, this includes the domain name, not just a relative uri. (Most browsers will handle it either way, but best to be safe than sorry) So, you'll want something like.... header('Location: yourdomain.com/index.php?name=Next'); Link to comment https://forums.phpfreaks.com/topic/227171-change-uri/#findComment-1172214 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.