Jump to content

how I do I add a specific piece of of data into a specific column in a database?


Recommended Posts

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>

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.

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)) {

 

}

 

?>

 

 

 

 

 

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

}

?>

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.