I don't think it's possible but what I am trying to do is insert data into dynamic tables. (I know it's not in good db design but it's more for personal use than anything).

I'm trying to create a small memo script. The user selects the username or usernames from the dynamic textboxes, fills out the title and the body, the script formats the text and inserts it into the database. Everything works but I keep getting hung up on attempting to submit the data into multiple dynamic datatables... Here is my script as it currently stands:

<?php
$connection = mysql_connect('localhost','username','password')
or die ("Could not connect to MySQL!");   
$selectdb = mysql_select_db('userindex') or die ("Could not select to database!"); $result = mysql_query("SELECT DISTINCT fullname FROM profiles"); while($data = mysql_fetch_array($result)){ $fullname = $data[fullname]; $memoname = str_replace( ' ', '', $fullname ); $memoname = strtolower($memoname); echo "<input type=\"checkbox\" name=\"$memoname\" value=\"$memoname\""; if($memoname == "on"){echo" CHECKED";} echo "> $fullname <br>"; } ?>

As you see from that example the username starts out as "Christopher Joe" and is converted to "christopherjo" then set to the variable $memoname to be posted upon submission of the form (the rest of the form isn't shown)

<?php
$title=$_POST["title"]; 
$newtitle=str_replace(Chr(13),'<p>', $title); 
echo "$newtitle <br>"; 

$article=$_POST["article"]; 
$newarticle=str_replace(Chr(13),'<p>', $article); 
// the above is for formatting

$memoname = "christopherjo"; // this variable is set for individual testing

$con = mysql_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }mysql_select_db("memosystem", $con);

  $sql="INSERT INTO $memoname (personalmemo, personalmemotitle) values ('$newarticle', '$newtitle')";
  if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
  echo "Memo sent!";mysql_close($con)
?> 

That portion formats the text (keeps paragraphs as paragraphs) then attempts to insert the data into the proper datatable. It works perfactly with a single user (as shown above - I set the variable) however I can't wrap my head around attempting to insert the same memo to the other users... If there was some other function that I can use to create a type of "SQL echo" or some other idea to make this work please let me know.....

I would really appriciate it..
Christopher

    maybe I don't understand your problem exactly, but the only thing I can see that would be an issue is a table not existing, in which case you should call a CREATE IF NOT EXISTS before the insert. Also, can you elaborate on an SQL echo? this is the first I've heard of it ... other than echoing out SQL of course. That is a simple as echo $sql. ๐Ÿ˜‰

      I know it doesn't exsist. The tables do exsist because the registration script inserts them properly. I just need to know how to go about the sql query to where $newarticle and $newtitle are submitted to $memoname

      However $memoname is $_POST["memoname"] which contains multiple table names... How do I create an sql query to insert the same information into a dynamic table? Thats the question...

      could I set the variable of the memoname to loop username++ that way it auto increases and set the script to loop through the values of 1 to 50... I'm drawing a blank here....

        Maybe a better database design would be easier ๐Ÿ™‚

        I don't remember their names or schemas off-hand (not using MySQL myself), but I do recall that the DBMS has its own SQL database which records information about the tables and structure that the other databases have. You could perhaps query that for information about your database.

          create a suggestion script for the usernames, http://www.w3schools.com/ajax/ajax_source.asp

          The suggestion results are checkboxes, what the user could modify. (you could do with a site reload of course.)

          create a memo table, with the field s below:

          memo_id
          memo_title
          memo_body
          sender_id
          users_id
          date_time

          create an users table for the user's id list to the connected ID's.
          users_id
          connected_user_id
          readed_event

          And when the user signed in, write a checker program that select these connected tables.

          Dynamic table create? forget it.

          DarkJackalX6;10890443 wrote:

          I don't think it's possible but what I am trying to do is insert data into dynamic tables. (I know it's not in good db design but it's more for personal use than anything).

          I'm trying to create a small memo script. The user selects the username or usernames from the dynamic textboxes, fills out the title and the body, the script formats the text and inserts it into the database. Everything works but I keep getting hung up on attempting to submit the data into multiple dynamic datatables... Here is my script as it currently stands:

          <?php
          $connection = mysql_connect('localhost','username','password')
          or die ("Could not connect to MySQL!");   
          $selectdb = mysql_select_db('userindex') or die ("Could not select to database!"); $result = mysql_query("SELECT DISTINCT fullname FROM profiles"); while($data = mysql_fetch_array($result)){ $fullname = $data[fullname]; $memoname = str_replace( ' ', '', $fullname ); $memoname = strtolower($memoname); echo "<input type=\"checkbox\" name=\"$memoname\" value=\"$memoname\""; if($memoname == "on"){echo" CHECKED";} echo "> $fullname <br>"; } ?>

          As you see from that example the username starts out as "Christopher Joe" and is converted to "christopherjo" then set to the variable $memoname to be posted upon submission of the form (the rest of the form isn't shown)

          <?php
          $title=$_POST["title"]; 
          $newtitle=str_replace(Chr(13),'<p>', $title); 
          echo "$newtitle <br>"; 
          
          $article=$_POST["article"]; 
          $newarticle=str_replace(Chr(13),'<p>', $article); 
          // the above is for formatting
          
          $memoname = "christopherjo"; // this variable is set for individual testing
          
          $con = mysql_connect("localhost","username","password");
          if (!$con)
            {
            die('Could not connect: ' . mysql_error());
            }mysql_select_db("memosystem", $con);
          
            $sql="INSERT INTO $memoname (personalmemo, personalmemotitle) values ('$newarticle', '$newtitle')";
            if (!mysql_query($sql,$con))
            {
            die('Error: ' . mysql_error());
            }
            echo "Memo sent!";mysql_close($con)
          ?> 
          

          That portion formats the text (keeps paragraphs as paragraphs) then attempts to insert the data into the proper datatable. It works perfactly with a single user (as shown above - I set the variable) however I can't wrap my head around attempting to insert the same memo to the other users... If there was some other function that I can use to create a type of "SQL echo" or some other idea to make this work please let me know.....

          I would really appriciate it..
          Christopher

            <?
            if($_POST["memoname"])
            {
            $sql="INSERT INTO #1# (`field1`,`field2`,`field3`) VALUES ('1','2','3'); ";
            
            foreach($_POST["memoname"] AS $table)
            {
            $sql_query.=str_replace("`#1#`","$table",$sql);
            }
            
            echo $sql_query;
            }
            ?>

            However $memoname is $_POST["memoname"] which contains multiple table names... How do I create an sql query to insert the same information into a dynamic table? Thats the question...

              You shocked me with this method you want to do:

              in Hungary, there is a name "Kiss Jรกnos" which appears at home more than 100000 times.

              user authenticate hmm.... why is that ID in that database?
              rahter use that to make a user selected.

              and in checkboxes you use single variable for name, why don't you store that in an array???? users_for_database[]

                It was late at night when I posted that. This script is just for a small number of people to use maybe less than 10.. I didn't forsee common names as being an issue because I wasn't wanting to go farther than that lol. I was just wanting a quick and sloppy way of doing it but I guess the conventional is always proper... Thanks for the help guys I was just trying to find a shortcut ๐Ÿ˜›

                No worries, I'll use an array. lol

                  Write a Reply...