Jump to content

Recommended Posts

dude it is js

<script scr="mootools.js"></script>

this means you include the mootools javascript into your page. its some extra javascript library to make javascript coding a lot easier.

 

and no you dont install a thing since you dont have to install a thing to run javascript

got it, works great thanks Dj Kat.

 

I've put this code into the form.php

 

<?php
$con = mysql_connect("xxx","xx","xx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db(xxx", $con);

$sql="INSERT INTO guests (guest_name, guest_email)
VALUES
('$_POST[username]','$_POST[email]')";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "record added";

mysql_close($con)
?>

 

but it doesn't quite work, all it does is enter the words Array into the database and in only 1 row despite how many people i enter data for.

 

any idea?

hmmm the modify button dissapeared oh well

anyway try this havent tested it

<?php
$con = mysql_connect("xxx","xx","xx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("xxx", $con);
$sql="INSERT INTO guests (guest_name, guest_email) VALUES";
for($i=0;$i<sizeof($_POST['username']);$i++){

$sql.="('".mysql_real_escape_string($_POST['username'][$i])."','".mysql_real_escape_string($_POST['email'][$i])."')";
if(!$i==sizeof($_POST['username'])){
	$sql.=",";
}
}
//
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "record added";
?>

thanks again,

 

using that revised code returns this error

 

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('3','3')('4','4')' at line 1

 

not sure where to look for this error.

 

any ideas?

Why not use php to create an input box that asks the user for the number of peoples emails they will need to add then have that value be inserted into a variable such as $number_of_input_boxes, then simply hit enter and all the boxes will appear..............

Here is the first page:

I just named it upload_number.php

 

-------------------------------------------------------------------------------------------------<?

<?php
//YOU NEED TO HAVE THIS ON ALL OF YOUR PAGES THAT YOU WANT TO RETAIN THE VALUES IN THE SESSIONS.
session_start(); 

//This will turn ALL of our post variables into session variables
foreach($_POST as $key => $val)
{
$_SESSION[$key] = $val;
}
?>

<form enctype="multipart/form-data" method="post" action="upload.php">
<label>Number of Email Adresses to Add</label>
<input name="email_number" id="email_number" value="<?php echo $_SESSION['email_number']; ?>"  size= "20" />

<input type="submit" name="Submit" class="submit-form" value="Submit">
  </p></form></h4>

 

-------------------------------------------------------------------------------------------------

Here is the second page.... I just named it upload.php

-------------------------------------------------------------------------------------------------

 

 

<?php 
//YOU NEED TO HAVE THIS ON ALL OF YOUR PAGES THAT YOU WANT TO RETAIN THE VALUES IN THE SESSIONS.
session_start(); 

//This will turn ALL of our post variables into session variables
foreach($_POST as $key => $val)
{
$_SESSION[$key] = $val;
}
?>

  <form enctype="multipart/form-data" method="post" action="upload_emails.php">
  <label>First Name</label>
<input name="first_name" id="first_name" value="<?php echo $_POST['first_name']; ?>"  size= "20" />
<br />
<?php
  // start of emails
  $number_emails = $_SESSION['email_number'];
  for($x=0;$x<$number_emails;$x++){
  ?>
    <field>Email Address</field><input class="none" name="file_email<? echo $x;?>" type="text" id="file_email<? echo $x;?>">
    <br />
  
  <?php
  // end of for loop
  }
  ?>
  <p><input name="number_emails" type="hidden" value="<? echo $number_emails;?>">
    <input type="submit" name="Submit" class="submit-form" value="Submit">
  </p></form></h4>

 

-------------------------------------------------------------------------------------------------

For the final page

I named it upload emails.......

-------------------------------------------------------------------------------------------------

<?php
echo 'Do what you want here!!!';
?>

 

 

Sorry its a little sloppy, I just threw it together real quick....hopefully you get the point

cheers works perfectly.

 

still having problems with this sql statement

 

$sql.="INSERT INTO guests (guest_name, guest_email) VALUES";

for($i=0;$i<sizeof($_POST['username']);$i++){

 

$sql.="('".mysql_real_escape_string($_POST['username'][$i])."','".mysql_real_escape_string($_POST['email'][$i])."')";

if(!$i==sizeof($_POST['username'])){

$sql.=",";

}

}

//

if (!mysql_query($sql,$con))

{

die('Error: ' . mysql_error());

}

echo "record added";

?>

 

 

hi again,

 

I've worked out that this script work when using only 2 rows of fields, if I add anymore it fails.

 

So I'm assuming that it's somthing to do with the loop, which, I think, is this line

 

for($i=0;$i<sizeof($_POST['username']);$i++){

 

does this line look correct?

nah dont worry bout the code tags thing  just use it for future usage

did you do the echo the sql after the loop or before if its after then youre right it means the loop is correct otherwise place the echo($sql) after the loop to see what it does

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.