PHP - Displaying "include" Page But Not The Main Page...
Hello everyone. I'm having a problem with what should be a fairly simple login system that is included on the index page of my site. Basically, it is set up to display a short form so that the user can enter his/her email address and password to log in. If there is a mistake with the email/password, it displays the same form with a notification that there was an incorrect email or password. The problem that I'm having is that when the wrong email/password is entered, the page goes to the next step of notifying the user of the incorrect information but it does not display the rest of the page that it is included on. What is happening is when the user arrives at the site it displays the index.php page, which is currently a blank page with some simple text, and the included page mentioned above. When an incorrect email/password is entered, instead of staying on the index page and displaying the included page with the login form, the user is redirected away from the index page to the included page only.
Here's my code for "head.inc.php": Code: [Select] <?php include("conf.inc.php"); // Includes the db and form info. session_start(); // Starts the session. if ($_SESSION['logged'] == 1) { // User is already logged in. $_SESSION['email'] = $email; header("Location: main.php"); // Goes to main page. exit(); // Stops the rest of the script. } else { if (!isset($_POST['submit'])) { // If the form HAS NOT been submitted. echo "<form name=\"form\" action=\"head1.inc.php\" method=\"POST\" style=\"margin-bottom:0;\">"; echo "<a href=\"signup.php\" class=\"bluelink\">Sign Me Up!</a> "; echo "<a href=\"pwordhelp.php\" class=\"bluelink\" onClick=\"return popup(this, 'notes')\">Forgot Password</a> <br>"; echo "<input type=\"text\" name=\"email\" size=\"17\" value=\"Email...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Email...') {this.value=''; this.style.color='#000000'}\"> "; echo "<input type=\"text\" name=\"pword\" size=\"17\" value=\"Password...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Password...') {this.value=''; this.style.color='#000000'; this.type='password'}\"> "; echo "<input type=\"submit\" name=\"submit\" value=\"Submit\"> "; echo "</form>"; } else { // If the form HAS been submitted $email = form($_POST['email']); $pword = md5($_POST['pword']); // Lightly encrypts the password. $q = mysql_query("SELECT * FROM `signin` WHERE email = '$email' AND pword = '$pword'") or die (mysql_error()); // mySQL query $r = mysql_num_rows($q); // Checks to see if anything is in the db. if (!$r) { // There is something in the db. The username/password match up. echo "<form name=\"form\" action=\"head1.inc.php\" method=\"POST\" style=\"margin-bottom:0;\">"; echo "<a href=\"signup.php\" class=\"bluelink\">Sign Me Up!</a> "; echo "<a href=\"pwordhelp.php\" class=\"bluelink\" onClick=\"return popup(this, 'notes')\">Forgot Password</a> <br>"; echo "<font color=\"#FF0000\"><strong>Incorrect Email or Password.</strong></font> "; echo "<input type=\"text\" name=\"email\" size=\"17\" value=\"Email...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Email...') {this.value=''; this.style.color='#000000'}\"> "; echo "<input type=\"text\" name=\"pword\" size=\"17\" value=\"Password...\" style=\"color: #999999\" onfocus=\"if (this.value == 'Password...') {this.value=''; this.style.color='#000000'; this.type='password'}\"> "; echo "<input type=\"submit\" name=\"submit\" value=\"Submit\"> "; echo "</form>"; } else { // If the username/password is invalid $_SESSION['logged'] = 1; // Sets the session. $_SESSION['email'] = $email; header("Location: main.php"); // Goes to main page. exit(); // Stops the rest of the script. } } } ?> Here's the code for "index.php": Code: [Select] <?php include("head.inc.php"); echo "This is the index page"; ?> Any ideas on how to stop the redirection from the index page when the incorrect info is entered? Similar TutorialsI'm a very new PHP user (as in, I just started today) and need to make a set of navigation buttons which will take the user to "next" or "previous" pages. I assume that the $_GET function is involved, but I don't know how to do it. It needs to work like this: If the URL looks like "http://website.com/page1.php" I need the "next" button (a href image) to change it to "/page2.php", and while on page 2, for the "previous" button to take the user to "/page1.php" and so forth. How can I cause the page number to increment or decrease respective to the href image being clicked? This include does not work. I presume due to the ? in it. <?php include("signin-redirect.php?page=my-account.php");?> It works as just signin-redirect.php but I want to include the ?page=my-account.php on the end of it. Thanks Can someone please help me with an array problem i can not figure out. I need the array to be numbered from 1 to how ever many fields that are needed in the form and have a mysql field name and the title of the field also in the array. 1, "mysql_field_name", "Title of form field" 2, "", "" and so on then the form will be shown based on the array. I have the following draft code which I am working with. any suggestions on how i may do this array ? Code: [Select] <?php $options = array( '1'=> array('fieldtext'=>'option1', 'mysqlfield'=>'option1'), '2'=> array('fieldtext'=>'option2', 'mysqlfield'=>'option2'), '3'=> array('fieldtext'=>'option3', 'mysqlfield'=>'option3'), '4'=> array('fieldtext'=>'option4', 'mysqlfield'=>'option4'), ); // $options = array(1 => "option1", "option2", "option3", "option4"); // the line above works but i want to include the name of the mysql field as well. $userid = 1; ?> <div style="align: center; margin: 12px; font-family:Tahoma;"> <br><br><?php if ($_POST['Update'] != "Update") { // check if form submitted yet, if not get data from mysql. $res = db_query("SELECT * FROM `users` WHERE `userid` = '" . $userid . "'"); foreach($options as $key => $value) { $_POST[$key] = mysql_result($res, 0, $value); } $ok_to_update = "no"; } elseif ($_POST['Update'] == "Update") { // check if form submitted yet, if so get POST data. // error checking // foreach($options as $key => $value) { // $_POST[$i] = ""; // } $ok_to_update = "yes"; } if ($_POST['Update'] == "Update" && $ok_to_update == "yes") { // $res = db_query("INSERT INTO `users` () VALUES ()"); // add user details to database. ?><p><br><br><br>Thank you for updating</p><?php } else { ?><form name="form1" method="post" action=""> <?php foreach($options as $key => $value) { ?><p><?php echo($value); ?>: <input type="text" name="<?php echo($key); ?>" value="<?php echo($_POST[$key]);?>"></p> <?php } ?> <input name="Update" type="submit" value="Update"> </form> <?php } ?> </div> This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=317771.0 Hello. I hope one of the PHP/HTML gurus here can help me. I have a web page that has been altered a bit to add some Google Analytics stuff and I've moved it to a 2nd directory. The original one works fine, the 2nd one won't post the form when I click the submit button. 1st URL https://www.theneutralizer.info/neutralizer 2nd URL: https://www.theneutralizer.info/neutralizer2 I have changed the action property to the correct script, and it does exist. But the problem is when clicking the button nothing happens. Anyone have any ideas? I can send the PHP code if needed, but since it's HTML output, it should work the way it is displayed in the browser. David Hello! I am executing an external command from a PHP script, using the exec function. Since this program can take more than 1-2 minutes to run, I thought I should use a "Loading page...please wait". What I need is to be able to get the process id from the external program that is being run and, when this finishes, I'll start outputting the results. Is there a way to do this? Hi, bit stuck on how to find and replace "<" and ">" with "<" and ">". I basically have a database record that outputs to screen and I need the code in the <code> tags to be rendered to the screen. I therefore need it to go through the whole array variable from the db and change the symbols just inside the code tags. Please be aware that the code tags might happen more than once here's an example below Code: [Select] <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1> </code> the desired output would be: <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> <p>blah blah blah</p> <p>blah blah blah</p> <p>blah blah blah</p> <code> <h1>hello</h1 </code> help on this would be great Cheers Rob Im dealing with html links in a database where I need to execute a small piece of php code. Well mysql doesnt execute php code thats held in a table. The easiest way for me to do this is just add the links without the code, & set up a function that will replace anything I set to for example in my case a link lookin like this: http://mysite.com/index.php?page=offers&blah=blah&sid= needs to look like this; http://mysite.com/index.php?page=offers&blah=blah&sid=<?php echo $_SESSION['login']; ?> so I would need a function like <?php $replace('sid=','sid=<?php echo $_SESSION['login'];?> ?> something like that. And I know its possible & I could create a function like this but honestly right now I am so tired after working 12 hours im lazy dont want to think to hard while I know there are a lot of people out there that have a function like this already. If you dont have one & dont feel like writing one for me could you atleast point me in the right direction so I dont have to think to hard?! Thanks!! Hi, I want something this to be done. When a user tries to logged into the site by entering wrong password, the error message like " Invalid username or password" should be displayed in the same page. I tried following coding. But it shows the error message in a different page. $connect=mysql_connect('localhost','root',''); mysql_select_db('bank',$connect); $username= $_POST['username']; $password= $_POST['password']; $result = mysql_query ('select * from users where username = "' . $_POST['username'] . '" and password = "' . $_POST['password'] . '"'); while($row=mysql_fetch_row($result)){ $user_type=$row[4]; } session_start(); session_register("user_type"); $_SESSION["user_type"]=$user_type; if($user_type=='T'){ header('Location:teller_page.php'); }else if($user_type=='AO'){ header('Location:accofficer_page.php'); }else if($user_type=='AS'){ header('Location:accsup_page.php'); }else if($user_type=='LS'){ header('Location:loansup_page.php'); }else if($user_type=='CS'){ header('Location:cashsup_page.php'); }else{ header('Location:try_again.php'); } I have page for checkout ( shopping cart) When person leaves a page I have a javascript called which gives alert Are you sure you want to leave this page? OK and Cancel button Which works fine However I donot want this alert when shopping cart is empty or I want this alert only when the page is left with entries in shopping cart Hello I use this code to display popup login when user to clicked on a "proceed to checkout" button in the cart page (woocomerce) <?php function woocommerce_button_proceed_to_checkout() { $checkout_url = WC()->cart->get_checkout_url(); ?> <div <?php echo mf_get_option( 'login_reg_popup' ) ? 'data-toggle="modal" data-target="#login-modal"' : null; ?>> <a class="checkout-button button alt wc-forward" href="<?php echo ! mf_get_option( 'login_reg_popup' ) ? wc_get_page_permalink( 'myaccount' ) : '#'; ?>" class="checkout-button button alt wc-forward"><?php _e( 'اقدام به پرداخت', 'woocommerce' ); ?></a> <?php }
But after login, I want the user to be redirected to the "checkout" page if it is on the cart page
I found the following code but I couldn't put it in the code above <?php //redirect to your "current" page wp_redirect( $_SERVER["HTTP_REFERER"] ); // redirect to the "checkout" page function wpse_131562_redirect() { if (! is_user_logged_in() && (is_woocommerce() || is_cart()) ) { // feel free to customize the following line to suit your needs wp_redirect(site_url('checkout/')); exit; } } add_action('template_redirect', 'wpse_131562_redirect');
Hi, Having issues with my script: It lists people in different departments, but i want the height of my overall table to be 100%, so that this table fills the entire screen. I'm using the following code: Code: [Select] <html> <!-- <body style="overflow: hidden"> --> <span style="font:bold 1px arial;"> <table style="float: left; height: 100%; width: 100%px; border: 1px solid red"> <?PHP include("config.php"); $result = mysql_query("SELECT * FROM medarbejder ORDER BY medarbejder"); //echo "$result"; echo "<tbody>"; echo "<TABLE float:left height:100% border=0 width=100% >"; // <!--Start IT-afdeling--> echo"<td bgcolor=#7FFF00> <span style=font-size:48px;> <div align=center> IT-Afdelingen </div> </span> </td>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; IF ($row['status']==1 && $row['afdeling']==2) { echo "<td width=100% height=100% bgcolor=#FFFFFF> <span style=font-size:32px;> " . $row['medarbejder'] . " (til stede) </span> </td>"; } elseif ($row['status']!=1 && $row['afdeling']==2) { echo "<td width=100% height=100% bgcolor=#FF0000> <span style=font-size:32px;color=white;> " . $row['medarbejder'] . " (ikke til stede) </span> </td>"; } echo "<td>"; echo "</td>"; //echo "<br>"; echo "</tr>"; } // <!--Start Marketing-afdeling--> $result = mysql_query("SELECT * FROM medarbejder ORDER BY medarbejder"); echo"<td width=100% height=100% bgcolor=#37FDFC><span style=font-size:48px;> <div align=center> Kommunikation og marketing </div> </span> </td>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; IF ($row['status']==1 && $row['afdeling']==1) { echo "<td width=100% height=100% bgcolor=#FFFFFF> <span style=font-size:32px;> " . $row['medarbejder'] . " (til stede) </span> </td>"; } elseif ($row['status']!=1 && $row['afdeling']==1) { echo "<td width=100% height=100% bgcolor=#FF0000> <span style=font-size:32px;color=white;> " . $row['medarbejder'] . " (ikke til stede) </span> </td>"; } echo "<td>"; echo "</td>"; //echo "<br>"; echo "</tr>"; } // <!--Start Skema-afdeling--> $result = mysql_query("SELECT * FROM medarbejder ORDER BY medarbejder"); echo"<td width=100% height=100% bgcolor=#FF6600> <span style=font-size:48px;> <div align=center> Skema-lægning </div> </span> </td>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; IF ($row['status']==1 && $row['afdeling']==3) { echo "<td width=100% height=100% bgcolor=#FFFFFF> <span style=font-size:32px;> " . $row['medarbejder'] . " (til stede) </span> </td>"; } elseif ($row['status']!=1 && $row['afdeling']==3) { echo "<td width=100% height=100% bgcolor=#FF0000> <span style=font-size:32px;color=white;> " . $row['medarbejder'] . " (ikke til stede) </span> </td>"; } echo "<td>"; echo "</td>"; //echo "<br>"; echo "</tr>"; } echo "</table>"; echo "</tbody>"; mysql_close($con); ?> </span> </html> I have been searching around, but haven't found a way to apply this to my own code. Any help is much appriciated. For example if I wanted to let any user to be able to add a page to my site where they can title it and give a description of it or whatever they like to it, what would the code be for doing this type of thing? I have a menu on my site on each page, I want to put it in it's own menu.php file but i'm not sure how to set the class="active" for whatever page i'm on. Here is my code:<?php if ($url == $curpage) { $class = "active"; } else { $class = "in-active"; } ?> <ul id="top-navigation"> <li><a href="./" class="<? echo $class ?>">Homepage</a></li> <li><a href="?p=MM" class="<? echo $class ?>">Maintenance Mode</a></li> <li><a href="?p=UCP" class="<? echo $class ?>">User CP</a></li> <li><a href="?p=LYRICS" class="<? echo $class ?>">Lyrics</a></li> <li><a href="?p=SB1" class="<? echo $class ?>">Sidebar 1</a></li> <li><a href="?p=SB2" class="<? echo $class ?>">Sidebar2</a></li> <li><a href="?p=SHP" class="<? echo $class ?>">Site HomePage</a></li> <li><a href="?p=EDTpst" class="<? echo $class ?>">post.php</a></li> <li><a href="?p=EDTUCP" class="<? echo $class ?>">UCP.php</a></li> <li><a href="?p=EDTtimer" class="<? echo $class ?>">timer.php</a></li> </ul> I want $curpage to be the only page I'm on not all of the pages. How would I do this would it be like $url = (isset($_GET['p']) ? $_GET['p'] : 'home'); $s1 = "main" ; $s2 = "MM" ; $s3 = "UCP" ; $s4 = "LYRICS" ; //cont. . . if ($url == $s1) { $class = "active"; } elseif ($url == $s2) { $class = "active"; } elseif ($url == $s3) { $class = "active"; } elseif ($url == $s4){ $class = "active"; } //cont. . . Hello guys. I'm so sorry if y'all feel like I'm bothering with this noob threads. I'm making a dynamic stats signature using info my mysql. It currently is working like its supposed to. But i want to have an image of a player's stats of each player. For example. A player types in the URL: www.test.com/stats.php?user=Username Now, when a player accesses that url, the default stats image will be show, and for stats. I want the "Username" to be the query and that gets the info. For example: mysql_query("SELECT * FROM players WHERE user = '$usernamehere' How can i detect the url username though? This is my current set up: mysql_query("SELECT * FROM players WHERE user = 'test' - It's working. But i want to use variable and give that "Username" ( From url ) it's stats. Here's my current code: <?php $imagepath="css/images/dog.JPG"; $image=imagecreatefromjpeg($imagepath); $imgheight=imagesy($image); $color=imagecolorallocate($image, 255, 255, 255); include("config.php"); $result = mysql_query("SELECT * FROM playerinfo WHERE user = 'Test'", $connect); while($myrow = mysql_fetch_row($result)) { // Not working properly. imagestring($image, 5, 50, $imgheight-50, $myrow[0], $color); imagestring($image, 3, 30, $imgheight-30, $myrow[2], $color); } // This line works like it should: //imagestring($image, 5, 50, $imgheight-50, "Using it like this works!", $color); header('Content-Type: image/jpeg'); imagejpeg($image); ?> Hi guys I am a newbie with PHP and I have been trying to solve this problem for 3 days.. Ive set up a booking form on my website to be sent directly to my email once the client clicked on the send button.. The problem I am having while checking these pages on wamp is that the booking form is ok but when I click on the send button the following message error appears "Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\fluffy_paws\booking_form2.php on line 27" When I check online I have this message "500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed." Are my codes wrong??? My webhosting is Blacknight.com , Im on Windows Vista, my internet is a dongle with O2 ireland Thanks for your help! I am come across a very odd situation when I include a connnet.php file. For some reason it messes up the layout of the page. However when I enter the connect code onto the page it looks fine. Code: [Select] include("connect.php"); What is also strange is that when I include the header and footer it works fine. For some reason it is just when I include the connect.php file. Is this because it is above the CSS file? Code: [Select] include("header.php"); Code: [Select] include("footer.php"); Hi guys I'm struggling a bit, I need to replace a word that occurs multiple times in text with an array("up","down","forward","backwards") of words. $find = "left"; $replace = array("up","down","forward","backwards"); $text = "left left left left"; echo str_replace($find,$replace,$text); The Output is: array array array array Did try this with a foreach statement as well, but no luck. Is there a better way of doing this? Thanks cant work out this mysql syntax error "operation":"medupdate","medid":"","name":"ibo","medyear":"5","medmonth":"21","medday":"1","recuser":1,"SuccFail":"fail","SuccFailMessage":"error occured You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '''WHERE med_id=' at line 2","ResultData":""} Code: [Select] $sql="update metodology set med_description='".$req['name']."', med_year='".$req['medyear']."', med_month='".$req['medmonth']."', med_day='".$req['medday']."', med_recorddate= now(), med_recorduserid= 1'"; $sql.= " WHERE med_id=".$req['medid']; This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=342600.0 |