Jump to content

[SOLVED] 3 forms 1 submit


kev wood

Recommended Posts

i have this page which contains three different forms

 

<form name="dropdown_list" action="insert.php" method="POST">
<select name="dropdown">
<option value="constructiondb">Construction</option>
<option value="electricaldb">Electrical</option>
<option value="technicaldb">Technical</option>
</select>
</form>
<br />
<form name="radio_btn" action="insert.php" method="POST">
<select name="radio">
<option value="internal">Internal News</option>
<option value="general">General News</option>
</select>
</form>
<br />
<form name="form" action="insert.php" method="POST">
Date: <input type="text" name="date" /><br /><br>
Title:  <input type="text" name="title" /><br /><br />
Article:<br /><textarea cols="50" rows="10" name="article" onkeyup="textLimit(this, 500);"></textarea><br />
</form>

 

the first form is used to select the db the user wants access to and the second form is used to select which table the user will be adding the data taken from the third form into.  i have tried to use javascript to submit the forms but when i go to the next page some of the variables are not being sent through.

 

here is the page which is retrieving the data

 

<?php

if (isset($_POST['dropdown_list'])) {
    $db = $_POST['dropdown_list'];
}
if (isset($_POST['radio_btn'])) {
    $table = $_POST['radio_btn'];
}
$a = substr(mysql_escape_string($_POST['date']),0,25);
$b = substr(mysql_escape_string($_POST['title']),0,25);
$c = substr(mysql_escape_string($_POST['article']),0,500);

$con = mysql_connect("localhost","xxxxxx","xxxxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("$db", $con);



$sql= "INSERT INTO $table (date, title, article) VALUES ('$a', '$b', '$c')";

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

mysql_close($con)
?>

 

when i go to this page i am not getting any connection errors and the variables $a, $b and $c all have the data which they supposed to hold.

 

the error that i am getting is as follows

 

Error: You have an error in your SQL syntax near '(date, title, article) VALUES ('21/10/2008', 'The first Article', '\r\n\r\nI set' at line 1

 

 

to me this looks like the only data not being set through is the data sent from the second form.  i cannot work this out any help would be great.

Link to comment
https://forums.phpfreaks.com/topic/129403-solved-3-forms-1-submit/
Share on other sites

<form action="insert.php" method="POST">
<select name="dropdown">
<option value="constructiondb">Construction</option>
<option value="electricaldb">Electrical</option>
<option value="technicaldb">Technical</option>
</select>
<br />
<select name="radio">
<option value="internal">Internal News</option>
<option value="general">General News</option>
</select>
<br />
   Date: <input type="text" name="date" /><br /><br>
   Title:  <input type="text" name="title" /><br /><br />
   Article:<br /><textarea cols="50" rows="10" name="article" onkeyup="textLimit(this, 500);"></textarea><br />
</form>

 

<?php

if (!isset($_POST['dropdown_list'])) {
  die("No DB selected");
}
$db = $_POST['dropdown_list'];
if (!isset($_POST['radio_btn'])) {
  die("No Table selected");
}
$table = $_POST['radio_btn'];
$a = substr(mysql_real_escape_string($_POST['date']),0,25);
$b = substr(mysql_real_escape_string($_POST['title']),0,25);
$c = substr(mysql_real_escape_string($_POST['article']),0,500);

$con = mysql_connect("localhost","xxxxxx","xxxxxxx");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db($db, $con);

$sql= "INSERT INTO $table (date, title, article) VALUES ('$a', '$b', '$c')";

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

mysql_close($con)
?>

did you make sure and put it INSIDE the FORM tags?

 

<form action="insert.php" method="POST">
<select name="dropdown">
<option value="constructiondb">Construction</option>
<option value="electricaldb">Electrical</option>
<option value="technicaldb">Technical</option>
</select>
<br />
<select name="radio">
<option value="internal">Internal News</option>
<option value="general">General News</option>
</select>
<br />
   Date: <input type="text" name="date" /><br /><br>
   Title:  <input type="text" name="title" /><br /><br />
   Article:<br /><textarea cols="50" rows="10" name="article" onkeyup="textLimit(this, 500);"></textarea><br />
<input type="submit" value="Submit" />
</form>

ignore the last post submit button in the wrong place.  i think i have been looking at code too long for today simple things are passing me by.

 

i have got the form submitting now just getting errors about the passwords.  i have had enough for one day my eyes are sore now.  i will come back tomorrow it is time for me to go home now.  thanks for your help anyway i can sort the rest i think.

Archived

This topic is now archived and is closed to further replies.

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