adamdyer Posted August 23, 2007 Share Posted August 23, 2007 here - i have to have the option where customers can add a booking once they are into the customer area - however I can get the data sent , but the data just ends up as a new customer rather then adding a booking to the original customers data. (if that makes sense) MakeABooking.php <!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-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php $CheckIn= $_GET['Check_In']; echo( "Check In = <B>$CID</B></br>" ); $CheckOut= $_GET['Check_Out']; echo( "Check Out = <B>$CID</B></br>" ); # connect to MySQL $conn = @mysql_connect("localhost","ajdref","ref2") or die ("sorry - could not wont connect to MySQL"); # select the specified database $rs = @mysql_select_db("ajdref", $conn) or die ("sorry - could not connect to the ajdref"); #create the query - sets $sql to contain the required query $sql = "SELECT * FROM `Booking Database`"; $sql = "INSERT INTO `Booking Database` (`Check In`, `Check Out`) VALUES ('$CheckIn', '$CheckOut')"; mysql_query($sql,$conn)or die(mysql_error()); if($rs){ echo("Booking added");} else { echo("Error! Booking not added");} ?> </body> </html> MakeABooking.html <!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-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <form NAME="GetCode" ACTION="makeabooking.php" METHOD="get"> <body> <p>Check In <INPUT Name ="Check_In" size = 20 > </p> <p>Check Out <INPUT Name ="Check_Out" size = 40 > </p> <div align="left"> <input type="reset" value="Clear" name="RESET"> <input type="submit" value="Send" name="SUBMIT" > </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/66324-how-i-do-i-add-a-specific-piece-of-of-data-into-a-specific-column-in-a-database/ Share on other sites More sharing options...
Fjerpje Posted August 23, 2007 Share Posted August 23, 2007 First of all dont ever show your database username en password connection Quote Link to comment https://forums.phpfreaks.com/topic/66324-how-i-do-i-add-a-specific-piece-of-of-data-into-a-specific-column-in-a-database/#findComment-331797 Share on other sites More sharing options...
adamdyer Posted August 23, 2007 Author Share Posted August 23, 2007 Good Point, I shall modify as such. EDIT - Oh, I Cant. tut Quote Link to comment https://forums.phpfreaks.com/topic/66324-how-i-do-i-add-a-specific-piece-of-of-data-into-a-specific-column-in-a-database/#findComment-331799 Share on other sites More sharing options...
Fjerpje Posted August 23, 2007 Share Posted August 23, 2007 And second remove the @ before the php tags and also remove the ' ' arround Booking Database and stuff Quote Link to comment https://forums.phpfreaks.com/topic/66324-how-i-do-i-add-a-specific-piece-of-of-data-into-a-specific-column-in-a-database/#findComment-331802 Share on other sites More sharing options...
Fjerpje Posted August 23, 2007 Share Posted August 23, 2007 And if i get your question straight you want to update a customer? or... can you rather explain it more Quote Link to comment https://forums.phpfreaks.com/topic/66324-how-i-do-i-add-a-specific-piece-of-of-data-into-a-specific-column-in-a-database/#findComment-331803 Share on other sites More sharing options...
xyn Posted August 23, 2007 Share Posted August 23, 2007 whats your database structure like? Quote Link to comment https://forums.phpfreaks.com/topic/66324-how-i-do-i-add-a-specific-piece-of-of-data-into-a-specific-column-in-a-database/#findComment-331804 Share on other sites More sharing options...
adamdyer Posted August 23, 2007 Author Share Posted August 23, 2007 yes basically, updating a customers data in my database so that once logged in, if they choose to 'Make A Booking' the data from that goes into their file on my database, however at the moment it dosnt do that, whatever the data the customer puts in my database thinks its creating a whole new customer rather then updating the original customers data. Quote Link to comment https://forums.phpfreaks.com/topic/66324-how-i-do-i-add-a-specific-piece-of-of-data-into-a-specific-column-in-a-database/#findComment-331807 Share on other sites More sharing options...
xyn Posted August 23, 2007 Share Posted August 23, 2007 do you have a separate table for customers and bookings? or the same? Quote Link to comment https://forums.phpfreaks.com/topic/66324-how-i-do-i-add-a-specific-piece-of-of-data-into-a-specific-column-in-a-database/#findComment-331808 Share on other sites More sharing options...
adamdyer Posted August 23, 2007 Author Share Posted August 23, 2007 same table but different columns. eg. - the customer data is in one table but each section - name, address, check in, check out etc etc are all in different columns Quote Link to comment https://forums.phpfreaks.com/topic/66324-how-i-do-i-add-a-specific-piece-of-of-data-into-a-specific-column-in-a-database/#findComment-331809 Share on other sites More sharing options...
Fjerpje Posted August 23, 2007 Share Posted August 23, 2007 Yeah thats oke but you'll need 2 diffrent tables Quote Link to comment https://forums.phpfreaks.com/topic/66324-how-i-do-i-add-a-specific-piece-of-of-data-into-a-specific-column-in-a-database/#findComment-331823 Share on other sites More sharing options...
Fjerpje Posted August 23, 2007 Share Posted August 23, 2007 Just create a second table bookings or add this to your code: <?php //Your Mysql information $host = "localhost"; $username = "username"; $password = "password"; //A permanent connection to your database takes some load off mysql server mysql_pconnect($host,$username,$password); //Automaticly make tables if they do not exist $query = "CREATE TABLE IF NOT EXISTS bookings(id INTEGER PRIMARY KEY,name VARCHAR(20),booking VARCHAR(100), and so on...)"; $mysql_query($query); $query = "CREATE TABLE IF NOT EXISTS people(id INTEGER PRIMARY KEY,nameVARCHAR(20),surname VARCHAR(20), and so on...)"; $mysql_query($query); <h3>Register</h3> ?> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> Name: <input type="text" name="name"><br> surname: <input type="test" name="surname"><br> <input type="submit" value="register"><input type="reset" value="reset"> </form> <?php $name = $_POST["name"]; $surname = $_POST["surname"]; if(!empty($name) && ($surname)) { } ?> Quote Link to comment https://forums.phpfreaks.com/topic/66324-how-i-do-i-add-a-specific-piece-of-of-data-into-a-specific-column-in-a-database/#findComment-331828 Share on other sites More sharing options...
Fjerpje Posted August 23, 2007 Share Posted August 23, 2007 And here the actual code to register people: Make this code your index.php <?php //Your Mysql information $host = "localhost"; $username = "username"; $password = "password"; $databasename = "databasename"; //A permanent connection to your database takes some load off mysql server mysql_pconnect($host,$username,$password); //Select database mysql_select_db($databasename); //Automaticly make tables if they do not exist $query = "CREATE TABLE IF NOT EXISTS bookings(id INTEGER PRIMARY KEY,name VARCHAR(20),booking VARCHAR(100), and so on...)"; $mysql_query($query); $query = "CREATE TABLE IF NOT EXISTS people(id INTEGER PRIMARY KEY,nameVARCHAR(20),surname VARCHAR(20), and so on...)"; $mysql_query($query); $name = $_POST["name"]; $surname = $_POST["surname"]; $submit = $_POST["submit"]; if(!empty($name) && ($surname)) { $query = "SELECT * FROM people WHERE name='$name' AND surname='$surname'"; $result = mysql_query($query); if(mysql_num_rows($result) > 0) { echo("A same user with this name already exists"); } else { $query = "INSERT INTO people VALUES(null,'$name','surname')"; mysql_query($query); echo("You have bin succesfully added to our database"); } } elseif(isset($submit)) { echo("Not all fields have bin filled in"); } else { ?> <h3>Register</h3> <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> Name: <input type="text" name="name"><br> surname: <input type="test" name="surname"><br> <input type="submit" name="submit" value="register"><input type="reset" value="reset"> </form> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/66324-how-i-do-i-add-a-specific-piece-of-of-data-into-a-specific-column-in-a-database/#findComment-331857 Share on other sites More sharing options...
Fjerpje Posted August 23, 2007 Share Posted August 23, 2007 And here the code to add bookings: Name this file bookings.php Quote Link to comment https://forums.phpfreaks.com/topic/66324-how-i-do-i-add-a-specific-piece-of-of-data-into-a-specific-column-in-a-database/#findComment-331860 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.