Jump to content

php-newbies

Members
  • Posts

    47
  • Joined

  • Last visited

    Never

Everything posted by php-newbies

  1. Thank you so much for the code, but I have tried to run the code independently but it will not run. I am such I have messed up the code. But is there any way I can include part of your code in my php code so that I can still use my html page. <?php //connect to the database $con = mysql_connect("localhost","dbusrn","pwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); //Set values for populating form $fname = ''; $lname = ''; //error tracking variable $errors = array(); //Check if form was posted if($_SERVER['REQUEST_METHOD']=='POST') { //Validate input $fname = trim($_POST['fname']); $lname = trim($_POST['lname']); if(empty($fname)) { $errors[] = "First name is required."; } if(empty($lname)) { $errors[] = "Last name is required."; } //If no format errors, check if there is a match if(count($errors)) { $fnameSQL = mysql_real_escape_string($fname); $lnameSQL = mysql_real_escape_string($lname); $query = "SELECT * FROM Customer_Registration WHERE Firstname = '$fnameSQL' AND Lastname = '$lnameSQL'"; $result = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result)<1) { //No record found $errors[] = "No user found with the name '{$fname} {$lname}'"; } else { //Include the page to update the user. //Use the results of this query to populate the form include('update-Exist-cus.php'); exit(); } } } $errorMsg = ''; if(count($errors)) { $errorMsg .= "The following errors occured:"; $errorMsg .= "<ul>"; foreach($errors as $err) { $errorMsg .= "<li>{$err}</li>"; } $errorMsg .= "</ul>"; } ?> <html> <body> <div style="color:red;">$errorMsg</div> <form action="" method="post"> First Name: <input type="text" name="fname" value="<?php echo $fname; ?>"><br> Last Name: <input type="text" name="lname" value="<?php echo $lname; ?>"><br> <button type="submit">Check Name</button> </form> </body> </html>
  2. Hi again. I have this code up and running. Basically I have html form page with 2 text boxes namely Firstname and lastname plus submit button. Now when the user enter a random name or just hit the submit button this page still loads up though they are blank fields. What I want now is that I want to block the page from loading the fields if the user enter the wrong name or submitting an empty field instead display an error message. Many thanks My code so far is this. <?php //connect to the database $con = mysql_connect("localhost","usrn","pwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); $Firstname = $_POST['Fname']; $Lastname = $_POST["Lname"]; $result = mysql_query ("select * from Customer_Registration WHERE Firstname = '$Fname' AND Lastname = '$Lname' "); $row = mysql_fetch_row($result); $cf_id = $row[0]; $Firstname = $row[6]; $Lastname = $row[7]; $Address = $row[8]; $Postcode = $row[9]; $Phone = $row[10]; $Email = $row[11]; $Customer_Type = $row[12]; $Computer_type = $row[13]; $Computer_maker = $row[14]; $Model = $row[15]; $OS = $row[16]; $Appointment_date = $row[17]; $Problem = $row[18]; ?> <?php print( '<a href="http://www.gopcss.com/">Click here to go back to home page <p></a>');?> <form action="update-Exist-cus.php" method="post"> <table width="30%" border="2" cellspacing="0" cellpadding="8"> <tr><td width="" class="FormText">Customer ID:</td> <td width=""><?php echo $row[0]; ?></td></tr> <tr><td width="10%" class="FormText">First name:</td> <td width=""><?php echo $row[6]; ?></td></tr> <tr><td width="10%" class="FormText">Last name:</td> <td width=""><?php echo $row[7]; ?></td></tr> <tr><td width="10%" class="FormText">Address:</td> <td width="10%"><input name="Address" type="text" value="<?php echo $Address; ?>"?> </td></tr> <tr><td width="10%" class="FormText">Postcode:</td> <td width="10%"><input name="Postcode" type="text" value="<?php echo $Postcode; ?>"?> </td></tr> <tr><td width="10%" class="FormText">Phone:</td> <td width="10%"><input name="Phone" type="text" value="<?php echo $Phone; ?>"?> </td></tr> <tr><td width="10%" class="FormText">Email:</td> <td width="10%"><input name="Email" type="text" value="<?php echo $Email; ?>"?> </td></tr> <tr><td width="10%" class="FormText">Customer:</td> <td width="10%"><input name="Customer_Type" type="text" value="<?php echo $Customer_Type; ?>"?> </td></tr> <tr><td width="10%" class="FormText">Computer :</td> <td width="10%"><input name="Computer_type" type="text" value="<?php echo $Computer_type; ?>"?> </td></tr> <tr><td width="10%" class="FormText">Manufactural:</td> <td width="10%"><input name="Computer_maker" type="text" value="<?php echo $Computer_maker; ?>"?> </td></tr> <tr><td width="10%" class="FormText">Model:</td> <td width="10%"><input name="Model" type="text" value="<?php echo $Model; ?>"?> </td></tr> <tr><td width="10%" class="FormText">Operating System:</td> <td width="10%"><input name="OS" type="text" value="<?php echo $OS; ?>"?> </td></tr> <tr><td width="10%" class="FormText">Appointment:</td> <td width="10%"><input name="Appointment_date" type="text" value="<?php echo $Appointment_date; ?>"?> </td></tr> <tr><td width="10%" class="FormText">Problem:</td> <td width="10%"><textarea name="Problem" rows="10" cols="20" ><?php echo $Problem; ?></textarea></td></tr> <td width="10%"><input name="submit" value="submit" type="submit" <br> <input type="Submit" value="Cancel"</br></td> <td width="10%"><input type="hidden" name="cf_id" value="<?php echo $row[0]; ?>" /></td></tr> </form> <?php ?>
  3. Thanks for your suggestion. Actually I have update.php to update existing records. I think to check for firstname and phone number duing registration will be a good idea and if both matches then it should open up update.php automatically. But do not know how to link this files together. Thanks ahain for your time
  4. Hello litebearer, many thanks for your response. I have this code for my customer.php <?php //connect to the database $con = mysql_connect("localhost","usrn","pwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); $Firstname = ['Firstname']; $Lastname = ['Lastname']; $Address = ['Address']; $Postcode = ['Postcode']; $Phone = ['Phone']; $Email = ['Email']; $Problem =['Problem']; mysql_query("INSERT INTO Customers (FirstName, LastName, Address, Postcode, Phone, Email, Problem) VALUES ('$Firstname', '$Lastname', '$Address', '$Postcode', '$Phone', '$Email', '$Problem')"); ?> Need help to check if the customer firstname and lastname already exist before inserting the records and if already exist it should not create a new id instead just update the table.
  5. I have a customer registration form up and running, the form allows customers to complete the forms and the data is then inserted into mysql db table via php form. I want to prevent duplicates records from already existing customers from creating a new records instead I want the customers to update their existing records in the backend. That is allow them to complete the form as normal, once they hit the submit button, the code should check if the customer first name and last name is already in the database if yes then it should update their records and if not it should insert new record to the table. I do not want to alert the customer that their records already exist. I do not know where to start. Please help Thank you so much in advance for your help.
  6. I appreciate all the help from you and Pikachu2000. Working now. Many thanks.
  7. I appreciate all the help from you and Pikachu2000. This is what is happening. I have 3 user cf_ids in the table namely 48, 47 and 51 all these 3 have different first names and last names etc cf_id 48 mark as first name cf_id 47 Peter as first name cf_id 51 Lisberth as first name Say I search Lisberth and it loads all its records after making a few changes I hit the submit button. these is what happens Liberth replaces Mark as first name as well other records on the column Liberth replaces Peter as first name as well other records on the column If I search for Mark or Peter I get empty textboxes. I do not know what is going on really. Pulling my hair off. It just deletes or previous records and replaces it with it own.
  8. Thanks again for your help, but how do I pass the value of cf_id in the form "search.php" and the value location.
  9. ok, error msg below. thanks UPDATE Customer_Registration SET Firstname='Mark',lastname='Peterson',Address='pitfield',Postcode='EC2 5GH',Phone='000245876',Email='blackogbe@yahoo.com',Customer_Type='Home',Computer_type='Laptop',Computer_maker='Acer',Model='aspire 1241',OS='Windows7', Appointment_date='2011-09-28 11:08:31',Problem='344bgte',Solution='I like working with mark',Comment='hello' WHERE cf_id=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 '' at line 2
  10. Thanks for your response, I have tried that but got a syntax error
  11. I have 3 set of pages. The first html page only contains a search textbox and a submit button which then call up the second page search.php which populate html table with search result. The third page is update.php which allows to update the records populated by search.php. The problem is that it when it update the records it automatically updates all rows in the table making all records look the same. I do not know where I have made a mistake please help. When I use phpadmin to update the records no problem as I can specifically input the cf_id number directly. Search.php code <?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("^/[A-Za-z]+/", $_POST['name'])){ $name=$_POST['name']; } } else{ echo "<p>Please enter a search query</p>"; } } //connect to the database $con = mysql_connect("localhost","dbusrn","dbpwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); $name = $_POST['name']; $result = mysql_query ("select * from Customer_Registration where Firstname like '%$name%' or lastname like '%$name%' "); $row = mysql_fetch_row($result); $cf_uid = $row[0]; $Firstname = $row[6]; $lastname = $row[7]; $Address = $row[8]; $Postcode = $row[9]; $Phone = $row[10]; $Email = $row[11]; $Customer_Type = $row[12]; $Computer_type = $row[13]; $Computer_maker = $row[14]; $Model = $row[15]; $OS = $row[16]; $Appointment_date = $row[17]; $Problem = $row[18]; $Solution = $row[19]; $Comment = $row[20]; ?> <form action="updatecus.php" method="post"> <table width="100%" border="2" cellspacing="0" cellpadding="8"> <tr><td width="45%" class="FormText">Customer ID:</td> <td width="55%"><?php echo $row[0];?></td></tr> <tr><td width="45%" class="FormText">First name:</td> <td width="55%"><input name="Firstname" type="text" value="<?php echo $Firstname;?>"?> </td></tr> <tr><td width="45%" class="FormText">Last name:</td> <td width="55%"><input name="lastname" type="text" value="<?php echo $lastname;?>"?> </td></tr> <tr><td width="45%" class="FormText">Address:</td> <td width="55%"><input name="Address" type="text" value="<?php echo $Address; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Postcode:</td> <td width="55%"><input name="Postcode" type="text" value="<?php echo $Postcode; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Phone:</td> <td width="55%"><input name="Phone" type="text" value="<?php echo $Phone; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Email:</td> <td width="55%"><input name="Email" type="text" value="<?php echo $Email; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Customer:</td> <td width="55%"><input name="Customer_Type" type="text" value="<?php echo $Customer_Type; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Computer :</td> <td width="55%"><input name="Computer_type" type="text" value="<?php echo $Computer_type; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Manufactural:</td> <td width="55%"><input name="Computer_maker" type="text" value="<?php echo $Computer_maker; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Model:</td> <td width="55%"><input name="Model" type="text" value="<?php echo $Model; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Operating System:</td> <td width="55%"><input name="OS" type="text" value="<?php echo $OS; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Appointment:</td> <td width="55%"><input name="Appointment_date" type="text" value="<?php echo $Appointment_date; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Problem:</td> <td width="55%"><textarea name="Problem" rows="10" cols="20" ><?php echo $Problem; ?></textarea></td></tr> <tr><td width="45%" class="FormText">Solution:</td> <td width="55%"><textarea name="Solution" rows="10" cols="20" ><?php echo $Solution; ?></textarea></td></tr> <tr><td width="45%" class="FormText">Comment:</td> <td width="55%"><textarea name="Comment" rows="10" cols="20" ><?php echo $Comment; ?></textarea></td></tr> <td width="55%"><input name="submit" value="submit" type="submit" <br> <input type="Submit" value="Cancel"</br></td> </form> <?php ?> update.php code <?php //connect to the database $con = mysql_connect("localhost","dbusrn","dbpwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); //if (isset($_POST['submit'])) { $cf_id = $_POST['cf_id']; $Firstname = $_POST['Firstname']; $lastname = $_POST['lastname']; $Address = $_POST['Address']; $Postcode = $_POST['Postcode']; $Phone = $_POST['Phone']; $Email = $_POST['Email']; $Customer_Type = $_POST['Customer_Type']; $Computer_type = $_POST['Computer_type']; $Computer_maker = $_POST['Computer_maker']; $Model = $_POST['Model']; $OS = $_POST['OS']; $Appointment_date = $_POST['Appointment_date']; $Problem = $_POST['Problem']; $Solution = $_POST['Solution']; $Comment = $_POST['Comment']; if (isset($_POST['submit'])) { $query ="UPDATE Customer_Registration SET Firstname='$Firstname',lastname='$lastname',Address='$Address',Postcode='$Postcode',Phone='$Phone',Email='$Email',Customer_Type='$Customer_Type',Computer_type='$Computer_type',Computer_maker='$Computer_maker',Model='$Model',OS='$OS', Appointment_date='$Appointment_date',Problem='$Problem',Solution='$Solution',Comment='$Comment' WHERE cf_id=cf_id"or die (mysql_error()); echo $query; mysql_query($query) or die(mysql_error()); //mysql_close($con); echo "<p>Congrats Record Updated</p>"; } ?> Thank you in advance for your help
  12. first name and last name are different, but I have use the same email. I only have 2 set of code. The first one populate the form and the second update the records. I will try to use unique values and see what happens
  13. Yes that is what it suppose to do but it update other cf_uid making all records look the same
  14. I have a weird problem. Though is updating but it updates all other rows with same records. The idea was to update only records related to the user_id. Any ideas please
  15. Thanks. I have echo the string. Result below: UPDATE Customer_Registration SET Firstname='Dave',lastname='anderson',Address='56 Collington road',Postcode='SE34 5FG',Phone='078564258',Email='dave43@hotmail.com',Customer_Type='',Computer_type='Laptop',Computer_maker='Dell',Model='1534',OS='', Appointment_date='',Problem='My pc is really slow. driving my crazy',Solution='wref43g',Comment='wedwf4f' WHERE cf_uid=29 Congrats Record Updated I noticed that Appointment_date, Customer_Type and OS does not return any value. Still the table is not updated.
  16. ok, I get what you mean. I have removed the single quote ie WHERE cf_uid=$cf_uid but is still not updating the records.
  17. Thanks for your response. Sorry I did not understand what you mean. I need a pointer. Correction welcome.
  18. Hello all. Please I need help to update customer table. I get the texboxes populated with select query no problem. I have html page with a search box and when the user enter their first name or last name and click search it will call up the search.php file here is the file: This code below populate the textboxes to be updated: <?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("^/[A-Za-z]+/", $_POST['name'])){ $name=$_POST['name']; } } else{ echo "<p>Please enter a search query</p>"; } } //connect to the database $con = mysql_connect("localhost","dbusrn","dbpwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); $name = $_POST['name']; $result = mysql_query ("select * from Customer_Registration where Firstname like '%$name%' or lastname like '%$name%' "); $row = mysql_fetch_row($result); $cf_uid = $row[0]; $Firstname = $row[6]; $lastname = $row[7]; $Address = $row[8]; $Postcode = $row[9]; $Phone = $row[10]; $Email = $row[11]; $Customer_Type = $row[12]; $Computer_type = $row[13]; $Computer_maker = $row[14]; $Model = $row[15]; $OS = $row[16]; $Appointment_date = $row[17]; $Problem = $row[18]; $Solution = $row[19]; $Comment = $row[20]; ?> <form action="updatecus1.php" method="post"> <table width="100%" border="2" cellspacing="0" cellpadding="8"> <tr><td width="45%" class="FormText">Customer ID:</td> <td width="55%"><?php echo $cf_uid;?></td></tr> <tr><td width="45%" class="FormText">First name:</td> <td width="55%"><input name="Firstname" type="text" value="<?php echo $Firstname;?>"?> </td></tr> <tr><td width="45%" class="FormText">Last name:</td> <td width="55%"><input name="lastname" type="text" value="<?php echo $lastname;?>"?> </td></tr> <tr><td width="45%" class="FormText">Address:</td> <td width="55%"><input name="Address" type="text" value="<?php echo $Address; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Postcode:</td> <td width="55%"><input name="Postcode" type="text" value="<?php echo $Postcode; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Phone:</td> <td width="55%"><input name="Phone" type="text" value="<?php echo $Phone; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Email:</td> <td width="55%"><input name="Email" type="text" value="<?php echo $Email; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Customer:</td> <td width="55%"><input name="Customer_type" type="text" value="<?php echo $Customer_Type; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Computer :</td> <td width="55%"><input name="Computer_type" type="text" value="<?php echo $Computer_type; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Manufactural:</td> <td width="55%"><input name="Computer_maker" type="text" value="<?php echo $Computer_maker; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Model:</td> <td width="55%"><input name="Model" type="text" value="<?php echo $Model; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Operating System:</td> <td width="55%"><input name="First name" type="text" value="<?php echo $OS; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Appointment:</td> <td width="55%"><input name="Operating System" type="text" value="<?php echo $Appointment_date; ?>"?> </td></tr> <tr><td width="45%" class="FormText">Problem:</td> <td width="55%"><textarea name="Problem" rows="10" cols="20" ><?php echo $Problem; ?></textarea></td></tr> <tr><td width="45%" class="FormText">Solution:</td> <td width="55%"><textarea name="Solution" rows="10" cols="20" ><?php echo $Solution; ?></textarea></td></tr> <tr><td width="45%" class="FormText">Comment:</td> <td width="55%"><textarea name="Comment" rows="10" cols="20" ><?php echo $Comment; ?></textarea></td></tr> <td width="55%"><input name="submit" value="submit" type="submit" <br> <input type="Submit" value="Cancel"</br></td> </form> <?php -------------------------------------------------------------------------------------- The update.php file have the following code: <?php //connect to the database $con = mysql_connect("localhost","dbusrn","dbpwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("mydb", $con); if (isset($_POST['submit'])) { $cf_uid = $_POST['cf_uid']; $Firstname = $_POST['Firstname']; $lastname = $_POST['lastname']; $Address = $_POST['Address']; $Postcode = $_POST['Postcode']; $Phone = $_POST['Phone']; $Email = $_POST['Email']; $Customer_Type = $_POST['Customer_Type']; $Computer_type = $_POST['Computer_type']; $Computer_maker = $_POST['Computer_maker']; $Model = $_POST['Model']; $OS = $_POST['OS']; $Appointment_date = $_POST['Appointment_date']; $Problem = $_POST['Problem']; $Solution = $_POST['Solution']; $Comment = $_POST['Comment']; $query = "UPDATE Customer SET Firstname='$Firstname',lastname='$lastname',Address='$Address',Postcode='$Postcode',Phone='$Phone',Email='$Email',Customer_Type='$Customer_Type',Computer_type='$Computer_type',Computer_maker='$Computer_maker',Model='$Model',OS='$OS', Appointment_date='$Appointment_date',Problem='$Problem',Solution='$Solution',Comment='$Comment' WHERE cf_uid='$cf_uid '"; mysql_query($query) or die(mysql_error()); mysql_close($con); echo "<p>Congrats Record Updated</p>"; } ?> I got congrats record updated but in actual fact no record are updated. Please help MOD EDIT: code tags added.
×
×
  • 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.