Jump to content

john-formby

Members
  • Posts

    91
  • Joined

  • Last visited

Everything posted by john-formby

  1. This would be much better suited to a client side language like JavaScript.
  2. Something like this: edit.php <?php $theuID = 1; if(isset($_POST['submit'])) { foreach($_POST as $key=>$value) { $$key = $value; } $sqlupdate = "UPDATE tbluser SET firstname = '$firstname', lastname = '$lastname' WHERE uID = '$uID'"; $result = mysql_query($sqlupdate); header('Location: edit.php'); } $sql = mysql_query("SELECT uID,firstname,lastname FROM tbluser WHERE uID = $theuID"); $row = mysql_fetch_array($sql); echo ' <html> <head> <title>Form</title> </head> <body> <form action="edit.php" method="post"> <input type="hidden" name="uID" value="'.$row['uID'].'" /> <input type="text" name="firstname" value="'.$row['firstname'].'" /> <input type="text" name="lastname" value="'.$row['lastname'].'" /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html>'; ?>
  3. You would echo your existing fields out to a form. When the submit button is clicked, grab the values and do an update query to overwrite the original values.
  4. Oops, just realised you are not storing the variable on the page. This should work: WHERE student_gender = '".$_POST['gender']."'");
  5. WHERE student_gender = $gender ");
  6. I am going to have a complete guess about the structure of your script and see what happens To get to the inbox you need to be logged in and are possibly storing a value in a session? If you are not logged in, you are redirected to the login page? Check that your session is active on the inbox page by commenting out the redirect code to login and echoing the session variable. John
  7. Hi, Have a look at: http://php.about.com/od/gdlibrary/a/rotate_image_gd.htm John
  8. I don't know of any books that cover that and having looked online, there is a surprising lack of tutorials related to this subject. What I would suggest is that you break your project down into sections and look at each part. e.g. 1. Creating a DB and tables 2. Select, Insert, Update and Delete queries using PHP/MySQL 3. Form manipulation using PHP 4. PHP Arrays, loops and conditional statements 5. Login scripts (for admin) using sessions You should be able to find plenty of tutorials on these topics which should help you get started. John
  9. Do you mean something like this: SQL DB Tables -- -- Table structure for table `tblcars` -- CREATE TABLE `tblcars` ( `cID` int(11) NOT NULL auto_increment, `cmake` varchar(100) NOT NULL, PRIMARY KEY (`cID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ; -- -- Dumping data for table `tblcars` -- INSERT INTO `tblcars` (`cID`, `cmake`) VALUES (1, 'Audi'), (2, 'Volvo'), (3, 'Saab'), (4, 'Ford'), (5, 'Fiat'), (6, 'Honda'); -- -------------------------------------------------------- -- -- Table structure for table `tbluser` -- CREATE TABLE `tbluser` ( `uID` int(11) NOT NULL auto_increment, `cID` int(11) NOT NULL, `uname` varchar(100) NOT NULL, PRIMARY KEY (`uID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; -- -- Dumping data for table `tbluser` -- INSERT INTO `tbluser` (`uID`, `cID`, `uname`) VALUES (1, 2, 'Bob Smith'), (2, 5, 'Dave Jones'); index.php <?php $dbHost = "localhost"; $dbUser = "USERNAME"; $dbPass = "PASSWORD"; $dbname = "dbcarselect"; $db = mysql_connect($dbHost,$dbUser,$dbPass); mysql_select_db($dbname,$db); $sql1 = mysql_query("SELECT * FROM tbluser ORDER BY uname ASC"); echo '<html> <head> <title>Car DB</title> </head> <body>'; while($row1 = mysql_fetch_array($sql1)) { $uID = $row1['uID']; $cID = $row1['cID']; $uname = $row1['uname']; $sql2 = mysql_query("SELECT * FROM tblcars ORDER BY cmake ASC"); echo 'Name: '.$uname.' - Car: <select name="cmake">'; while($row2 = mysql_fetch_array($sql2)) { echo '<option ' . ($cID==$row2['cID'] ? 'selected' : '') . ' value="'.$row2['cID'].'">'.$row2['cmake'].'</option>'; } echo '</select><p />'; } echo '</body> </html>'; ?> I have created 2 tables, one for cars and one for users. The PHP script will run a while loop to echo out each user along with a select box containing their car make stored in the user table. John
  10. You are missing the closet curly bracket: }elseif($_GET['error'] == "email"){ echo "<div align='center'><h4 style='color:red'>Email must be valid</h4><br></div>"; } // insert bracket here ?>
  11. I learned through online tutorials and taking scripts apart. I am a kinesthetic learner so I learn best by doing rather than watching or listening. The way you learn best will determine which method is most suited to you. Some good tutorials are: http://uk2.php.net/tut.php http://www.w3schools.com/PHP/DEfaULT.asP http://www.tizag.com/phpT/ I have been learning for a couple of years and every day I find a better way to do something. John
  12. I was bored so have done a simple example using the select menu: SQL tables (for database dbcomments) CREATE TABLE `tblcomments` ( `cID` int(11) NOT NULL auto_increment, `uID` int(11) NOT NULL, `comment` longtext NOT NULL, PRIMARY KEY (`cID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; -- -- Dumping data for table `tblcomments` -- INSERT INTO `tblcomments` (`cID`, `uID`, `comment`) VALUES (1, 1, 'test comment'), (2, 1, 'another comment'), (3, 1, 'final comment'); -- -------------------------------------------------------- -- -- Table structure for table `tbluser` -- CREATE TABLE `tbluser` ( `uID` int(11) NOT NULL auto_increment, `uname` varchar(100) NOT NULL, PRIMARY KEY (`uID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; -- -- Dumping data for table `tbluser` -- INSERT INTO `tbluser` (`uID`, `uname`) VALUES (1, 'Bob'), (2, 'Dave'); index.php <?php $dbHost = "localhost"; // Database Connection Details $dbUser = "USERNAME"; // Database Connection Details $dbPass = "PASSWORD"; // Database Connection Details $dbname = "dbcomments"; // Database Connection Details $db = mysql_connect($dbHost,$dbUser,$dbPass); // Connection Code mysql_select_db($dbname,$db); // Connects to database $uID = $_POST['uID']; if(isset($_POST['add'])) { foreach($_POST as $key=>$value) { $$key = $value; } $sql3 = mysql_query("INSERT INTO tblcomments (cID, uID, comment) VALUES ('', '$uID', '$comment')"); $successmsg = 'Comment Added'; } if($uID != '') { $sql = mysql_query("SELECT * FROM tbluser, tblcomments WHERE tbluser.uID = tblcomments.uID && tbluser.uID = $uID"); $row = mysql_fetch_array($sql); } echo '<!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 http-equiv="Content-Language" content="en-us" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Comments</title> </head> <body> <form name="chooseuser" action="index.php" method="post"> <div>Choose User: <select class="txtselect" name="uID">'; $sql2 = mysql_query("SELECT * FROM tbluser"); $numrows2 = mysql_num_rows($sql2); if ($numrows2 == 0) { echo '<option value="">No Users</option>'; } else { echo '<option value="">Choose User</option>'; while($row2 = mysql_fetch_array($sql2)) { echo '<option ' . ($row['uID']==$row2['uID'] ? 'selected' : '') . ' value="'.$row2['uID'].'">'.$row2['uname'].'</option>'; } } echo '</select> <input class="subbtn" type="submit" name="submit" value="Submit" /></div> </form>'; if($uID != '') { echo $successmsg; $sql4 = mysql_query("SELECT * FROM tblcomments WHERE uID = $uID ORDER BY cID DESC"); $numrows4 = mysql_num_rows($sql4); echo '<hr />'; if($numrows4 == 0) { echo 'No Comments'; } else { while($row4 = mysql_fetch_array($sql4)) { echo $row4['comment'].'<br /><hr />'; } } echo '<form name="addcomment" action="index.php" method="post"> <input type="hidden" name="uID" value="'.$uID.'" /> <textarea name="comment"></textarea><br /> <input type="submit" name="add" value="Add Comment" /> </form>'; } echo '</body> </html>'; ?> Please bear in mind that the above code does not have any validation or error checking. Hope this helps, John
  13. If you have hundreds of people, then having the search facility by allowing people to type the name is fine. If you have only a few people, then I would query the database and display the results in a drop down menu. By selecting the person from the list, it displays the details and shows a form for adding info about the person. As awpti says, it is not that difficult.
  14. Have a look at: http://uk.php.net/imagesetpixel
  15. <?php $fp = fopen("hit.txt", "r"); $hits = fread($fp, 1024); fclose($fp); $hits = $hits + 1; echo "Count = " . $hits . "</p>"; $fp = fopen("hit.txt", "w"); fwrite($fp, $hits); fclose($fp); ?> That should work
  16. <?php if(isset($_POST['submit'])) { $to = "steve@gmail.com"; $subject = "NEW MESSAGE FROM WEBSITE"; $fname_field = $_POST['fname']; $lname_field = $_POST['lname']; $email_field = $_POST['email']; $website_field = $_POST['website']; $coffee_field = $_POST['coffee']; $message = $_POST['message']; $body = "FirstName: $fname_field\n LastName: $lname_field\n E-Mail: $email_field\n Website: $website_field\n Coffee: $coffee_field\n Message:\n $message"; mail($to, $subject, $body); header("Location: http://www.blindacre.com/");die; } The else section is outside of the if(isset($_POST['submit'])) { code so is automatically redirecting you to the site before you see the form.
  17. $edit_sql = "UPDATE travek_video SET link='".$_POST['link']."', title='".$_POST['title']."', description='".$_POST['desc']."', folder='".$_POST['folder']."', WHERE id='".$_GET['video']."' AND uploader='".$_SESSION['username']."'"; $result = mysql_query($edit_sql);
  18. Have a look at this link: http://www.ibdhost.com/contact/
  19. This is what I use to connect to my databases: <?php $dbHost = "localhost"; // Database Connection Details - host $dbUser = "root"; // Database Connection Details - username $dbPass = "blah"; // Database Connection Details - password $dbname = "testdb"; // Database Connection Details - database name $db = mysql_connect($dbHost,$dbUser,$dbPass); // Connection Code mysql_select_db($dbname,$db); // Connects to database ?> Try that and see if you have any problems
  20. Hi, no problem. Here is an example for you. MySQL table structure: CREATE TABLE `tbluser` ( `uID` int(11) NOT NULL auto_increment, `firstname` varchar(30) NOT NULL, `lastname` varchar(30) NOT NULL, KEY `uID` (`uID`) ) ENGINE=MyISAM; -- -- Dumping data for table `tbluser` -- INSERT INTO `tbluser` VALUES (1, 'John', 'Formby'); CREATE TABLE `tblaudit` ( `auditID` int(11) NOT NULL auto_increment, `uID` int(11) NOT NULL, `editor` varchar(30) NOT NULL, `formname` varchar(30) NOT NULL, `whenpost` timestamp NOT NULL default '0000-00-00 00:00:00', KEY `auditID` (`auditID`) ) ENGINE=MyISAM; edituser.php <?php $dbHost = "localhost"; $dbUser = "blah"; $dbPass = "blah"; $dbname = "testdb"; $db = mysql_connect($dbHost,$dbUser,$dbPass); mysql_select_db($dbname,$db); $uID = 1; $editor = 'John'; // The person who is editing the record. This would be grabbed from the session if(isset($_POST['submit'])) { foreach($_POST as $key=>$value) { $$key = $value; } // update the record $sql2 = "UPDATE tbluser SET firstname = '$firstname', lastname = '$lastname' WHERE uID = '$uID'"; $result2 = mysql_query($sql2); // create the audit trail $sql3 = mysql_query("INSERT INTO tblaudit (auditID, uID, editor, formname, whenpost) VALUES ('', '$uID', '$editor', '$formname', NOW())") or die(mysql_error()); echo 'User details updated'; } echo ' <html> <head> <title>Edit User</title> </head> <body>'; $sql = mysql_query("SELECT * FROM tbluser WHERE uID = '$uID'"); $row = mysql_fetch_array($sql); echo '<form name="edituser" action="edituser.php" method="post"> <input type="hidden" name="uID" value="'.$row['uID'].'" /> <input type="hidden" name="formname" value="Edit User" /> <input type="hidden" name="editor" value="'.$editor.'" /> <input type="text" name="firstname" value="'.$row['firstname'].'" /> <input type="text" name="lastname" value="'.$row['lastname'].'" /> <input type="submit" name="submit" value="submit" /> </form> </body> </html>'; ?> I have not tested because I am at work at the moment. If you get any errors let me know.
  21. How are you opening the popup window? If it is through a form then you could post the variable in a hidden field. If it is through a hyperlink then pass it as a get variable.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.