PHP - Modify Mysql Tables Using Form Back-end Of Cms
Hi am in processes of making a bespoke CMS for a project in uni am having a problem with my scrip basically i have three php files i have content which echos out the database tables i wish to edit with a link to an update_content page when u click on that it bring u too update_content.php which allows the user to modifier the content in the tables but when i hit update am getting a Parse error: syntax error, unexpected T_IF in line 4 of my update_ac file any help would be great
cheers richie <?php require("includes/connection.php") // If form button has been pressed then do the following if(isset($_POST['update'])){ // Get id of post $id = $_GET['id']; $header = $_POST['header']; $content = $_POST['content']; // Update database table $query = "UPDATE pages SET header = '$header', content = '$content' WHERE id = '$id'"; $result = mysql_query($query); if ($result){ echo "Successfully edited entry"; } else { echo "There was error editing entry"; } } ?> Similar TutorialsCannot modify header information - headers already sent by (output started at ) on line 179 I labeled 179 its at the bottom. I understand this means its already generating the html but not how or where. A solution would of course be nice but if some one could tell me even how to figure it out it would be great. Code: [Select] <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "test@test.com"; $email_subject = "$mile"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } /*"trail_section_mile", float dash "trail_section_name", #9()alphanumeric "name", "date"auto date "email",same "telephone" same "trail_condition" no validation just sanitize size limit "attention_area" no validation just sanitize size limit "under_20" no validation just sanitize size limit "_20_54" no validation just sanitize size limit "_55_over" no validation just sanitize size limit */ if(!isset($_POST['trail_section_mile']) ) { died('1'); } if(!isset($_POST['trail_section_name']) ) { died('2'); } if(!isset($_POST['name']) ) { died('3'); } if(!isset($_POST['email']) ) { died('4'); } if(!isset($_POST['telephone']) ) { died('5'); } if(!isset($_POST['trail_condition']) ) { died('6'); } if(!isset($_POST['attention_area']) ) { died('7'); } if(!isset($_POST['under_20']) ) { died('8'); } if(!isset($_POST['_20_54']) ) { died('9'); } if(!isset($_POST['_55_over']) ) { died('0'); } if(!isset($_POST['total_hours']) ) { died('011'); } //comments field is a honeypot require ('Validate.php'); $email = $_REQUEST['email']; $validate = new Validate(); if (!Validate::email($email, array('check_domain' => true, 'use_rfc822' =>true))) { echo "Invalid email"; } $trail_section_mile = $_POST['trail_section_mile']; // required $trail_section_name = $_POST['trail_section_name']; // required $name = $_POST['name']; // required $email = $_POST['email']; // required $telephone = $_POST['telephone']; // required $trail_condition = $_POST['trail_condition']; // required $attention_area = $_POST['attention_area']; // required $under_20 = $_POST['under_20']; $_20_54 = $_POST['_20_54']; $_55_over = $_POST['_55_over']; $_55_over = $_POST['total_hours']; // required if (preg_match('/[\d\D\b\B\s\S]/', $comments)) { echo "nope"; } if (!preg_match("/([\w\.\#\-\,]{1,30})+/", $trail_section_mile)) {echo "please enter the section mile markers again only numbers, decimals dashes and # are aloud"; } if (!preg_match("/[a-z'-]+/", $trail_section_name)) { echo "Try your last name again."; } if (!preg_match("/[a-z'-]+/", $name)) { echo "please re-type your address."; } if (!preg_match("/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/i", $telephone)) { echo "Something is wrong with the phone number you intered. Please enter your area code first then ther rest of tyour number."; } if (( preg_match( "/[\r\n]/", $first_name ) || preg_match( "/[\r\n]/", $email ) || preg_match( "/[\r\n]/", $last_name) ) || preg_match( "/[\r\n]/", $state)) { echo "nope"; } $trail_section_mile = strip_tags($trail_section_mile); $trail_section_name = strip_tags($trail_section_name); $name =strip_tags($name); $email = strip_tags($email); $telephone = strip_tags($telephone); $trail_condition = strip_tags($trail_condition); $attention_area = strip_tags($attention_area); $under_20 = strip_tags($under_20); $_20_54 = strip_tags($_20_54); $_55_over = strip_tags($_55_over); $total_hours = strip_tags($total_hours); $trail_section_mile = htmlspecialchars($trail_section_mile); $trail_section_name = htmlspecialchars($trail_section_name); $name = htmlspecialchars($name); $email = htmlspecialchars($email); $telephone = htmlspecialchars($telephone); $trail_condition = htmlspecialchars($trail_condition); $attention_area = htmlspecialchars($attention_area); $under_20 = htmlspecialchars($under_20); $under_20 = htmlspecialchars($_20_54); $_55_over = htmlspecialchars($_55_over); $total_hours = htmlspecialchars($total_hours); $email_message = "Form details below.\n\n"; $email_message = date("m/d/Y") . "\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Trail Section Mile Markers: ".clean_string($trail_section_mile)."\n"; $email_message .= "Trail Section Name : ".clean_string($trail_section_name)."\n"; $email_message .= "Reported by: ".clean_string($name)."\n"; $email_message .= "Email Address: ".clean_string($email)."\n"; $email_message .= "Telephone Number: ".clean_string($telephone)."\n"; $email_message .= "General Trail Condition : ".clean_string($trail_condition)."\n"; $email_message .= "Mile #/Problem/Suggested Improvements: ".clean_string($attention_area)."\n"; $email_message .= "Volunteers Under Age 20 #Males/#Females/Ethnicity/Name: ".clean_string($under_20)."\n"; $email_message .= " Volunteers Ages 20 to 54 #Males/#Females/Ethnicity/Name: ".clean_string($_20_54)."\n"; $email_message .= "Volunteers Age 55+ #Males/#Females/Ethnicity/Name: ".clean_string($_55_over)."\n"; $email_message .= "Total Volunteer Hours: ".clean_string($total_hours)."\n"; $about ="Maintenance Report from" .$name. "/n"; // create email headers $headers = 'Subject : '.$about."/r/n" .'From: '.$email."\r\n" .'Reply-To: '.$email."\r\n" . 'X-Mailer: PHP/' . phpversion(); header("Location: oht/maintenance/maintenance-report/thank-you/"); //line 179 @mail($email_to, $email_subject, $email_message, $headers); ?> <?php } ?> MOD EDIT: [code] . . . [/code] BBCode tags added. The Script:
<?php include($_SERVER['DOCUMENT_ROOT'] . "/gallerysite/header.php"); ?> <?php include($_SERVER['DOCUMENT_ROOT'] . "/gallerysite/connect.php"); ?> <?php if(isset($_GET['thread_id'])) { $tqs = "SELECT * FROM `thread` WHERE `id` = '" . $_GET['thread_id'] . "'"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); $row = mysqli_fetch_assoc($tqr); ?> <div class="div"> <h1>Admin Modify</h1> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="text" name="title" value="<?php echo $row['title']; ?>"/><br/> <textarea type="text" name="caption"><?php echo $row['caption']; ?></textarea> <input type="submit" name="admin_update" value="Update" /> </form> </div> <?php // This prints e.g.: // 47 echo "The Thread ID: "; echo $_GET['thread_id']; if(isset($_POST['admin_update'])){ $tqs = "UPDATE `thread` SET `title` = '" . $_POST['title'] . "', `caption` = '" . $_POST['caption'] . "' WHERE `id` = '" . $_GET['thread_id'] . "'"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); } } ?> <?php include($_SERVER['DOCUMENT_ROOT'] . "/gallerysite/footer.php"); ?>I do not see why this is not working. The "UPDATE" SQL statement has worked without the "WHERE" part and modified all of the posts. (With this the database connection works too.) Though, this statement does work in PhpMyAdmin: UPDATE `thread` SET `title` = 'testing', `caption` = 'testing' WHERE `id` = '47';I added the "WHERE" part to the script and now it is not modifying the text in the table anymore, basically the "updates" do not happen. What could be the issue here? Any suggestions are much appreciated. Also, I have used this way of "syntax style" in PHP, perhaps somebody could be modifying the "UPDATE" SQL statement into a different syntax style so I can try it out, I would much appreciate it. I would also like to ask how the "syntax style" I have used is and if it can be better than this? Edited by glassfish, 20 October 2014 - 05:52 AM. Hi friends. I want to php code on how i can modify my retrieved database values from a particular table before echoing out. Please could you help me correct the code. Or if there is any better way of editing loop datas before printing out, please kindly drop the code for me. Thanks <?php please if there is any better way of editing loop values from mysql database before printing out, please kindly drop the code for me. Thanks This portion is kind of stumping me. Basically, I have a two tables in this DB: users and users_access_level (Separated for DB normalization) users: id / username / password / realname / access_level users_access_level: access_level / access_name What I'm trying to do, is echo the data onto an HTML table that displays users.username in one table data and then uses the users.access_level to find users_access_level.access_name and echo into the following table data, I would prefer not to use multiple queries if possible or nested queries. Example row for users: 1234 / tmac / password / tmac / 99 Example row for users_access_level: 99 / Admin Using the examples above, I would want the output to appear as such: Username: Access Name: Tmac Admin I am not 100% sure where to start with this, but I pick up quickly, I just need a nudge in the right direction. The code I attempted to create just shows my lack of knowledge of joining tables, but I'll post it if you want to see that I did at least make an effort to code this myself. Thanks for reading! hi i have generated a product list from a mysql table called product_list, once i enter a new product in to the table the product will be shown in the generated list and the list will grow and the table grows. and i want to allow user the edit/delete/save the products from the generated table, i have no idea how to do it and what is the algorithmic idea to do it so. here is the php and the html code. <!--Body container for creating a new product in to the list--> <div class="body_orderviewform"> <form name="form1" method="post" action="upload_file.php" enctype="multipart/form-data"> <p> <label for="user_id">User ID:</label> <input type="text" name="user_id" id="user_id"> <label for="customer_name">Customer Name:</label> <input type="text" name="customer_name" id="customer_name"> <label for="customer_family">Customer_family</label> <input type="text" name="customer_family" id="customer_family"> <label for="freelancer_name">Purchaser:</label> <input name="freelancer_name" type="text" id="freelancer_name"> <? if (isset($_COOKIE['picAdd'])) echo $_COOKIE['picAdd'];?> </p> <!------------------------------------------------------------------------------------------------------- for generating the list --> <div class="div.neworder_list" > <div class="div.neworder_listheader" align="center"> <table width="637" border="1" > <tr> <td width="193"><label for="link">link:</label> <label for="link_new"></label> <input type="text" name="link_new" id="link_new"></td> <td width="202"><label for="unitprice">Unit Price:</label> <label for="Unit_price_new"></label> <input type="text" name="Unit_price_new" id="Unit_price_new"></td> <td width="220"><label for="qty">Quantity:</label> <label for="quantity_new"></label> <input type="text" name="quantity_new" id="quantity_new"></td> </tr> <tr> <td><label for="express">Express Fee:</label> <label for="express_new"></label> <input type="text" name="express_new" id="express_new"></td> <td><label for="commission_new">Commission:</label> <input type="text" name="commission_new" id="commission_new"></td> <td><label for="customer_description">Description</label> <label for="description_new"></label> <textarea name="description_new" id="description_new" cols="45" rows="5"></textarea></td> </tr> <tr> <td> </td> <td colspan="2">Picture Upload: <input type="hidden" name="<?php echo ini_get("session.upload_progress.name");?>" value="123" /> <input name="file" type="file" autofocus="autofocus"/> <br /> </tr> <tr> <td colspan="3"><input type="reset" name="reset" id="reset" value="Reset"> <input type="submit" name="submit" id="submit" value="Submit The Product"></td> </tr> </table> </form> </div> <div class="neworder_listview"> <p> <form action="" method="post" name="list"> <input type="submit" name="del" id="del" value="Save"> <input type="submit" name="save" id="save" value="Del"> </p> <table width="1022" border="1" align="center"> <tr> <th width="24" scope="col"> </th> <th width="24" scope="col">Row#</th> <th width="137" scope="col">Manager</th> <th width="137" scope="col">Purchaser Desc</th> <th width="40" scope="col"><p>Link</p> <p>/Ссылки</p></th> <th width="53" scope="col">ФОТО</th> <th width="50" scope="col">Unit Price/Цена за еденицу товара</th> <th width="46" scope="col">Quantity/ Кол-во</th> <th width="138" scope="col">Total Unit Price/ Общая цена</th> <th width="89" scope="col">Express/Доставка по Китаю</th> <th width="119" scope="col">Description/Описание</th> <th width="89" scope="col">ADDITIONAL LINKS/ЗAMЕНЫ</th> </tr> <?php $username = "my username"; $password = "my pass"; $database = "userinfo"; $link = mysql_connect("localhost", "$username", "$password"); if(!$link) {echo("Failed to establish connection to mysql server"); exit();} $status = mysql_select_db($database); $query = "SELECT * FROM order_list"; $result = mysql_query($query); $num = mysql_num_rows($result); $i=0; while ($i < $num) { $field1_name=mysql_result($result,$i,"admin_st"); $field2_name=mysql_result($result,$i,"freelancer_st"); $field3_name=mysql_result($result,$i,"link"); $field4_name=mysql_result($result,$i,"picture"); $field5_name=mysql_result($result,$i,"unitprice"); $field6_name=mysql_result($result,$i,"qty"); $field7_name=mysql_result($result,$i,"express"); $field8_name=mysql_result($result,$i,"customer_st"); $i++; } ?> <?php $i=0; $row=1; while ($i < $num) { $f1=mysql_result($result,$i,"admin_st"); $f2=mysql_result($result,$i,"freelancer_st"); $f3=mysql_result($result,$i,"link"); $f4=mysql_result($result,$i,"pic_address"); $f5=mysql_result($result,$i,"unitprice"); $f6=mysql_result($result,$i,"qty"); $f7=mysql_result($result,$i,"express"); $f8=mysql_result($result,$i,"customer_st"); $totao_unit_price = $f5*$f6; ?> <tr> <td><input type="checkbox" name="del_chbox" id="del_chbox"> <td><p><font face="Arial"><input name="row_txtbox" type="text" id="row_txtbox" size="2" value="<?php echo $row; ?>"></font></td> <td><p><font face="Arial"> <textarea name="manager_txtbox" cols="10" id="manager_txtbox"><?php echo $f1; ?></textarea></font></td> <td><p><font face="Arial"> <textarea name="purchase_txtbox" cols="10" id="purchase_txtbox"><?php echo $f2; ?></textarea> </font></td> <td><font face="Arial"><a href="<?php $f3 ?>" target="_blank"><?php echo $f3; ?></a></font></td> <td><font face="Arial"><img src="<?php echo $f4;?>" width="100" align="middle"100></font></td> <td><font face="Arial"><input name="unitprice_txtbox" type="text" id="unitprice_txtbox" size="2" value="<?php echo $f5; ?>"></font></td> <td><font face="Arial"> <input name="qty_txtbox" type="text" id="qty_txtbox" size="2" value="<?php echo $f6; ?>"></font></td> <td><p><font face="Arial"><?php echo $totao_unit_price; ?></font></td> <td><p><font face="Arial"><input name="express2" type="text" id="express3" size="2" value="<?php echo $f7; ?>"></font></td> <td><p><font face="Arial"> <textarea name="custdesc_txtbox" cols="20" id="custdesc_txtbox"><?php echo $f8; ?></textarea></font></td> <td><input name="express2" type="text" id="express3" size="2" value="<?php echo "new link" ?>"></td> </tr> <p> <?php $i++; $row++; } ?> </table> </p> <p> </p> </form> Ok so I have this site where I'm posting a message to my Database. But when I go to pull the message from the MYSQL DB it's one long sentence. Any suggestions? I have these two tables...
schedule (gameid, homeid, awayid, weekno, seasonno)
teams (teamid, location, nickname)
This mysql query below gets me schedule info for ALL 32 teams in an array...
$sql = "SELECT h.nickname AS home, a.nickname AS away, h.teamid AS homeid, a.teamid AS awayid, s.weekno FROM schedule s INNER JOIN teams h ON s.homeid = h.teamid LEFT JOIN teams a ON s.awayid = a.teamid WHERE s.seasonno =2014"; $schedule= mysqli_query($connection, $sql); if (!$schedule) { die("Database query failed: " . mysqli_error($connection)); } else { // Placeholder for data $data = array(); while($row = mysqli_fetch_assoc($schedule)) { if ($row['away'] == "") {$row['away']="BYE";} $data[$row['homeid']][$row['weekno']] = $row['away']; $data[$row['awayid']][$row['weekno']] = '@ '.$row['home']; } }However, I only want to get info for one specific team, which is stored in the $teamid variable. This should be very easy, right? I have tried multiple things, including this one below (where I added an AND statement of "AND (h.teamid=$teamid OR a.teamid=$teamid)"), but this one still outputs too much... $sql = "SELECT h.nickname AS home, a.nickname AS away, h.teamid AS homeid, a.teamid AS awayid, s.weekno FROM schedule s INNER JOIN teams h ON s.homeid = h.teamid LEFT JOIN teams a ON s.awayid = a.teamid WHERE s.seasonno =2014 AND (h.teamid=$teamid OR a.teamid=$teamid)"; $schedule= mysqli_query($connection, $sql); if (!$schedule) { die("Database query failed: " . mysqli_error($connection)); } else { // Placeholder for data $data = array(); while($row = mysqli_fetch_assoc($schedule)) { if ($row['away'] == "") {$row['away']="BYE";} $data[$row['homeid']][$row['weekno']] = $row['away']; $data[$row['awayid']][$row['weekno']] = '@ '.$row['home']; } }Below is the array that the above outputs. In a nutshell, all I want is that 1st array ([1]) which has, in this example, the Eagles full schedule. It's not giving me too much else and I guess I could live with it and just ignore the other stuff, but I'd rather be as efficient as possible and only get what I need... Array ( [1] => Array ( [1] => Jaguars [2] => @ Colts [3] => Redskins [4] => @ 49ers [5] => Rams [6] => Giants [7] => BYE [8] => @ Cardinals [9] => @ Texans [10] => Panthers [11] => @ Packers [12] => Titans [13] => @ Cowboys [14] => Seahawks [15] => Cowboys [16] => @ Redskins [17] => @ Giants ) [27] => Array ( [1] => @ Eagles ) [28] => Array ( [2] => Eagles ) [4] => Array ( [3] => @ Eagles [16] => Eagles ) [14] => Array ( [4] => Eagles ) [15] => Array ( [5] => @ Eagles ) [3] => Array ( [6] => @ Eagles [17] => Eagles ) [] => Array ( [7] => @ Eagles ) [16] => Array ( [8] => Eagles ) [25] => Array ( [9] => Eagles ) [11] => Array ( [10] => @ Eagles ) [7] => Array ( [11] => Eagles ) [26] => Array ( [12] => @ Eagles ) [2] => Array ( [13] => Eagles [15] => @ Eagles ) [13] => Array ( [14] => @ Eagles ) ) Lets start out by saying I'm a nube to sql/php things so I am learning as I go. I try to read all that I can before I post, and only post when I cant figure it out on my own. That being said. What I want to do in simplest terms is be able to assign a variable to each item in an sql table. So say I have an mysql table that has ID, username, fontcolor. I want to be able to pull those out so say.... while($row = mysql_fetch_array($users)) { $username[$i] = $row[username]; $fontcolor[$i] = $row[fontcolor]; } Then on the page I can just call to $username[1] type thing. I have tried mixing this several different ways with for and while and I keep getting errors on the page. I realize the code isn't showing everything but its just there to show you the idea of what I'm trying to do. I just want it to generate a list(array) that will make it easier for me to call back just the items I need on parts of the page with out having to have extra coding everywhere. Thanks in advance. Jim This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=354724.0 On an HTML Form, I have several Text boxes called "base1, base2...base13" Another text box I have is called "base_quantity" In my PHP routine: This is part of my code: Code: [Select] $selected_base = $_POST['base1']; if ($selected_base == 'yes') { $base_value = $base_value + 1; $base_status = 'Yes'; } else if ($selected_base == 'no') { $base_value = $base_value - 1; $base_status = 'No'; }Later on in the PHP routine I want to pass back to the Form the value of $base_status and place it in the "base_quantity" text box. Something like this: base_quantity = $base_value. Can someone tell me how information is passed back to the FORM. Thank You, Sam Hi Having thought the PHP form was working OK, I took a break. Upon return, it's up to its old tricks. Could anyone glance over this code for blatant errors? It works when it wants and when it doesn't... Much appreciated <? $select=$_POST['select']; $name=$_POST['name']; $email=$_POST['email']; $confirmail=$_POST['confirmail']; $month=$_POST['month']; $day=$_POST['day']; $year=$_POST['year']; $leaving=$_POST['leaving']; $hour=$_POST['hour']; $minutes=$_POST['minutes']; $ampm=$_POST['ampm']; $going=$_POST['going']; $flightnumber=$_POST['flightnumber']; $pay=$_POST['pay']; $song=$_POST['song']; $comments=$_POST['comments']; $to="beepbeepyeah@kabeoke.com"; header('Location:http://www.kabeoke.com'); $message="Message Type: $select\n\nName: $name\n\nEmail: $email\n\n$confirmail\n\nDate of Journey: $month, $day, $year\n\nLeaving From: $leaving\n\nDeparture Time: $hour:$minutes $ampm\n\nGoing to: $going\n\nFlight Number: $flightnumber\n\nPayment Method: $pay\n\nSong Requests: $song\n\nComments: $comments"; if(mail($to,"Slap it - message from Kabeoke.com!",$message,"From: $email\n")) { } else { echo "There was a problem sending the mail. Please check that you filled in the form correctly."; } ?> Hello Everyone, I have created a form for a personal project that I am working on. I have some error checking and stuff in the form but what I would like to happen is when an error has occurred for the page to reopen the form with the error message. I know that this can be done with the header function. But how do I get the form to display the error. Here is the block of code that I am working with Code: [Select] if ($file_error > 0) { header ('Location: add_category.php'); echo "There was an error uploading file."; } else { if ($file_type != $image_array) { header ('Location: add_category.php'); echo "Invalid Image Type"; } if ($file_name == FALSE) { header ('Location: add_category.php'); echo "Please choose a image for your category"; } if ($file_size > 5000000) { header ('Location: add_category.php'); echo "File size is to large. Images must be smaller than 5MB."; } if (str_word_count($description) > 300) { header ('Location: add_category.php'); echo "<p>category description must be less than 300 words<br />You have '.str_word_count($description).' words</p>"; }This is the form code that I am working with Code: [Select] <div id="content"> <form id="add_cat_form" name="add_cat_form" action="do_category.php" method="post" enctype="multipart/form-data"> <fieldset> <legend><p>Add Category</p></legend> <p> <label for="cat_name">Category Name:</label> <input class="input_box" type="text" name="cat_name" id="cat_name" /> </p> <p> <label for="cat_image">Category Image:</label> <input class="file" type="file" name="cat_image" id="cat_image" /> </p> <p> <label for="cat_desc">Description:</label><br /><textarea class="cat_desc" name="cat_desc" id="cat_desc"></textarea><br /> <span id="word_count">300 words Max</span> </p> <input class="submit_button" type="submit" value="Add Category" /> </fieldset> </form> </div> Hello everyone. I am writing this order/feedback form using a php script.
Every time i hit submit, the html page (that has the form inside) just reloads and does not perform the script
could anyone give me some pointers in my code the form/php?
I have made sure they are linked verbatim
I am a nube so please forgive my inexperience
Here is the form in the html , down below it is the corresponding php code for the form
Hi guys, i was wondering how can i make php to generate custom image with required fields (contact form). For example, i have a page with first name, last name, full address, email. And it's like this: First name: <input field here> Last name: <input field here> Full Address: <input field here> Email: <input field here> I would like to know how can i (once they fill all the info) generate an image with custom background (prepared full image previously) with all the filled info and have it emailed back to him. That email should be something like: Dear, FirstName, Here's your full info displayed on image below <img src="/path/to/thatImage.png"></img> Is this even possible? If so, please let me know how, i used to google a lot, but i can't find a solution, and i'm beginner in coding. Hope you guys will help me out, thanks a lot in advance! Hello everyone, I am having a problem since some time now and need some help. I have created a login page where the user has to input a username and password to login. The username will be put in a session and when the user logs out the session data and session itself gets destroyed. However when I go back in the browser history to the page where I logged in I get the "famous" resend information dialog that asks you to resend the information from the login form. Which means that all the post data gets resend and the user logs in again without having to put in a username and password. Here is my code: Login.tpl: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Snitch</title> <link rel="stylesheet" type="text/css" href="templates/css/snitch1440x900.css" /> </head> <body> <div id="login-achtergrond"> <div id="login"> <form action="." id="loginform" name="login" method="post"> <input type="hidden" name="actie" value="Login"></input> <input type="text" id="username" name="username" value="" style="opacity:0.7;filter:alpha(opacity=70)"></input> <input type="password" id="password" name="password" value="" style="opacity:0.7;filter:alpha(opacity=70)"></input> <input id="aanmelden" type="submit" name="submit" value="" style="opacity:0;filter:alpha(opacity=0)"> </form> </div> <div id="registreer"> </div> </div> </body> </html> Here is the code of my login page (I created this in a OOP way): Code: [Select] <?php class Handler_Login extends Actie_Handler { function __construct($actie_handle) { parent::construct($actie_handle); $this->actie = $actie_handle; } function secured_handler() { if ($this->session->check_session() == false) { $password = $_POST['password']; $username = $_POST['username']; $login = $this->dbh->Login($username, $password); if ($login == true) { $this->session->set('username', $username); $this->view->displayHome(); $this->view->display(); } else { echo "You are not logged in!"; } unset($_POST['password']); unset($_POST['username']); } if ($this->session->check_session() == true) { $this->view->displayHome(); $this->view->display(); } } } ?> Here is the code of my logout: Code: [Select] <?php class Handler_Loguit extends Actie_Handler { function __construct($actie_handle) { parent::construct($actie_handle); $this->actie = $actie_handle; } function secured_handler() { $this->session->stopSession(); $this->view->displayLogin(); $this->view->display(); } } ?> Here is the code of my session: Code: [Select] <?php class Session { function __construct() { if(!isset($_SESSION)) { session_start(); } } function set($name, $value) { $_SESSION[$name] = $value; } function get($name) { return $_SESSION[$name]; } function stopSession() { $_SESSION = array(); //even though I don't use any cookies someone told me that I had to remove the cookie of the session to completely destroy it? //please tell me if this is correct if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } session_destroy(); } function session_message($naam) { return print_r($_SESSION[$naam]); } function check_session() { if(isset($_SESSION['username']) && !empty($_SESSION['username'])) { return true; } else { return false; } } } ?> this is the code of my view for those who might be interested: Code: [Select] <?php class view_manager { private $tpl; function __construct() { } function displayStatus() { $status = file_get_contents("templates/status.tpl"); $this->tpl = str_replace("%content%", $status, $this->tpl); } function displayLogin() { $this->tpl = file_get_contents("templates/login.tpl"); } function displayHome() { $this->tpl = file_get_contents("templates/home.tpl"); } function display() { echo $this->tpl; } } ?> using a header to redirect to the login page is not going to work since I use my view_manager to display the pages. Does anyone know of any solution to get rid of that stupid resend information dialog without using a header? I tryed unsetting the values of POST in my login code but that did not seem to work. Please help me out I've been looking for an answer for over 1 and a half week so far Is there anyone who knows how to remove the POST data from a form when the user goes back in browser history? If it's not possible, is there any solution except using a header? Please, take a look to the following code.After clicking Next it goes to overview.php.Why when I click back on my browser to return to this page again, it is not returning back? When I click back I receive "Confirm Form Resubmission" message. After refreshing page it loads page. I guess problem is in "session_start();" part. Something to do with cookies. Please, help me it is very urgent for me. <?php session_start(); echo "<html> <head> <title>Hello World</title> <meta http-equiv='Content-Type' content='text/html; charset=Windows-1252'/> </head>"; require_once ('functions.inc'); if(!isset($_POST['userid'])) { echo "<script type='text/javascript'>"; echo "window.location = 'index.php'"; echo "</script>"; exit; }else{ session_register("userid", "userpassword"); $username = auth_user($_POST['userid'], $_POST['userpassword']); if(!$username) { $PHP_SELF = $_SERVER['PHP_SELF']; session_unregister("userid"); session_unregister("userpassword"); echo "Authentication failed " . "Please, write correct username or password. " . "try again "; echo "<A HREF=\"index.php\">Login</A><BR>"; exit; } } function auth_user($userid, $userpassword){ global $default_dbname, $user_tablename; $user_tablename = 'user'; $link_id = db_connect($default_dbname); mysql_select_db("d12826", $link_id); $query = "SELECT username FROM $user_tablename WHERE username = '$userid' AND password = '$userpassword'"; $result = mysql_query($query) or die(mysql_error()); if(!mysql_num_rows($result)){ return 0; }else{ $query_data = mysql_fetch_row($result); return $query_data[0]; } } echo "hello"; echo "<form method='POST' name='myform' action='overview.php'>"; echo "<input type='submit' value='Next'>"; echo "</form>"; ?> just trying to see if i have this right in my head here.. if i have a page that has a topic on it and many replies, the tables would look like this.. would this be the right code to pull out the topic AND all responses for say. www.mysite.com/view?id=1 $topic = 'SELECT * from topics where id = $id' $replies = 'SELECT * from replies where replies.topic_id = $id' I have looked all over the net on how to fix this... I am creating a baseball statistical website and I have 2 tables with identical columns (2012hitting and 2013hitting). I am trying to create a page where I can 1) group each year's statistics (which I have been able to do) and 2) have a row named "Career Totals". Each table has about 15 columns, various stats. How can I add the data from my 2012hitting table to my 2013hitting table into a Career Totals row for each player? This is what I'm trying now: Code: [Select] /* CONNECTION VARIABLES */ $id = $_GET['id']; // get var from URL /* Get data. */ $sql = "SELECT * (sum(2012hitting.hr) +sum(2013hitting.hr)) as totalhr FROM 2012hitting, 2013hitting WHERE id='$id'"; $result = mysql_query($sql); ?> <?php $alternate = "2"; while ($row = mysql_fetch_array($result)) { $field1 = $row["season"]; $field2 = $row["team"]; $field3 = $row["games"]; $field4 = $row["ave"]; $field5 = $row["slg"]; $field6 = $row["r"]; $field7 = $row["h"]; $field8 = $row["rbi"]; $field9 = $row["bb"]; $field10 = $row["k"]; $field11 = $row["hr"]; $field12 = $row["dbl"]; $field13 = $row["tpl"]; $field14 = $row["sb"]; $field15 = $row["obp"]; $field16 = $row["ops"]; if ($alternate == "1") { $color = "#ffffff"; $alternate = "2"; } else { $color = "#E4E4E4"; $alternate = "1"; } echo "<tr bgcolor=$color><td align='center'>$field1</td><td align='center'>$field2</td><td align='center'>$field3</td><td align='center'>$field4</td><td align='center'>$field5</td><td align='center'>$field6</td><td align='center'>$field7</td><td align='center'>$field8</td><td align='center'>$field9</td><td align='center'>$field10</td><td align='center'>$field11</td><td align='center'>$field12</td><td align='center'>$field13</td><td align='center'>$field14</td><td align='center'>$field15</td><td align='center'>$field16</td></tr>"; } echo "</table>"; ?> Thank you in advance! Okay so I have 2 tables in my database. One called user and one called messages. A user logs in to the message board and leaves a message (eg nice website). They write in the author name and the message then after the message is posted it says "Nice website" Posted by (author) on (date). All is good so far. It works. However if you look at my code you will see I have a session started. This session is storing the username of the logged in user. From the column username in the users table. (This table has has an id for each user). Ive played around with the code trying to make it so the user doesnt have to fill in the author box. I want rid of that box So the logged in user just leaves a message then it says "posted by (username) on (date). Im missing something from my code. Can anyone tell me what? Please? <?php session_start(); mysql_connect("*************", "*****************", "***************"); mysql_select_db("***********************"); $time = time(); //this checks to see if the $_SESSION variable has been not set //or if the $_SESSION variable has been not set to true //and if one or the other is not set then the user gets //sent to the login page if (!isset($_SESSION['username'])) { header('Location: http://***************.com/login.php'); } $query = "INSERT INTO messages VALUES( NULL, '". mysql_real_escape_string($_POST['message']) ."', '". mysql_real_escape_string($_POST['username']) ."', '$time' )";if( $result = mysql_query($query) ) { if(mysql_affected_rows() > 0 ) { echo "Message Posted.<br><a href='messageboard.php'>Return</a>"; } else { echo 'There was an error posting your message. Please try again later.'; } } else { echo "There was a database error."; // comment out next line for live site. echo "<br>Query string: $query<br>Returned error: " . mysql_error() . '<br>'; } ; |