Announcement

Collapse
No announcement yet.

well it says newbies on the front !!!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • well it says newbies on the front !!!

    Hi, i know this is probably a very basic question.. i am learning!

    I have a form that is dynamically generated. Basically the script that i send the results of the forum does not know how many elements to expect. These are of the form

    name1, email1, name2, email2, name3, email3, name4, email4 etc.

    What i want is a WHILE loop that checks for data in an email field, then does something with it (like send an email), then the email number should get increased and start the while loop again.

    But i don't know how to do this, how do i check for like (name(x) != "") sort of thing, i don't know how to do it.

    I thought something like $name.$nameid or something like that but it does not work.

    I hope i am making sense. Thanks if you know what to do here.
    Christopher Padfield
    Web Based Helpdesk
    DeskPRO v3.0.3 Released - Download Demo Now!

  • #2
    I think you will have to post your code so we can get an idea of what you are doing.

    Comment


    • #3
      be kind

      First script. Generates the form. The $friends variable is inside config.php

      Code:
      <html>
      <head>
      </head>
      <body>
      <?php
      
      require("config.php");
      
      $email=1;
      $name=1;
      
      
      
      while ($email <= $friends) {
      
      	$friend_segment="
      
      	<P>Friends' Name:<INPUT type=\"text\" NAME=\"email$email\" SIZE=20><br>
      	Friends' Email:<INPUT type=\"text\" NAME=\"name$email\" SIZE=20>
      
      	";
      
      	$friend_block .="$friend_segment";
      
      	$email += 1;
      	$name += 1;
      }
      
      
      $form_block="
      
      <FORM METHOD=\"post\" ACTION=\"action.php\">
      
      <p><b>Your name:</b><br>
      <INPUT type=\"text\" NAME=\"refer_name\" SIZE=30></P>
      
      <p><b>Your Email:</b><br>
      <INPUT type=\"text\" NAME=\"refer_email\" SIZE=30></P>
      
      <P><b>Friends' Names and Email Addresses<b></p>
      
      <INPUT type=\"hidden\" NAME=\"op\" VALUE=\"ds\">
      
      ";
      
      $end_block="
      <p><INPUT type=\"submit\" NAME=\"submit\" VALUE=\"Send Messages\"</p>
      </FORM>
      ";
      
      $form_block .= "$friend_block";
      $form_block .= "$end_block";
      
      
      if ($op != "ds") {
      	// need to see the form
      	echo "$form_block";
      }
      
      
      ?>
      </body>
      </html>
      now i want to send this to the next script. Havn't really done much here:

      Code:
      <html>
      <head>
      </head>
      <body>
      <?php
      
      require("config.php");
      
      $email_count=1;
      
      
      $email ="blah";
      $email1 = "testing"
      
      $emailcheck = $email.$email_count;
      
      echo "$emailcheck"
      
      
      #while ($email.$email_count != "") {
      #	echo "$name$email_count";
      #	$email_count++;
      #	$emailcheck =$email.$email_count;
      }
      
      
      echo "<br>end!";
      
      
      ?>
      </body>
      </html>
      as i don't know how to. See what i am trying to do? Trying to use each of the name1, name2, name3 that come into it but don't know how to put the 1 on the end and keep it as the contents sent to the script.

      make sense?
      Christopher Padfield
      Web Based Helpdesk
      DeskPRO v3.0.3 Released - Download Demo Now!

      Comment


      • #4
        in words:

        say i had $email5 as [email protected]

        now i want to get this but i also want $email1, $email2

        so how do i make up this variable from the word email and $id starts at 1 and i can $id++

        i want something like

        $email$id which is the same as $email1 where $id=1 but i know this is not correct.

        You can tell i am new at this!
        Christopher Padfield
        Web Based Helpdesk
        DeskPRO v3.0.3 Released - Download Demo Now!

        Comment


        • #5
          arr.. done it. Using arrays in html. New to me

          so now i used:

          Code:
          <html>
          <head>
          </head>
          <body>
          <?php
          
          require("config.php");
          
          ?>
          
          
          <FORM METHOD="post" ACTION="action.php">
          
          <p><b>Your name:</b><br>
          <INPUT type="text" NAME="refer_name" SIZE=30></P>
          
          <p><b>Your Email:</b><br>
          <INPUT type="text" NAME="refer_email" SIZE=30></P>
          
          <P><b>Friends' Names and Email Addresses<b></p>
          
          <? for ($count = 1; $count <= $friends; $count++): ?>
          
          Name:
          <INPUT NAME="name[]" TYPE=TEXT><BR>
          Email:
          <INPUT NAME="email[]" TYPE=TEXT<BR><BR>
          
          <? endfor ?>
          
          <BR><INPUT TYPE=SUBMIT>
          
          </FORM>
          </body>
          </html>
          and then

          Code:
          <html>
          <head>
          </head>
          <body>
          <?php
          
          require("config.php");
          
          
          $numrows = count ($email);
          for ($count = 0; $count < $numrows; ++$count) {
          	echo "$email[$count]";
          }
          
          
          echo "<br>end!";
          
          
          ?>
          </body>
          </html>
          and i can do it

          yipee.....

          Christopher Padfield
          Web Based Helpdesk
          DeskPRO v3.0.3 Released - Download Demo Now!

          Comment


          • #6
            Yes that is how I handle checkboxes in my favorites hack as you could have 0 or 50.

            You shouldn't have muliple scripts though, put them all into one and use variables on the command line to call each part i.e.

            if ($action=="" || isset($action)==0)
            { $action = "showform"; }

            if ($action == "showform")
            {

            // Use this
            <INPUT type="hidden" name="action" value="processform">

            }
            else if ($action == "processform")
            {

            // Process...

            }

            Comment


            • #7
              Rangersfan,

              thank you. I see what you are doing there, have changed it to work like that.

              I am getting there about 1/3 done i think.

              I have a question about mysql now. If i want to add stuff to mysql what do i have to do to make the id number just increase 1 or will this be done automatically. Also, once i have inserted a row of data how do i bring back that id number for that row of data back into the thread?

              This is the way vbulletin seems to do it

              Code:
              $DB_site->query("INSERT INTO thread (threadid,title,lastpost,forumid,open,replycount,postusername,lastposter,dateline,iconid,visible) VALUES (NULL,'".addslashes($subject)."',".time().",$forumid,1,0,'".addslashes($username)."','".addslashes($username)."',".time().",$iconid,$visible)");
                    $threadid=$DB_site->insert_id();
              so i am guessing you use NULL for the id and it auto incremements (as set in database design) but how do i get back that id as a variable?

              Thanks anyone who can help.
              Christopher Padfield
              Web Based Helpdesk
              DeskPRO v3.0.3 Released - Download Demo Now!

              Comment


              • #8
                If the field is set to auto-increment then it will move up 1 upon an insert. You don't have to set it to Null, you can just leave it out of the INSERT statement.

                To retrieve it you do as you have shown


                $threadid=$DB_site->insert_id();


                You must do that after your insert query and before any other query or you will lose it.

                Comment


                • #9
                  Thanks a lot RangersFan. You are a star. Thank you.
                  Christopher Padfield
                  Web Based Helpdesk
                  DeskPRO v3.0.3 Released - Download Demo Now!

                  Comment


                  • #10
                    one more little mini question

                    what is wrong with this:

                    Code:
                    $dbname = "referdb";
                    $table = "refer";
                    $connection = @mysql_connect("$servername", "$dbusername", "$dbpassword") or die("Couldn't connect.");
                    $result = @mysql_create_db($dbname,$connection) or die("Couldn't create database.");
                    
                    if ($result) {
                    	echo "<P>Database has been created!</P>";
                    	echo "<P></P><P> .... Attempting to create table</P>";
                    	
                    	$create_table = "CREATE TABLE $table (
                    	
                    	id 		mediumint(8) unsigned DEFAULT '0' NOT NULL auto_increment,
                    	refer_name	VARCHAR(100),
                    	refer_email	VARCHAR(100),
                    	refer_note	TEXT,
                    	name		VARCHAR(100),
                    	email		VARCHAR(100),
                    	date		DATE,
                    	clicked		CHAR(1),
                    	reminders	VARCHAR(3),
                    	last_email_date	VARCHAR(100),
                    	no_reminders	CHAR(1),
                    	redirect_url	VARCHAR(100),
                    	homepage	CHAR(1),
                    	PRIMARY KEY (id),
                    	UNIQUE id (id)
                    )";
                    
                    $result2 = mysql_query($create_table,$connection) or die("Couldn't execute query.");
                    It creates the database fine but for some reason creating the table never works.

                    I know it is a different way to vbulletin does this but this is the method my book is doing (and that has explanations why in it!) just can't get it to work though.

                    [Edited by chrispadfield on 10-26-2000 at 07:42 PM]
                    Christopher Padfield
                    Web Based Helpdesk
                    DeskPRO v3.0.3 Released - Download Demo Now!

                    Comment


                    • #11
                      This syntax using or in an assignment is not something I am aware of it. Does PHP support this type of behaviour?

                      $connection = @mysql_connect("$servername", "$dbusername", "$dbpassword") or die("Couldn't connect.");

                      Comment


                      • #12
                        no idea but i guess it must because it successfully creates the database.

                        I guess i am going to have to do it a different way.
                        Christopher Padfield
                        Web Based Helpdesk
                        DeskPRO v3.0.3 Released - Download Demo Now!

                        Comment


                        • #13
                          well i got it working. Done it slightly different way (using sitepoint tutorial) but i think it was because the database never got selected, i thought that after creating it that it would then be selected but it seems this is not the case. Think that is why it would not work.

                          I now got the script creating database, table and got it putting data into it as well. Getting there
                          Christopher Padfield
                          Web Based Helpdesk
                          DeskPRO v3.0.3 Released - Download Demo Now!

                          Comment

                          widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                          Working...
                          X