Jump to content

ReeceSayer

Members
  • Posts

    97
  • Joined

  • Last visited

Everything posted by ReeceSayer

  1. All sorted thanks!!! final code is: <?php include("connection.php"); require_once "header.php"; // Include the database connection file. $username = $_SESSION['username']; $sql = "SELECT orderID, username, QtyHam, QtyCheese, QtyBLT, QtyCoke, QtyFanta, QtyDrPepper, DelCentre, DelAddress, DelAddressL2, DelPostCode FROM sandwich WHERE username='$username'"; //set quantities for each sandwich $QtyHam = "SELECT QtyHam FROM sandwich WHERE username='$username'"; $QtyCheese = "SELECT QtyCheese FROM sandwich WHERE username='$username'"; $QtyBLT = "SELECT QtyBLT FROM sandwich WHERE username='$username'"; $QtyCoke = "SELECT QtyCoke FROM sandwich WHERE username='$username'"; $QtyFanta = "SELECT QtyFanta FROM sandwich WHERE username='$username'"; $QtyDrPepper = "SELECT QtyDrPepper FROM sandwich WHERE username='$username'"; //set order values for each sandwich $Ham = "SELECT price FROM sandwiches WHERE sandwich = 'QtyHam'"; $Cheese = "SELECT price FROM sandwiches WHERE sandwich = 'QtyCheese'"; $BLT = "SELECT price FROM sandwiches WHERE sandwich = 'QtyBLT'"; $Coke = "SELECT price FROM sandwiches WHERE sandwich = 'QtyCoke'"; $Fanta = "SELECT price FROM sandwiches WHERE sandwich = 'QtyFanta'"; $DrPepper = "SELECT price FROM sandwiches WHERE sandwich = 'QtyDrPepper'"; //set price values $result = mysql_query($sql) or die('MySQL Error!<br />Query: '.htmlentities($sql).'<br />'.mysql_error()); $price = mysql_query($Ham) or die('MySQL Error!<br />Query: '.htmlentities($Ham).'<br />'.mysql_error()); $price2 = mysql_query($Cheese) or die('MySQL Error!<br />Query: '.htmlentities($Cheese).'<br />'.mysql_error()); $price3 = mysql_query($BLT) or die('MySQL Error!<br />Query: '.htmlentities($BLT).'<br />'.mysql_error()); $price4 = mysql_query($Coke) or die('MySQL Error!<br />Query: '.htmlentities($Coke).'<br />'.mysql_error()); $price5 = mysql_query($Fanta) or die('MySQL Error!<br />Query: '.htmlentities($Fanta).'<br />'.mysql_error()); $price6 = mysql_query($DrPepper) or die('MySQL Error!<br />Query: '.htmlentities($DrPepper).'<br />'.mysql_error()); // quantity values $quantity = mysql_query($QtyHam) or die('MySQL Error!<br />Query: '.htmlentities($QtyHam).'<br />'.mysql_error()); $quantity2 = mysql_query($QtyCheese) or die('MySQL Error!<br />Query: '.htmlentities($QtyCheese).'<br />'.mysql_error()); $quantity3 = mysql_query($QtyBLT) or die('MySQL Error!<br />Query: '.htmlentities($QtyBLT).'<br />'.mysql_error()); $quantity4 = mysql_query($QtyCoke) or die('MySQL Error!<br />Query: '.htmlentities($QtyCoke).'<br />'.mysql_error()); $quantity5 = mysql_query($QtyFanta) or die('MySQL Error!<br />Query: '.htmlentities($QtyFanta).'<br />'.mysql_error()); $quantity6 = mysql_query($QtyDrPepper) or die('MySQL Error!<br />Query: '.htmlentities($QtyDrPepper).'<br />'.mysql_error()); //fetch price result $Hamprice = mysql_fetch_row($price); $Cheeseprice = mysql_fetch_row($price2); $BLTprice = mysql_fetch_row($price3); $Cokeprice = mysql_fetch_row($price4); $Fantaprice = mysql_fetch_row($price5); $DrPepperprice = mysql_fetch_row($price6); //fetch quantity result $QtyHamprice = mysql_fetch_row($quantity); $QtyCheeseprice = mysql_fetch_row($quantity2); $QtyBLTprice = mysql_fetch_row($quantity3); $QtyCokeprice = mysql_fetch_row($quantity4); $QtyFantaprice = mysql_fetch_row($quantity5); $QtyDrPepperprice = mysql_fetch_row($quantity6); $total = $QtyHamprice[0] * $Hamprice[0] + $QtyCheeseprice[0] * $Cheeseprice[0] + $QtyBLTprice[0] * $BLTprice[0] + $QtyCokeprice[0] * $Cokeprice[0] + $QtyFantaprice[0] * $Fantaprice[0] + $QtyDrPepperprice[0] * $DrPepperprice[0] ; ?> <!-- end of php start of xhtml --> <!-- xhtml files require a DOCTYPE, then an html tag and then the head --> <!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" xml:lang="en" lang="en" > <!-- head defines Page Title, Character set and Stylesheet link --> <head> <title>Course Data</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link href="login.css" rel="stylesheet" type="text/css" /> </head> <!-- After the head, comes the body of your web page --> <body> <div class="container"> <CENTER> <!-- A Heading for the page --> <h1>Order List</h1> <!-- A table to display the data --> <table class="neat" border="2"> <tr> <th>orderID</th> <th>Qty Ham</th> <th>Qty Cheese</th> <th>Qty BLT</th> <th>Qty Coca-Cola</th> <th>Qty Fanta</th> <th>Qty Dr. Pepper</th> <th>Delivery Centre</th> <th>Delivery Address Line 1</th> <th>Delivery Address Line 2</th> <th>Delivery Post Code</th> </tr> </CENTER> <!-- enclose some PHP code to collect the data from the table in the database --> <?php // LOOP through all the records in the database table while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['orderID'] . "</td>"; echo "<td>" . $row['QtyHam'] . "</td>"; echo "<td>" . $row['QtyCheese'] . "</td>"; echo "<td>" . $row['QtyBLT'] . "</td>"; echo "<td>" . $row['QtyCoke'] . "</td>"; echo "<td>" . $row['QtyFanta'] . "</td>"; echo "<td>" . $row['QtyDrPepper'] . "</td>"; echo "<td>" . $row['DelCentre'] . "</td>"; echo "<td>" . $row['DelAddress'] . "</td>"; echo "<td>" . $row['DelAddressL2'] . "</td>"; echo "<td>" . $row['DelPostCode'] . "</td>"; echo "</tr><br><br>"; } // Free up the memory used for $result mysql_free_result($result); // Close the database connection mysql_close(); ?> <!-- Close the XHTML table --> </table> <p> <?php echo "Your total is: &#8356;<b>" . $total . "</b>"; ?> </p> <p><a href="home.php">Home</a></p> <p><a href="logout.php">Logout</a></p> </div> </body> </html> <?php require_once "footer.php"; ?> This appears to be working for me... thanks alot
  2. i know... i've done a poor job but i need a quick fix as i have to present this tomorrow... its not neccessary but i'd rather have it done... i had a rethink and tried to edit the code and got this: <?php include("connection.php"); require_once "header.php"; // Include the database connection file. $username = $_SESSION['username']; $sql = "SELECT orderID, username, QtyHam, QtyCheese, QtyBLT, QtyCoke, QtyFanta, QtyDrPepper, DelCentre, DelAddress, DelAddressL2, DelPostCode FROM sandwich WHERE username='$username'"; //set quantities for each sandwich $QtyHam = "SELECT QtyHam FROM sandwich WHERE username='$username'"; $QtyCheese = "SELECT QtyCheeseFROM sandwich WHERE username='$username'"; $QtyBLT = "SELECT QtyBLT FROM sandwich WHERE username='$username'"; $QtyCoke = "SELECT QtyCoke FROM sandwich WHERE username='$username'"; $QtyFanta = "SELECT QtyFanta FROM sandwich WHERE username='$username'"; $QtyDrPepper = "SELECT QtyDrPepper FROM sandwich WHERE username='$username'"; //set order values for each sandwich $Ham = "SELECT price FROM preorder WHERE sandwich = 'QtyHam'"; $Cheese = "SELECT price FROM preorder WHERE sandwich = 'QtyCheese'"; $BLT = "SELECT price FROM preorder WHERE sandwich = 'QtyBLT'"; $Coke = "SELECT price FROM preorder WHERE sandwich = 'QtyCoke'"; $Fanta = "SELECT price FROM preorder WHERE sandwich = 'QtyFanta'"; $DrPepper = "SELECT price FROM preorder WHERE sandwich = 'QtyDrPepper'"; $total = $Ham * $QtyHam; $result = mysql_query($sql) or die('MySQL Error!<br />Query: '.htmlentities($sql).'<br />'.mysql_error()); // $result2 = mysql_query($total) or die('MySQL Error!<br />Query: '.htmlentities($total).'<br />'.mysql_error()); ?> <!-- end of php start of xhtml --> <!-- xhtml files require a DOCTYPE, then an html tag and then the head --> <!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" xml:lang="en" lang="en" > <!-- head defines Page Title, Character set and Stylesheet link --> <head> <title>Course Data</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link href="login.css" rel="stylesheet" type="text/css" /> </head> <!-- After the head, comes the body of your web page --> <body> <div class="container"> <CENTER> <!-- A Heading for the page --> <h1>Order List</h1> <!-- A table to display the data --> <table class="neat" border="2"> <tr> <th>orderID</th> <th>Qty Ham</th> <th>Qty Cheese</th> <th>Qty BLT</th> <th>Qty Coca-Cola</th> <th>Qty Fanta</th> <th>Qty Dr. Pepper</th> <th>Delivery Centre</th> <th>Delivery Address Line 1</th> <th>Delivery Address Line 2</th> <th>Delivery Post Code</th> <th>Price Total</th> </tr> </CENTER> <!-- enclose some PHP code to collect the data from the table in the database --> <?php // LOOP through all the records in the database table while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['orderID'] . "</td>"; echo "<td>" . $row['QtyHam'] . "</td>"; echo "<td>" . $row['QtyCheese'] . "</td>"; echo "<td>" . $row['QtyBLT'] . "</td>"; echo "<td>" . $row['QtyCoke'] . "</td>"; echo "<td>" . $row['QtyFanta'] . "</td>"; echo "<td>" . $row['QtyDrPepper'] . "</td>"; echo "<td>" . $row['DelCentre'] . "</td>"; echo "<td>" . $row['DelAddress'] . "</td>"; echo "<td>" . $row['DelAddressL2'] . "</td>"; echo "<td>" . $row['DelPostCode'] . "</td>"; } echo "<td>" . $total['Price Total'] . "</td>"; echo "</tr>"; /* while ($row = mysql_fetch_array($result2)) { echo "<td>" . $row['Price Total'] . "</td>"; echo "</tr>"; } */ // Free up the memory used for $result mysql_free_result($result); // Close the database connection mysql_close(); ?> <!-- Close the XHTML table --> </table> <p> </p> <p><a href="home.php">Home</a></p> <p><a href="logout.php">Logout</a></p> </div> </body> </html> <?php require_once "footer.php"; ?> Thankyou
  3. your not at Leeds met are you? lol I'm rushing to do my project too lol
  4. sorry im not really with it at the minute... I'll post the code.. <?php include("connection.php"); require_once "header.php"; // Include the database connection file. $username = $_SESSION['username']; $sql = "SELECT orderID, username, QtyHam, QtyCheese, QtyBLT, QtyCoke, QtyFanta, QtyDrPepper, DelCentre, DelAddress, DelAddressL2, DelPostCode FROM sandwich WHERE username='$username'"; $result = mysql_query($sql) or die('MySQL Error!<br />Query: '.htmlentities($sql).'<br />'.mysql_error()); ?> <!-- end of php start of xhtml --> <!-- xhtml files require a DOCTYPE, then an html tag and then the head --> <!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" xml:lang="en" lang="en" > <!-- head defines Page Title, Character set and Stylesheet link --> <head> <title>Course Data</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link href="login.css" rel="stylesheet" type="text/css" /> </head> <!-- After the head, comes the body of your web page --> <body> <div class="container"> <CENTER> <!-- A Heading for the page --> <h1>Order List</h1> <!-- A table to display the data --> <table class="neat" border="2"> <tr> <th>orderID</th> <th>Qty Ham</th> <th>Qty Cheese</th> <th>Qty BLT</th> <th>Qty Coca-Cola</th> <th>Qty Fanta</th> <th>Qty Dr. Pepper</th> <th>Price Total</th> <th>Delivery Centre</th> <th>Delivery Address Line 1</th> <th>Delivery Address Line 2</th> <th>Delivery Post Code</th> </tr> </CENTER> <!-- enclose some PHP code to collect the data from the table in the database --> <?php // LOOP through all the records in the database table while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['orderID'] . "</td>"; echo "<td>" . $row['QtyHam'] . "</td>"; echo "<td>" . $row['QtyCheese'] . "</td>"; echo "<td>" . $row['QtyBLT'] . "</td>"; echo "<td>" . $row['QtyCoke'] . "</td>"; echo "<td>" . $row['QtyFanta'] . "</td>"; echo "<td>" . $row['QtyDrPepper'] . "</td>"; echo "<td>" . $row['Price'] . "</td>"; //Need to insert a total value here... echo "<td>" . $row['DelCentre'] . "</td>"; echo "<td>" . $row['DelAddress'] . "</td>"; echo "<td>" . $row['DelAddressL2'] . "</td>"; echo "<td>" . $row['DelPostCode'] . "</td>"; echo "</tr>"; } // Free up the memory used for $result mysql_free_result($result); // Close the database connection mysql_close(); ?> <!-- Close the XHTML table --> </table> <p> </p> <p><a href="home.php">Home</a></p> <p><a href="logout.php">Logout</a></p> </div> </body> </html> <?php require_once "footer.php"; ?> Thanks
  5. okay so i need to find a total price for an order but i have the orders and prices in different tables... for example... in one table i have: (Sandwich Table) orderid sandwich price 1 QtyCheese 1.99 2 QtyHam 2.29 3 QtyBLT 2.09 4 QtyCoke 0.79 5 QtyDrPepper 0.79 6 QtyFanta 0.79 and in the other i have: (Preorder Table) orderid username QtyCheese QtyBLT QtyHam QtyCoke QtyFanta QtyDrPepper DelCentre DelAddress DelAddressL2 DelPostCode OrderExp orderdate 5 RSayer 2 3 1 4 5 6 Dewsbury uigubvr vhjkvnjkvjk jkbrfjkbe 6 2009-05-13 11:59:31 (sorry not sure i could format this properly) Basically i need some code to take the values from the second table, Preorder, and times them by the prices i have set out... Is there any way to do this? I think i've set the tables out quite awkwardly... but any help would be great!!! Thanks Reece
  6. yeah thats it worked perfectly thanks alot
  7. Right i have a form which when a radio button is selected it inserts a number, 5, 10, 15 or 20 into my table... what i'm trying to do is make it so when an administrator runs a script it will subtract 1 from the value in this row for all fields in the table... thanks
  8. yeah just reread the code... this topic can be deleted... i missed 3 $ signs from the beggining of a string...thanks
  9. Okay so i have the following code: <?php require_once "header.php"; echo "". $_SESSION['username']; echo " You are currently logged in " ; ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <br><br> <form action="authenticateorder.php" method="POST"> <!-- you can use another action if you'd like --> <fieldset> <legend>Order</legend> <label>Ham:</label><br> <input type="text" name="Qtyham" id="Qtyham" size="2" maxlength="2"><br> <label>Cheese:</label><br> <input type="text" name="Qtycheese" id="Qtycheese" size="2" maxlength="2"><br> <label>BLT:</label><br> <input type="text" name="QtyBLT" id="QtyBLT" size="2" maxlength="2"><br> <label>Coca-Cola:</label><br> <input type="text" name="QtyCoke" id="QtyCoke" size="2" maxlength="2"><br> <label>Fanta</label><br> <input type="text" name="QtyFanta" id="QtyFanta" size="2" maxlength="2"><br> <label>Dr. Pepper:</label><br> <input type="text" name="QtyDrPepper" id="QtyDrPepper" size="2" maxlength="2"><br> <form method="POST" action="my_form_server_program"> <p> <input type="radio" name="Headingly" value="Headingly"/>Headingly <input type="radio" name="Harrogate" value="Harrogate"/>Harrogate <input type="radio" name="Wakefield" value="Wakefield"/>Wakefield <input type="radio" name="Dewsbury" value="Dewsbury"/>Dewsbury </p> </form> <input type="submit" name="submit" id="submit" value="Submit"> <a href="logout.php"> Logout </a> </fieldset> </form> </html> <?php require_once "footer.php"; ?> Which sends the results to my database yet when i go on the database the QtyCoke, QtyFanta & QtyDrPepper results are all missing... authenticate.php: <?php require_once "rehome.php"; if(!isset($_SESSION['username']) || !isset($_SESSION['sid']) ||!isset($_SESSION['ip'])) { header("Location: login.php"); exit; } // Include the database connection file. include("connection.php"); // Check if a person has clicked on submit. if(isset($_POST['submit'])) { // Create variables from each $_POST. $username = $_SESSION['username']; $Qtyham = $_POST['Qtyham']; $Qtycheese = $_POST['Qtycheese']; $QtyBLT = $_POST['QtyBLT']; $QtyCoke = $_POST['QtyCoke']; $QtyFanta = $_POST['QtyFanta']; $QtyDrPepper = $_POST['QtyDrPepper']; // Create a variable containing the SQL query. $query = "INSERT INTO `sandwich` (username, Qtyham, Qtycheese, QtyBLT, QtyCoke, QtyFanta, QtyDrPepper) VALUES ('$username', '$Qtyham', '$Qtycheese', '$QtyBLT', 'QtyCoke', 'QtyFanta', 'QtyDrPepper')"; // Perform the SQL query on the database. $result = mysql_query($query); // If the query failed, display an error. if(!$result) { echo "Your query failed. " . mysql_error(); // The dot seperates PHP code and plain text. } else { // Display a success message! echo "Thanks " . $username . " Your Order Has Been Confirmed<br>"; echo "You Will Be Redirected Shortly"; }} require_once "footer.php"; ?> Also... How would I go about using the radio buttons to input something like a yes/no field into my database? So i can see which delivery centre the product needs to go to? Thanks Again & Sorry for all of the posts today!
  10. hi i need to know how to add the current date & time into my mysql table when i send information in a form using php... basically when i send my form i want it to record datetime also... i have a table named "datetime", using the DATETIME type Thanks
  11. Yep thats sorted it Thanks alot for your help i owe ya one
  12. <?php // LOOP through all the records in the database table while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['orderID'] . "</td>"; echo "<td>" . $row['QtyHam'] . "</td>"; echo "<td>" . $row['QtyCheese'] . "</td>"; echo "<td>" . $row['QtyBLT'] . "</td>"; echo "</tr>"; } // Free up the memory used for $result mysql_free_result($result); // Close the database connection mysql_close(); ?> isn't that the code which should show the results in my table?
  13. right i think i needed to include a connection to my database so i added connection.php at the top... the result is i get an echo saying "Resource id #5" which i don't understand, followed by a blank table... and there are definately orders for my user...
  14. yes header.php contains <?php // Start a session session_start(); ?> <!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" xml:lang="en" lang="en"> <head> <title>Door Step Sandwiches</title> <meta http-equiv="content-type" content="application/xhtml; charset=utf-8" /> <link href="login.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="container"> <div id="header"> <h1><CENTER>DSS Logo / Door Step Sandwiches Title</CENTER></h1> </div>
  15. Trying to get information on an order for the username stored in the session... <?php require_once "header.php"; $username = $_SESSION['username']; $result = mysql_query("SELECT orderID, username, QtyHam, QtyCheese, QtyBLT FROM sandwich WHERE username='$username'"); echo $result; ?> <!-- end of php start of xhtml --> <!-- xhtml files require a DOCTYPE, then an html tag and then the head --> <!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" xml:lang="en" lang="en" > <!-- head defines Page Title, Character set and Stylesheet link --> <head> <title>Course Data</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link href="login.css" rel="stylesheet" type="text/css" /> </head> <!-- After the head, comes the body of your web page --> <body> <div class="container"> <!-- A Heading for the page --> <h1>Order List</h1> <!-- A table to display the data --> <table class="neat" border="2"> <tr> <th>orderID</th> <th>Qty Ham</th> <th>Qty Cheese</th> <th>Qty BLT</th> </tr> <!-- enclose some PHP code to collect the data from the table in the database --> <?php // LOOP through all the records in the database table while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['orderID'] . "</td>"; echo "<td>" . $row['QtyHam'] . "</td>"; echo "<td>" . $row['QtyCheese'] . "</td>"; echo "<td>" . $row['QtyBLT'] . "</td>"; echo "</tr>"; } // Free up the memory used for $result mysql_free_result($result); // Close the database connection mysql_close(); ?> <!-- Close the XHTML table --> </table> <p> </p> </div> <!-- End of container div --> <!-- And don't forget to close the body and html --> </body> </html> <?php require_once "footer.php"; ?> Thanks
  16. Thanks For Your Help Everyone!! I've managed to sort it out... it was a case of me being an idiot and keeping to many backups and things open in notepad++ i had 2 files called authenticate.php in seperate locations but it was the wrong one running in my apache server... so i just dragged and dropped the other 1 to replace the old one and it worked fine... sorry to have wasted your time & thanks again!!
  17. anyone with any idead would be very much appreciated! thankyou
  18. Nothing... theres only the same success message... does that mean that the query failed? I just tried to test it by typing the following into the mysql run bar for the database: INSERT INTO `customerinfo` (FirstName, SecondName, HouseNumber, Address, AddressLine2, Town, City, PostCode) VALUES ('Reece', 'Sayer', '18', 'Rushymoor', 'Askern', 'Doncaster', 'Yorkshire', 'DN60NG'); This worked out fine...
  19. i added the line: $result2 = mysql_query($query2) or die(mysql_error()); i also wrote in the echo... not sure if this is right or where you suggested: echo "Welcome " . $username . " You are now registered"; echo "<a href=\"login.php\"> Continue To Login!</a>"; echo $query2; The outcome is still the same... i get a success message but no actual result in my database. Thanks for the quick replies btw... its like 3.30am over here lol
  20. its the customerinfo table that it doesn't insert to, the insert into users works perfectly. Ive just changed the && to an || and i get no difference, maybe that part of the script doesn't work? When I click submit on the form i get the message "Welcome RSayer You Are Now Registered" plus the next echo just like it should... so i guess the session is still remembering me. The table 'customerinfo' contains the following: userID : INT(11) : Auto-Increment FirstName : VARCHAR(255) SecondName : VARCHAR(255) HouseNumber : INT(2) Address : VARCHAR(255) AddressLine2 : VARCHAR(255) Town : VARCHAR(255) City : VARCHAR(255) PostCode : VARCHAR(255) Not sure wether that will help. I think this is ok but not 100% as its the first time I've used either php or mysql Thanks again
  21. Im creating a login/register form in php for my uni work but i can't seem to get my registration to write to my table. Below is the form code: <?php require_once "header.php"; ?> <html> <form action="authenticate.php" method="POST"> <label>First Name: </label><br> <input type="text" name="FirstName" id="FirstName"><br> <label>Second Name: </label><br /> <input type="text" name="SecondName" id="SecondName"><br> <label>House Number: </label><br> <input type="number" name="HouseNumber" id="HouseNumber"><br> <label>Address: </label><br> <input type="text" name="Address" id="Address"><br> <label>Address Line 2: </label><br> <input type="text" name="AddressLine2" id="AddressLine2"><br> <label>Town: </label><br /> <input type="text" name="Town" id="Town"><br> <label>City: </label><br> <input type="text" name="City" id="City"><br> <label>Post Code: </label><br /> <input type="text" name="PostCode" id="PostCode"><br> <label>Username: </label><br> <input type="text" name="username" id="username"><br> <label>Password: </label><br /> <input type="password" name="password" id="password"><br> <label>Confirm: </label><br> <input type="password" name="password2" id="password2"><br> <label>Email address:</label><br> <input type="text" name="email" id="email"><br> <input type="submit" name="submit" id="submit" value="Submit"> <a href="login.php"> Login </a> </form> </html> <?php require_once "footer.php"; ?> and this is the php: <?php require_once "header.php"; // Include the database connection file. include("connection.php"); // Check if a person has clicked on submit. if(isset($_POST['submit'])) { if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['password2']) || empty($_POST['email'])) { echo "You have to fill in everything in the form."; // Display the error message. header("Location: register.php"); // Redirect to the form. exit; // Stop the code to prevent the code running after redirecting. } // Create variables from each $_POST. $username = $_POST['username']; $password = $_POST['password']; $password2 = $_POST['password2']; $email = $_POST['email']; $FirstName = $_POST['FirstName']; $SecondName = $_POST['SecondName']; $HouseNumber = $_POST['HouseNumber']; $Address = $_POST['Address']; $AddressLine2 = $_POST['AddressLine2']; $Town = $_POST['Town']; $City = $_POST['City']; $PostCode = $_POST['PostCode']; // Now, compare passwords and check if they're the same. if($password != $password2) { // If the passwords are NOT the same. Again display an error message and redirect. echo "Sorry, wrong password."; header("Location: register.php"); exit; } // Secure the password using an md5 hash. $password = md5($password); // Create a variable containing the SQL query. $query = "INSERT INTO `users` (username, password, email) VALUES ('$username', '$password', '$email')"; $query2 = "INSERT INTO `customerinfo` (FirstName, SecondName, HouseNumber, Address, AddressLine2, Town, City, PostCode) VALUES ('$FirstName', '$SecondName', '$HouseNumber', '$Address', '$AddressLine2', '$Town', '$City', '$PostCode')"; // Perform the SQL query on the database. $result = mysql_query($query); $result2 = mysql_query($query2); // If the query failed, display an error. if(!$result && !$result2) { echo "Registration failed because of " . mysql_error() . "<br>"; // The dot seperates PHP code and plain text. echo "<a href=\"register.php\"> Try Again By Returning To The Registration Screen</a>"; } else { // Display a success message! echo "Welcome " . $username . " You are now registered"; echo "<a href=\"login.php\"> Continue To Login!</a>"; } } require_once "footer.php"; ?> </div> <!-- Footer Section --> <div id="footer"> <p>Created by <a href="metitsolutions.html">Met It Solutions</a></p> </div> </div> <!-- end container --> </body> </html> I didn't write this code but i have tried to edit it to suit my needs... Thanks
×
×
  • 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.