Jump to content

Herbert at GC

Member
  • Posts

    15
  • Joined

  • Last visited

Everything posted by Herbert at GC

  1. Herbert at GC

    Live chat

    Can PHP be used to build live chat?
  2. After solving some PHP problem, its go kart time!

  3. This was also one of the problem. extra comma at the end of the "phone=?" bad: if ($stmt = $mysqli->prepare("UPDATE client_list SET company_name=?, contact=?, phone=?, WHERE id=?")) good: if ($stmt = $mysqli->prepare("UPDATE client_list SET company_name=?, contact=?, phone=? WHERE id=?")) - Herbert
  4. Hi Ben bind_param()is the problem and the or worked. problem solved! Thanks man -- IOU
  5. Hi Ben: code below. ============================================================== <link rel="stylesheet" href="crud-css.css" type="text/css" /> <?php /* Allows the user to both create new records and edit existing records */ // connect to the database include('crud-connect.php'); // creates the new/edit record form // since this form is used multiple times in this file, I have made it a function that is easily reusable function renderForm($company_name = '', $contact ='', $phone ='', $error = '', $id = '') { ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title> <?php if ($id != '') { echo "Edit Record"; } else { echo "Add Record"; } ?> </title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <h1><?php if ($id != '') { echo "Edit Record"; } else { echo "Add Record"; } ?></h1> <?php if ($error != '') { echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error . "</div>"; } ?> <form action="" method="post"> <div> <?php if ($id != '') { ?> <input type="hidden" name="id" value="<?php echo $id; ?>" /> <p>ID: <?php echo $id; ?></p> <?php } ?> <table> <tr> <td><strong>Company Name:</td> <td></strong> <input type="text" name="company_name" value="<?php echo $company_name; ?>"/> *</td> </tr> <tr> <td><strong>Contact Name:</td> <td></strong> <input type="text" name="contact" value="<?php echo $contact; ?>"/> *</td> <tr> <td><strong>Phone:</td> <td></strong> <input type="text" name="phone" value="<?php echo $phone; ?>"/> *</td> </tr> <tr> <td> </td> <td>*Required <input type="submit" name="submit" value="Submit" /></td> </tr> </table> </div> </form> </body> </html> <?php } /* EDIT RECORD */ // if the 'id' variable is set in the URL, we know that we need to edit a record if (isset($_GET['id'])) { // if the form's submit button is clicked, we need to process the form if (isset($_POST['submit'])) { // make sure the 'id' in the URL is valid if (is_numeric($_POST['id'])) { // get variables from the URL/form $id = $_POST['id']; $company_name = htmlentities($_POST['company_name'], ENT_QUOTES); $contact = htmlentities($_POST['contact'], ENT_QUOTES); $phone = htmlentities($_POST['phone'], ENT_QUOTES); // check that company_name and contact are both not empty if ($company_name == '', $contact == '', $phone == '') { // if they are empty, show an error message and display the form $error = 'ERROR: Please fill in all required fields!'; renderForm($company_name, $contact, $error, $phone, $id); } else { // if everything is fine, update the record in the database if ($stmt = $mysqli->prepare("UPDATE client_list SET company_name=?, contact=?, phone=?, WHERE id=?")) { $stmt->bind_param("ssi", $company_name, $contact, $phone, $id); $stmt->execute(); $stmt->close(); } // show an error message if the query has an error else { echo "ERROR: could not prepare SQL statement."; } // redirect the user once the form is updated header("Location: crud-view.php"); } } // if the 'id' variable is not valid, show an error message else { echo "Error!"; } } // if the form hasn't been submitted yet, get the info from the database and show the form else { // make sure the 'id' value is valid if (is_numeric($_GET['id']) && $_GET['id'] > 0) { // get 'id' from URL $id = $_GET['id']; // get the recod from the database if($stmt = $mysqli->prepare("SELECT * FROM client_list WHERE id=?")) { $stmt->bind_param("i", $id); $stmt->execute(); $stmt->bind_result($id, $company_name, $contact, $phone); $stmt->fetch(); // show the form renderForm($company_name, $contact, $phone, NULL, $id); $stmt->close(); } // show an error if the query has an error else { echo "Error: could not prepare SQL statement"; } } // if the 'id' value is not valid, redirect the user back to the view.php page else { header("Location: view.php"); } } } /* NEW RECORD */ // if the 'id' variable is not set in the URL, we must be creating a new record else { // if the form's submit button is clicked, we need to process the form if (isset($_POST['submit'])) { // get the form data $company_name = htmlentities($_POST['company_name'], ENT_QUOTES); $contact = htmlentities($_POST['contact'], ENT_QUOTES); $phone = htmlentities($_POST['phone'], ENT_QUOTES); // check that company_name and contact are both not empty if ($company_name == '' || $contact == '' || $phone == '') { // if they are empty, show an error message and display the form $error = 'ERROR: Please fill in all required fields!'; renderForm($company_name, $contact, $phone, $error); } else { // insert the new record into the database if ($stmt = $mysqli->prepare("INSERT client_list (company_name, contact, phone) VALUES (?, ?, ?)")) { $stmt->bind_param("ss", $company_name, $contact, $phone); $stmt->execute(); $stmt->close(); } // show an error if the query has an error else { echo "ERROR: Could not prepare SQL statement."; } // redirec the user header("Location: crud-view.php"); } } // if the form hasn't been submitted yet, show the form else { renderForm(); } } // close the mysqli connection $mysqli->close(); ?> Thanks, Herbert
  6. Hi Ben, it is actually if($name =='' || $last == '' || $phone == ''). I wonder if it's OK to use OR 3x? I don't want to post the whole codes I'm tying to solve it my self. Thanks! Herbert at GC.
  7. Hi Guys Help! This topic is from Complete Web Programmer tutorial (FYI the tutorial is great!). I'm trying to add a new row to the view.php page, I inserted a new row in PHPMyAdmin. I tweaked the codes (record.php), but it won't add the new record. The code currently use if statement to check for rows like this "if($name =='' || $last =='')", my code "if($name =='' || $last =='' || $mycode)" could the be the problem? I used OR 3x within if statement.??? Thank you, -- Herbert at GC
  8. Ben bro I hate to say this, but it works! Thanks again, Herbert
  9. Noting happens no errors or anything. I'll change the code on view.php. Thanks Ben
  10. Hi guys this topic is from video tutorial (Complete web programing)"PHP CRUD". From video tutorial "php_crud" -- videos: mysqli-2 "view.php" and mysqli- "delete.php" Problem: Can't delete a record (please help codes below). delete.php code =========================================================== <?php include('db-connect.php'); if (isset($_GET['id']) && is_numeric($_GET['id'])) { $id = $_GET['id']; if($stmt = $mysqli->prepare("DELETE FROM records WHERE id = ? LIMIT 1")) { $stmt->bind_param("i",$id); $stmt->execute(); $stmt->close(); } else { echo "Error: Could not prepare sql etatement"; } $mysqli->close(); header("Location: view.php"); } else { header("Location: view.php"); } ?> =================================================================== view.php code =================================================================== <?php include('db-connect.php'); if ($result = $mysqli->query("SELECT * FROM records ORDER BY id")) { if($result->num_rows > 0); { echo "<table border='1' cellpadding='10'>"; echo "<tr><th>ID</th><th>First Name</th><th>Last Name</th><th></th><th></th></tr>"; while ($row = $result->fetch_object()) { echo "<tr>"; echo "<td>" . $row->id . "</td>"; echo "<td>" . $row->firstname . "</td>"; echo "<td>" . $row->lastname . "</td>"; echo "<td><a href='records.php?id" . $row->id . "'>Edit</a></td>"; echo "<td><a href='delete.php?id" . $row->id . "'>Delete</a></td>"; echo "</tr>"; } echo "</table>"; } } else { echo "Error: " . $mysqli->error; } $mysqli->close(); ?> Thanks, Herbert
  11. Hi Ben, Thanks for adding validation to the PHP code. Works great! I appreciate your help! FYI, I just purchased the Killer PHP complete web programming video tutorial. You guys did a great job putting it together! Love it, highly recommended. Thanks again, Herbert
  12. PHP code below --------------------------------------- <?php $about = $_REQUEST['about']."\n"; $priority = $_REQUEST['priority']."\n"; $name = $_REQUEST['name']."\n"; $email = $_REQUEST['email']."\n"; $phone = $_REQUEST['phone']."\n"; $fax = $_REQUEST['fax']."\n"; $company = $_REQUEST['company']."\n"; $callme = $_REQUEST['callme']."\n"; $comments = $_REQUEST['comments']."\n"; $email_message = "About: {$about} Priority: {$priority} Name: {$name} E-mail: {$email} Phone: {$phone} Fax: {$fax} Message: {$comments} Company: {$company} Please call me at: {$callme}"; mail('email@sbcglobal.net','GC Feedback', $email_message); ?> ---------------------------------------- Again I'm using Dreamweaver to validate the form. Thanks, Herbert
  13. Form source code below ------------------------------------------------------------- <form method="post" action="contact.php"> <div align="right"> <table width="242" height="212" border="0" align="center" cellpadding="0" cellspacing="0"><tr> <td colspan="3" align="left" class="style4"><label><strong><span class="style5 style6 style12"><br/> </span><span class="style10">Contact Us</span><br /> About:</strong> <select name="about" id="about"> <option selected="selected">Click Here</option> <option value="Graphic Design">Graphic Design </option> <option value="Website Design">Website Design </option> <option value="Logo Design">Logo Design</option> <option value="Signage">Signage</option> <option value="Printed Promotional Materials">Printed Promotional Materials</option> <option value="Technical Illustration">Technical Illustration</option> <option value="Packaging Design">Packaging Design</option> <option value="Website Update, Existing Customer">Website Update, Existing Customer</option> <option value="Website Update, New Customer">Website Update, New Customer</option> <option value="Labels & Decals">Labels & Decals</option> <option value="OEM Custom Die Cut Decals">OEM Custom Die Cut Decals</option> <option value="Labels & Decals RND/Prototyping">Labels & Decals RND/Prototyping</option> <option value="Membrane Switch Production Engineering">Membrane Switch Production Engineering</ption> <option value="Material Data Sheet">Material Data Sheet</option> </select><br /></label><br /> <strong>Priority:</strong><br /> High <input type="radio" name="priority" id="priority" value="High" /> Normal <input type="radio" name="priority" id="priority2" value="Normal" /> Low <input type="radio" name="priority" id="priority3" value="Low" /> <br /> </label></td></tr> <tr><td width="49" class="style4"><div align="right" class="style29"> <label for="ID_textfieldName_1C7E60E43BF7560"></label><div class="contact"> <div align="left" class="style19"><p align="right" class="style3">Name:</p> </div></div></div></td><td width="1" class="style4"></td> <td width="304" class="style4"><div align="left"> <input name="name" type="text" id="name" size="30" /> </div></td> </tr><tr><td class="style4">Company:</td><td class="style4"></td> <td class="style4"><input name="company" type="text" id="company" size="30" /></td></tr> <tr><td class="style4"><div align="right" class="style29"><label for="ID_textfieldName_1C7E60E5088ED30"> </label><div class="contact"><div align="left" class="style3"> <div align="right">E-mail:</div></div></div></div></td><td width="1" class="style4"></td> <td width="304" class="style4"><div align="left"> <input name="email" type="text" id="email" size="30" /></div></td></tr> <tr><td class="style4"><div align="right" class="style29"> <label for="ID_textfieldName_1C7E60E580F5940"> </label> <div class="contact"><div align="left" class="style3"> <div align="right">Phone:</div></div></div></div></td> <td width="1" class="style4"></td><td width="304" class="style4"> <div align="left"><input id="phone" type="text" name="phone" size="30" /> </div></td></tr><tr><td class="style4"><div align="right" class="style29"> <label for="ID_textfieldName_1C7E60E5A5EA070"> </label><div class="contact"> <div align="left" class="style3"><div align="right">Fax:</div></div> </div></div></td><td width="1" class="style4"></td> <td width="304" class="style4"><div align="left"> <input id="fax" type="text" name="fax" size="30" /> </div></td></tr><tr><td colspan="3" class="style4"></td> </tr><tr><td height="25" colspan="3" valign="bottom" class="style4"><div align="center"> <div class="contact"><div align="left" class="style7"> <font face="Arial">Please enter your message below</font>:</div> </div></div></td></tr><tr><td colspan="3"></td></tr><tr> <td colspan="3" align="left"><div align="left"><p> <textarea name="comments" rows="6" cols="32" id="comments"></textarea><br /> <input type="submit" onclick="MM_validateForm('name','','R','company','','R','email','','RisEmail');return document.MM_returnValue" value="Send" /><input type="reset" name="Reset" id="button" value="Reset" /> </p></div></td></tr><tr><td colspan="3"></td></tr></table><br /></div> <div align="right"></div> </form> ------------------------------------------ Thanks, Herbert
  14. The contact form is entirely built using HTML, and use PHP as processor. I think I will have to re-build the contact form using PHP to self submit, but I don't really now much about PHP yet. Thanks, Herbert
  15. Hi Ben, Thanks for your input. I'm using Dreamweaver to validate the form. I kind of think that someone has been viewing my contact page source code, cut and paste the full path to the browser, hit enter (key board) and goes the blank email. The reason I said this is because I was able to re-create it. So I was thinking that if I can hide the action attributes or the value then it will not be visible in the source code.??? Thanks, Herbert
  16. Hello everyone! I am new to this forum. I am really glad to be here. Help:( I've been receiving blank email from our website's contact us mail form. Is there a way to hide the action attribute so that it looks like this "action=" " ". Your help will be greatly appreciated - Herbert
  17. Hello everyone. I am new to this forum. I am really glad to be here.

×
×
  • Create New...