PHP - Editing Table From Page - Struggles
So I have a page that displays a table from my database and now I have to create a link that edits the information and saves it back to the database from a page. I have 2 pages: student_man.php which displays the table info and provides the edit link, and then editstudent.php which displays the form etc where you edit the info and submit it. I think my first page is fine, or rather doesn't display any errors. I'm struggling with my second page however, receiving errors and my data that is already in the fields aren't displaying rather the fields are just empty. First time I attempt this just want to know if I am on the right path and what I might doing wrong.
Here is my code First page:<?php Code: [Select] <html> <head> <head> <title>Courses</title> <style type="text/css"> #apDiv2 { position:absolute; left:0px; top:0px; width:1024px; height:180px; z-index:2; } </style> </head> <body bgcolor="white"> <?php ?> <div id="apDiv1"> <div id="apDiv2"><img src="Images/Banner.gif" width="1024" height="180" /></div> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <center><p><a href="student_reg.php"> Register a student</a> -- <a href="course_man.php"> Manage courses </a> -- <a href="student_man.php"> Manage student </a> --<a href="list.php"> view registrations </a> </p></center> </div> <br> <br> <p><a href="selectdelstudent.php"> Delete </a> <a href="student_reg.php"> Add </a> </p> <!-- Table for course --> <div id="apdiv3"> <table border=1px noshade="no"> <tr> <td><b> Course Name</b></td> <td><b> Surname</b></td> <td><b> Initials</b></td> <td><b> Full First Name</b></td> <td><b> Title</b></td> <td><b> Maiden or previous surname</b></td> <td><b> Date of birth</b></td> <td><b> Gender</b></td> <td><b> Language of correspondence</b></td> <td><b> Identity number</b></td> <td><b> Cell Phone Number</b></td> <td><b> Fax Code + Number</b></td> <td><b> E-mail Address</b></td> <td><b> Postal address of student</b></td> </tr> </table> </div> <!-- Start of php code for retrieving student information --> <?php include 'includes/config.php'; //connect to database $link=mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); //error check if (!$link) { die('could not connect: ' . mysql_error()); } $db_selected=mysql_select_db(DB_NAME, $link); // error check if (!$db_selected) { die('can\t use ' . DB_NAME . ': ' . mysql_error()); } //query database $query=mysql_query("SELECT * FROM student "); //fetch results and convert to table while ($rows = mysql_fetch_array($query)): echo "<a href=\"editstudent.php?id=" . $rows['sno'] ."\" > edit </a>"; $cname=$rows['cname']; $sname=$rows['sname']; $init=$rows['init']; $fname=$rows['fname']; $title=$rows['title']; $msname=$rows['msname']; $dob=$rows['dob']; $sex=$rows['sex']; $lang=$rows['lang']; $idno=$rows['idno']; $telh=$rows['telh']; $telw=$rows['telw']; $cell=$rows['cel']; $fax=$rows['fax']; $email=$rows['email']; $address=$rows['address']; echo " <table border=1px> <tr> <td>$cname</td> <td>$sname</td> <td>$init</td> <td>$fname</td> <td>$title</td> <td>$msname</td> <td>$dob</td> <td>$sex</td> <td>$idno</td> <td>$telh</td> <td>$telw</td> <td>$cell</td> <td>$fax</td> <td>$email</td> <td>$address</td> </tr> </table>" ; endwhile; ?> </body> </html> ?> Here is my second page where you edit the info: <?php Code: [Select] <?php include 'includes/config.php'; //connect to database $link=mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); //error check if (!$link) { die('could not connect: ' . mysql_error()); } $db_selected=mysql_select_db(DB_NAME, $link); // error check if (!$db_selected) { die('can\t use ' . DB_NAME . ': ' . mysql_error()); } // connected to database if (!isset($_POST['submit'])) { $q = "SELECT * FROM student WHERE ID = $_GET[sno]"; $result = mysql_query($q); $person = mysql_fetch_array($result); } ?> <h1> You are editing a student </h1> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <p>Course name:</p> <INPUT TYPE = "text" name="input1"value="<?php echo $person['cname']; ?>" /> <br> <p>Surname:</p> <INPUT TYPE = "text" name="input2"value="<?php echo $person['sname']; ?>" /> <br> <p>Initials:</p> <INPUT TYPE = "text" name="input3"value="<?php echo $person['init']; ?>" /> <br> <p>Full First Name:</p> <INPUT TYPE = "text" name="input4"value="<?php echo $person['fname']; ?>" /> <br> <p>Title:</p> <INPUT TYPE = "text" name="input5"value="<?php echo $person['title']; ?>" /> <br> <p>Maiden or previous surname:</p> <INPUT TYPE = "text" name="input6"value="<?php echo $person['msname']; ?>" /> <br> <p>Date of Birth:</p> <INPUT TYPE = "text" name="input7"value="<?php echo $person['dob']; ?>" /> <br> <p>Gender:</p> <INPUT TYPE = "text" name="input8"value="<?php echo $person['sex']; ?>" /> <br> <p>Language for correspondence:</p> <INPUT TYPE = "text" name="input9"value="<?php echo $person['lang']; ?>" /> <br> <p>Identity Number:</p> <INPUT TYPE = "text" name="input10"value="<?php echo $person['id']; ?>" /> <br> <p>Home Telephone Code + Number:</p> <INPUT TYPE = "text" name="input11"value="<?php echo $person['telh']; ?>" /> <br> <p>Work Telephone Code + Number:</p> <INPUT TYPE = "text" name="input12"value="<?php echo $person['telw']; ?>" /> <br> <p>Cell Phone Number:</p> <INPUT TYPE = "text" name="input13"value="<?php echo $person['cel']; ?>" /> <br> <p>Fax Code + Number:</p> <INPUT TYPE = "text" name="input14"value="<?php echo $person['fax']; ?>" /> <br> <p>E-mail Address:</p> <INPUT TYPE = "text" name="input15"value="<?php echo $person['email']; ?>" /> <br> <p>Postal Address of student:</p> <INPUT TYPE = "text" name="input16"value="<?php echo $person['address']; ?>" /> <br> <INPUT TYPE = "Submit" name="submit" VALUE = "Submit"/> <input type="hidden" name="sno" value="<?php echo $_GET['sno']; ?>" /> </form> <?php if(isset($_POST['submit'])) { $u = "UPDATE student SET `cname` = '$_POST[input1]' `sname` = '$_POST[input2]' `init` = '$_POST[input3]' `fname` = '$_POST[input4]' `title` = '$_POST[input5]' `msname` = '$_POST[input6]' `dob` = '$_POST[input7]' `sex` = '$_POST[input8]' `lang` = '$_POST[input9]' `idno` ='$_POST[input10]' `telh` = '$_POST[input11]' `telw` = '$_POST[input12]' `cel` = '$_POST[input13]' `fax` = '$_POST[input14]' `email` = '$_POST[input15]' `address` = '$_POST[input16]' WHERE ID = $_POST(sno)"; mysql_query($u) or die(mysql_error()); echo "User has been modified!"; header("Location: index.php"); } ?> ?> On my second page I am receiving the following errors after typing random letters as info into the fields and submitting it: 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 '`sname` = 'sds' `init` = 'gfg' `fname` = 'rtr' `title` = '' `msname`' at line 3 Similar Tutorialsthe above/attached image shows a table outputted using a 'for loop', it has the action column that should either edit or delete entity... I need help to be able to edit or delete each entity by clicking the action link... find attached image... Hi guys, just wondering if someone can help me i am currently trying to edit a MYSQL database through PHP and just wondering if you could take a look at the code i have and tell me where i have gone wrong. I have tried to use a tutorial but have got lost and need some help. This is for my final year project for University and really needs to be done soon so i would be really greatful if someone could help me out. Thanks code below: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <link rel="stylesheet" type="text/css" href="style.css"/> <title>Database Editor</title> </head> <body> <div id="page"> <img src="images/banner1.jpg" alt="banner"/> <div id="navi-container"> <ul id="navi"> <li><a href="index.php">Home</a></li> <li><a href="news.php">News</a></li> <li><a href="latest_products.php">Latest Products</a></li> <li><a href="gallery.php">Gallery</a></li> <li><a href="Admin_page.php">Administration</a></li> </ul> </div> <?php ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <h1>Database Editor</h1> <table class="inputtable"> <tr> <td class="label">Item Name:</td> <td class="inputtd"> <input name="Item_Name" type="text" class="standardwidth" /></td> </tr> <tr> <td class="label"> Item Image:</td> <td class="inputtd"> <input name="Item_Image" type="text" class="standardwidth" /></td> </tr> <tr> <td class="label">Item Description:</td> <td class="inputtd"> <input name="Item_Description" type="text" class="standardwidth" /></td> </tr> <tr> <td class="label">Item Number:</td> <td class="inputtd"> <input name="Item_Number" type="text" class="standardwidth" /></td> </tr> </table> <br /> <table class="radbuttons"> <tr> <td class="standardwidth"> <input name="op" type="radio" checked="checked" value="rdbase" /> Read from Database</td> <td><input name="op" type="radio" value="cdbase" />Change Entry (enter data in form)</td> </tr> <tr> <td class="standardwidth"> <input name="op" type="radio" value="adbase" />Add to Database</td> <td><input name="op" type="radio" value="ddbase" />Delete Entry (enter name in form)</td> </tr> </table> <br /> <input name="submit" type="submit" value="submit" /> <input name="reset" type="reset" value="reset" /> <br /> </form> <?php if (count($view->peopleList) > 0) { ?> <table class="datatable"> <tr> <th><strong>Surname</strong></th> <th><strong>First Name </strong></th> <th class="standardwidth"><strong>Address </strong></th> <th><strong>Phone</strong></th> </tr> <?php foreach ($view->peopleList as $person) : ?> <tr> <td> <?php echo $person->getSurname(); ?> </td> <td> <?php echo $person->getFirstname(); ?> </td> <td> <?php echo $person->getAddress(); ?> </td> <td> <?php echo $person->getPhone(); ?> </td> </tr> <?php endforeach; } ?> </table> <?php ?> <?php $dbc = mysql_connect ('****','***','salford*****') OR die('Could not connect to MySQL : ' . mysql_error() ); mysql_select_db ('****') OR die('Could not select the database : ' . mysql_error() ); $query = "SELECT * FROM ****** ORDER BY Item_Number"; $result = mysql_query ($query); ?> <body> <h1>Database</h1> <table border="1"> <tbody> <tr> <td>Item Name</td> <td>Item Image</td> <td>Item Description</td> <td>Item Number</td> </tr> <?php while($row = mysql_fetch_array($result,MYSQL_ASSOC)) { echo " <tr> <td>$row[Item_Name]</td> <td>$row[Item_Image]</td> <td>$row[Item_Description]</td> <td>$row[Item_Number]</td> </tr> "; } mysql_close(); ?> $sql = 'INSERT INTO murrayfp10_ipad (Item_Name, Item_Description, Item_Number) VALUES (:Item_Name, :Item_Description, :Item_Number)'; $result = $this->dbh->prepare($sql); $result->execute(array( ':Item_Name' => $data['Item_Name'], ':Item_Description' => $data['Item_Description'], ':Item_Number' => $data['Item_Number'] )); return $this->dbh->lastInsertId(); } public function edittbl($data) { $sql = 'UPDATE murrayfp10_ipad SET Item_Name = :Item_Name, Item_Description = :Item_Description, Item_Number = :Item_Number WHERE Item_Name = :Item_Name'; $result = $this->dbh->prepare($sql); return $result->execute(array( ':Item_Name' => $data['Item_Name'], ':Item_Description' => $data['Item_Description'], ':Item_Number' => $data['Item_Number'], ':Item_Number' => $data['Item_Number'] )); } public function deletetbl($data) { $sql = 'DELETE FROM murrayfp10_ipad WHERE Item_Name = :Item_Name'; $result = $this->dbh->prepare($sql); return $result->execute(array( ':Item_Name' => $data['Item_Name'] )); } <div style="text-align:center;"> Copyright © M.Murray 2011 </div> </body> </html> Hey there is no error with this code it works just fine but I would love to know if there is unnecessary coding in it for example do i have to do the global variables? is there a better way to do mysql editing page? thanks <?php include "../configdb.php"; $id = $_GET['id']; if(isset($_POST['submit'])) { //global variables $name = $_POST['name']; $footer = $_POST['footer']; //run the query which adds the data gathered from the form into the database $result = mysql_query("UPDATE pages SET name='$name', footer='$footer' WHERE id='$id' ",$connect); echo "<b>Your Page have been edited successfully"; } elseif($id) { $result = mysql_query("SELECT * FROM pages WHERE id='$id' ",$connect); while($row = mysql_fetch_assoc($result)) { $name = $row['name']; $footer = $row['footer']; ?> <h3>::Edit Page</h3> <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?php echo $row['id']?>"> <input type="hidden" name="id" value="<?php echo $row['id']?>"> <input name="name" size="40" maxlength="255" value="<?php echo $name; ?>"> <input name="footer" size="40" maxlength="255" value="<?php echo $footer; ?>"> <input type="submit" name="submit" value="Submit"> <?php } } I need help trying to figure out why my form won't write the database it is supposed to - i checked the connection to the database and it works and the user seems to have permission to edit database - the error I get is "Error: User not added to database." from "register.php". Can someone please look over my code and see if the problem is coming from somewhere within?
I created a connection file (connect.php)
<? session_start(); // Replace the variable values below // with your specific database information. $host = "localhost"; $user = "master"; $pass = "hidden"; $db = "user"; // This part sets up the connection to the // database (so you don't need to reopen the connection // again on the same page). $ms = mysql_pconnect($host, $user, $pass); if ( !$ms ) { echo "Error connecting to database.\n"; } // Then you need to make sure the database you want // is selected. mysql_select_db($db); ?>Then there is the php script (register.php): <?php session_start(); // connect.php is a file that contains your // database connection information. This // tutorial assumes a connection is made from // this existing file. require('connect.php'); // If the values are posted, insert them into the database. if (isset($_POST['email']) && isset($_POST['password'])){ $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $password = $_POST['password']; $query = "INSERT INTO `member` (firstname, lastname, email, password) VALUES ('$firstname', '$lastname', '$email' '$password')"; $result = mysql_query($query); if ( !mysql_insert_id() ) { die("Error: User not added to database."); } else { // Redirect to thank you page. Header("Location: surveylanding_no-sidebar.html"); } } ?>Here is the HTML form: <form name="htmlform" method="post" class="form" action="register.php"> <p class="firstname"> <input type="text" name="firstname" id="firstname" /> <label for="firstname">First Name</label> </p> <p class="lastname"> <input type="text" name="lastname" id="lastname" /> <label for="lastname">Last Name</label> </p> <p class="email"> <input type="email" name="email" id="email" /> <label for="email">Email</label> </p> <p class="Password"> <input type="password" name="password" id="password" /> <label for="password">Password</label> </p> <p class="submit"> <input type="submit" value="Register"/> </p> </form> So i have this CMS that is used by lots of users and generally they do have rights to edit each others article. So now i'm thinking how can i at least warn them that somebody else is already editing it. Just that. maybe with sessions? but what happens when a user just closes the windows, will it destroy it. i taught about storing the value to mySQL but again what if the user closes the windows and so on. i never did this and i could use a boost. thanks guys Hello everyone. I need help with the following PHP APP. I am running on (Version PHP 7.2.10) I am trying to have a page table form on table.php pass the input variable of “5-Numbers” to another page called table_results.php I want that variable string of “5-Numbers” to be compared against 4 arrays and output any duplicates found within each of those 4 lists. If nothing is found, I still want some visual output that reads “None found”.
Lets pretend I have the following example .. On table.php, I typed inside my table form the 5-Numbers .. INPUT: 2,15,37,13,28 On table_results.php, the 4 arrays to be compared against my input numbers “ 2,15,37,13,28” are ..
$array_A = array(2,6,8,11,14,18,24); $array_B = array(1,2,9,10,13,14,25,28,); $array_C = array(1,3,7,9,13,15,20,21,24); $array_D = array(4,5,12,22,23,27,28,29);
So my output should read as follows below .. OUTPUT:
TABLE COLUMN 1 COLUMN 2 ROW 1 Matches Found Results .. ROW 2 GROUP A: 2 ROW 3 GROUP B: 2,13,28 ROW 4 GROUP ? 13,15 ROW 5 GROUP ? 28 ROW 6 5#s Input: 2,15,37,13,28
Please let me know if anyone has any suggestions on how to go about it. Thanks. Edited January 1, 2019 by Jayfromsandiego Wanted to include image example This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=323045.0 Hi, I want to post a simple comments box at the bottom of one of my web pages that will send the data from 4 different inputs, named "email," "name," "comments," and "telephone," to my email. Can someone look at my php code and see what is wrong? The website code box works great if I enter in all the fields, however if the email box is not filled out and you click the submit button, it displays "Invalid email address enteredThank you for your message, we will be in touch shortly" How do I get rid of "Thank you for your message, we will be in touch shortly" Also, it sends the email even if the ['Name'] tag is not filled out, I not sure how to make it required. By the way, I'm new to php, so sorry if this is a little hard to understand. Link to website: http://www.raysmasonryconcrete.com/contact.html Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Send Data Form</title> </head> <body> <?php if(!$_POST) exit; $email = $_POST['Email']; $name = $_POST['Name']; $telephone = $_POST['Telephone']; $comments = $_POST['Comments']; //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS'; if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){ $error.="Invalid email address entered"; $errors=1; } if($errors==1) echo $error; else{ $values = array ('Name','Email','Telephone','Comments'); $required = array('Name','Email','Telephone','Comments'); $your_email = "*****"; $email_subject = "Message From the HDS Builders Website:"; foreach($values as $key => $value){ if(in_array($value,$required)){ if ($key != 'Name' && $key != 'Comments' && $key != 'Telephone') { if( empty($_POST[$value]) ) { echo 'Please go back and complete all fields, thank you.'; exit; } } $email_content .= $value.': '.$_POST[$value]."\n"; } } } $headers = "From: $email\r\n"."Reply-To: $email\r\n".'X-Mailer: PHP/' . phpversion(); if(@mail($your_email, $email_subject, $email_content, $headers)) { echo 'Thank you for your message, we will be in touch shortly'; } else { echo 'ERROR!'; } ?> </body> </html> I'm not sure how to put in a tab when editing php with php $fh = fopen(MYBB_ROOT.'/member.php', "r") or cperror("Could not open file!"); //OPEN FILE $data = fread($fh, filesize(MYBB_ROOT.'/member.php')) or cperror("Could not read file!"); //MAKE TEMPORARY STRING fclose($fh); //CLOSE FILE AGAIN $newdata = preg_replace('#'.preg_quote('eval("\$online_status = \"".$templates->get("member_profile_online")."\";"); if(is_super_admin($memprofile[\'uid\'])){ eval("\$online_status = \"".$templates->get("unknownlocation")."\";"); }').'#','\t\teval("\\\\$online_status = \"".$templates->get("member_profile_online")."\";");',$data); //REPLACE IN STRING $fw = fopen(MYBB_ROOT.'/member.php', "w") or cperror('Could not open file!'); //OPEN FILE AGAIN $fb = fwrite($fw, $newdata) or cperror('Could not write to file'); //WRITE STRING TO FILE fclose($fw); //CLOSE FILE AGAIN } I need to tab that line twice so it lines up in the file, i've tried putting \t in twice but that doesn't work and just gives this error Fatal error: Call to undefined function teval() in /Applications/XAMPP/xamppfiles/htdocs/member.php on line 1621 So, how to you put tabs in? Thanks I need to open a template file change a text var and then save the file as something new. How can I do this? Hi I have a list created using php and mysql linked together. I have an edit and a delete button which edits and deletes data on the database. When I click edit it brings up current information and I can change it, which is fine. But I click to edit it in the database it changes all the records I have in the database!!! Instead of the specific record!!!! Could anybody please help!!!! One more question for the day. I'm trying to figure out the best way to run about this. Right now I have it set up so that two or more content pages CAN NOT have the same name or shortname as it performs checks to verify that there aren't both on my add new and edit pages. Now problem here is that say I'm on the edit form and I'm editing a content page with its dropdowns and what not in the form. Now I'm thinking what would be the next course of option because what if I only want to change one dropdown but still keep the same name and shortname. When I submit it, its going to kickback my response that it can't be saved because there's already a page in there with that name and shortname even though I didn't change it. Any suggestions? Hello The code shown below creates a new endpoint to the "my-account" section on my wordpress website. basically it displays the products a user purchased from our site. I just want to EXCLUDE a certain product category to be shown in this endpoint ! i hope you can help me achieve this !
Hey guys! I ran into another problem, i am looking to create a system so my users can go edit their accounts such as: Password, Age and Info and so on. but im am totally blank so i need some kind of tutorial to get started, or maybe help if anyone got time for that. Thanks Hi everyone I am using this code which is an example from a website Code: [Select] <?php $file_handle = fopen("myfile", "rb"); while (!feof($file_handle) ) { $line_of_text = fgets($file_handle); $parts = explode('=', $line_of_text); print $parts[0] . $parts[1]. "<BR>"; } fclose($file_handle); ?> Which does what it is meant to, however what I am trying to do is put all the input into a form, so values can be changed. How do I separate each part? Eg the 1st line of the files reads isactive = true, how would I grab this so I can put it back to the file later as isactive = false? Not all the options are true/false, most are just strings or ints. Thanks the files are created upon registration. just i get this error.. Warning: include(1) [function.include]: failed to open stream: No such file or directory in /home/bob/public_html/mysite/profiles/write.php on line 129 Warning: include(1) [function.include]: failed to open stream: No such file or directory in /home/bob/public_html/mysite/profiles/write.php on line 129 Warning: include() [function.include]: Failed opening '1' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/bob/public_html/mysite/profiles/write.php on line 129 Code: [Select] $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) $filename = "/home/bob/public_html/mysite/profiles/profileinfo/$username.info.php" or exit("Unable to open file!"); $handle = fopen($filename, 'w')or die; $content = "<b>Firstname: </b>$firstname <br> <b> Lastname: </b> $lastname <p> <b> Birthday: </b>$day $month $year <br> <b> Location: </b> $location"; fwrite($handle, $content)or die; fclose($handle); } $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) include ("/home/bob/public_html/mysite/profiles/profileinfo/$username.info.php")or die; I have print page using window.print in the body tag at the beginning of php file and i am trying to make the rest of the code as second page, the last table will be on the second page. it is not working. code: <b>Absent Report:</b> <table style ="page-break-before: always;" border='1'> <tr><th>ID</th><th>Name</th><th>Absent</th></tr> <?=$tdata?> </table> <a href="singlereportbyid.php" width="100%">Click here to go back to Main Menu</a> </div> </div> </div> </div> </body> </html> why it is not working? Hi. When i fill in my contact form, it shows a "Message sent successfully" message. Then nothing happens. I think there is something wrong with my hosting but the service provider just can't help with that.
How can i edit these codes to send a mail through smtp?
<?php
I've been working with PHP for only a few weeks now. I have learned a significant amount by creating a custom web app. I can usually figure things out by massive Googling and trial and error but this one has got me stumped. I have a form for this web app that I'd like to use as a configuration page. It houses all of the settings that the web app needs. On the backend, I'm housing all of this data in a XML file. So far, I've been able to parse the XML file to populate all of the appropriate fields in the HTML form. However, I'm having trouble taking the user's input and saving it back to the same XML. To do this, I have a processconfig.php page as the form's action. In this process.php page, I'm using the elements from the $_POST array to bring over all of the data in the form's fields. I want to take these $_POST array elements and insert them into the same XML that originally populated the form in the first place. With the code below I've been able to get the SimpleXML object to add data to the XML file but it is simply appended to the end with no formatting. As you can see, I've tried to name the form fields the same name as it's POST array element so that I can do the loop but it's not working. Is there an easier way to do this or is there another recommended way to retrieve and store configuration items for a web app? Here's my code: config.xml snippet Code: [Select] <Config> <General> <Logging> <Enabled>No</Enabled> </Logging> <QueryBuybackSites> <Enabled>Yes</Enabled> </QueryBuybackSites> <BuildFBA> <Enabled>No</Enabled> </BuildFBA> <BuildBB> <Enabled>No</Enabled> </BuildBB> <FBARankCutoff> <Value>1000000</Value> </FBARankCutoff> <Amazon0Offer> <DefaultPrice> <Value>47.77</Value> </DefaultPrice> <AutoKeep> <Enabled>Yes</Enabled> </AutoKeep> </Amazon0Offer> </General> </Config> configview.php snippet Code: [Select] <?php //Load all configuration data $configxml = simplexml_load_file('config.xml'); echo '<html> <head> <title>Easy Receive Configuration</title> </head> <body> <form action="processconfig.php" enctype="multipart/form-data" id="emf-form" method="post"> <table bgcolor="#FFFFFF" border="0" cellpadding="2" cellspacing="0" style="text-align: left;"> <tbody> <tr> <td colspan="2" style=""> <font color="#000000" face="Verdana" size="2"><b style="font-size: 20px;">Easy Receive Configuration Settings</b><br /> <label style="font-size: 15px;">This is where you can customize Easy Receive to your personal preferences</label></font> </td> </tr> <tr valign="top"> <td colspan="2" style=""> <hr /> <h3 id="element_0" name="element_0" style="font-size: 14px; padding: 10px 0pt 6px; margin: 14px 0pt; position: static;"> <span style="font-size: 24px;"><font color="#000000" face="Verdana">General Configuration Options</font></span></h3> </td> </tr> <tr valign="top"> <td align="" style=""> <p> <strong>Enable Logging</strong> <input name="General->Logging->Enabled" type="checkbox" ' . htmlify($configxml->General->Logging->Enabled) . ' /></p> </td> </tr> <tr valign="top"> <td align="" style=""> <p> <font color="#000000" face="Verdana" size="2"><strong>Build FBA shipment on the fly</strong> <input name="General->BuildFBA->Enabled" type="checkbox" ' . htmlify($configxml->General->BuildFBA->Enabled) . ' /></font></p> </td> </tr> </tbody> </table> </form></body> </html>'; function htmlify($input) { if ($input == "Yes") return "checked"; else return ""; } ?> processconfig.php snippet Code: [Select] <?php $xmlstring = file_get_contents('config.xml'); $configxml = new SimpleXMLElement($xmlstring); foreach ($_POST as $attrib=>$value){ $configxml->$attrib = $value; } $configxml->asXML('config.xml'); ?> I want to make a file that I can edit from a form. I don't know what type of file I should use, and how I would edit that file. When someone goes to the file I don't want them to be able to see the contents (like a php file holding variables). I also don't want to use .htaccess for this. This file will have things in such as the database connection variables. When someone edits the form, and save it, it will edit the database connection variables to the proper values. Here is the file I have now: Code: [Select] <?php $settings = array(); $settings['db']['host'] = 'xxxx'; $settings['db']['username'] = 'xxxx'; $settings['db']['password'] = 'xxxx'; $settings['db']['database'] = 'xxxx'; ?> Here is an example input field: Code: [Select] <input type="text" name="host" value="<?php echo $settings['db']['host']; ?>" /> What would be the best way to do this? |