Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,348 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,126 people online right now. Registration is fast and FREE... Join Now!




Connecting two mysql tables in PHP script

 
Reply to this topicStart new topic

Connecting two mysql tables in PHP script

neeno
post 26 Aug, 2008 - 03:23 AM
Post #1


New D.I.C Head

*
Joined: 14 Aug, 2008
Posts: 2

IPB Image

Hello people.. its my first post on this gr8 forum, i hope i placed it fine.
Anyway to the point, i know i aint much of an artist thats why i will try to explain the picture i posted.
So i have this table with events wich is shown to users, i made it so that certain event shows following:
[name of event] [date][time][details] , [name of event] is clickable and takes you to details site wich cointas a sign up textboxes. Now what do i need. I need a line of MySQl code wich will somehow bound the users who signed up to that specific event they clicked. I'm really a begginer, i wrote all this alone with a help of this book i bought and i kinda got stuck at this point.

I hope everything is somehow clear. Thanks for help.
User is offlineProfile CardPM

Go to the top of the page

CTphpnwb
post 26 Aug, 2008 - 05:48 AM
Post #2


D.I.C Regular

***
Joined: 8 Aug, 2008
Posts: 331



Thanked 19 times
My Contributions


When the user clicks, they're taken to another page, or the page is refreshed. You can use $_POST or $_GET to transfer information about what was clicked (and other information) to the new/refreshed page. Show us your code and we can offer suggestions as to what you want to post.

User is offlineProfile CardPM

Go to the top of the page

neeno
post 26 Aug, 2008 - 06:19 AM
Post #3


New D.I.C Head

*
Joined: 14 Aug, 2008
Posts: 2

ok first i got "admin" site where events are generated:

CODE
<?php

/**
* @neeno
* @copyright 2008
*/
//database connecting
mysql_connect("xx, "xx", "xx") or die(mysql_error());
mysql_select_db("xx") or die(mysql_error());
//checking fields and running ze code
if (isset($_POST['submit'])) {

//This makes sure they did not leave any fields blank
if (!$_POST['type'] | !$_POST['date'] | !$_POST['time'] | !$_POST['link'] | !$_POST['details'] ) {
die('You did not complete all of the required fields');
}
//inserting the event
$insert = "INSERT INTO dogodki (type, date, time, link, details)
VALUES ('".$_POST['type']."', '".$_POST['date']."','".$_POST['time']."','".$_POST['link']."','".$_POST['details']."')";
$add_member = mysql_query($insert);
}
?>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Untitled Document</title>
    </head>
    <body>
    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <fieldset>
        <legend>Data</legend>
            <p>
                <label>Type of event</label>
                <select name= "type">
                    <option>GvG</option>
                    <option>TA</option>
                    <option>HA</option>
                    <option>AB</option>
                    <option>Guild meeting</option>
                    </select>
            </p>
            <p>
                <label>Date of event</label>
                <input type = "text" name="date"/>
            </p>
            <p>
                <label>Time of event</label>
                <input type = "text" name="time"/>
            </p>
            <p>
                <label>Link to the build</label>
                <input type = "text" name="link"/>
            </p>
            <p>
                <label>Details</label>
                <textarea name = "details" rows = "10" cols = "30"></textarea>
            </p>
            <p>
            <input type="submit" name="submit" value="Add"/>
            </p>
    </fieldset>
    </form>
        
    </body>
</html>


Then i have the site where these generated events are shown:

CODE

<html>
<head>
</head>
<body>
<?php

/**
* @author
* @copyright 2008
*/

$conn = mysql_connect("xxx", "xxx", "xxx") or die (mysql_error());
mysql_select_db("xxx");

$sql = "SELECT type FROM dogodki";
$rezultat = mysql_query($sql, $conn) or die (mysql_error());
$sql1 = "SELECT date, time  FROM dogodki";
$rezultat1 = mysql_query($sql1, $conn) or die (mysql_error());
while($row = mysql_fetch_assoc($rezultat)){
    $row2 = mysql_fetch_assoc($rezultat1);
    foreach ($row as $name => $value){
    print "<a href = 'details.php'>$name: $value</a> ";}
    foreach ($row2 as $name => $value){
    print "$name: $value ";
    
    }
    print "<br/>";
    }
    
?>
</body>
</html>


These shown events are clickable and takes you to the next site:

CODE

<html>
<head>
</head>
<body>
<?php
$conn = mysql_connect("xxx", "xxx", "xxx") or die (mysql_error());
mysql_select_db("xxx");

$sql = "SELECT details FROM dogodki";
$rezultat = mysql_query($sql, $conn) or die (mysql_error());
while($row = mysql_fetch_assoc($rezultat)){
    foreach ($row as $name => $value){
    print "$name: $value ";
    
    }
    print "<br/>";
    }
    
?>

<form action="<?php echo $_SERVER['signup.php']; ?>" method="post">
    <fieldset>
        <legend>Sign up</legend>
        <p>
                
                <input type = "text" name="signup"/>
                <label>Sign up</label>
                
            </p>
        <p>
            
            <input type = "text" name= "late"/>
            <label>Minutes Late</label>
        </p>
        <p>
            <input type="submit" name="submit" value="Sign Up"/>
            </p>
    </fieldset>
    </form>
</body>


Here the users are suppose to sign up to the event they clicked. And this is where i got stuck.. i need this form in details.php to be submited and saved into database and the data has to be somehow connected to the events.
User is offlineProfile CardPM

Go to the top of the page

CTphpnwb
post 26 Aug, 2008 - 02:49 PM
Post #4


D.I.C Regular

***
Joined: 8 Aug, 2008
Posts: 331



Thanked 19 times
My Contributions


First, NEVER insert a $_POST directly into the database. That's a huge security hole.

Second, your code is all over the place. You need to organize it much more efficiently. There is nothing I see that would prevent this all from being on one page, and that would have the side benefit of causing you to see some of the obvious problems sooner.

User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/22/08 03:55AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month