...

View Full Version : Submit button outside php script not working



cyborg911
05-09-2011, 07:29 AM
This is a script that dynamically generates radio buttons using ajax. while its working fine, at the end where i put the submit button its not working!!
the button is supposed to lead to a page called "hello.php".






<?php
$q=$_GET["q"];

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

mysql_select_db("my_db", $con);

$sql="SELECT * FROM timing WHERE name = '".$q."'";

$result = mysql_query($sql);


$name=array("Titanic" => "A Romantic Love Story",
"Lord of the Rings" => "Action Adventure",
"Schindlers List" => "A man saves many",
"300" => "300 against a million!");

foreach($name as $keyname => $value)
{
if($q==$keyname)
{
echo $value;
}

}
/**if ($q== "Titanic")
{
echo $name['Titanic'];
}
else if ($q== "Lord of the Rings")
{
echo $name["LOTR"];
}
else if ($q=="Schindlers List")
{
echo $name["SL"];
}
else if ($q=="300")
{
echo $name["300"];
}
**/


echo "<table border='1'>
<tr>
<th>Movie Name</th>
<th>Morning</th>
<th>Afternoon</th>
<th>Evening</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['time']. "</td>";
echo "<td>" . $row['time1']. "</td>";
echo "<td>" . $row['time2']. "</td>";
echo "</tr>";
echo "<tr>";
echo "<td> Select Option </td>";

if($row['time']!='')
{
echo "<td>";
echo "<input type = 'radio' Name = 'r1' value='r1' id='rad1' onclick='zing()'>";
echo "</td>";
}
else
{
echo "<td>";
echo "";
echo "</td>";
}
if($row['time1']!='')
{
echo "<td>";
echo "<input type = 'radio' Name = 'r1' value='r2' id='rad2' >";
echo "</td>";

}
else
{
echo "<td>";
echo "";
echo "</td>";
}
if($row['time2']!='')
{
echo "<td>";
echo "<input type = 'radio' Name = 'r1' value='r3' id='rad3' >";
echo "</td>";
}
else
{
echo "<td>";
echo "";
echo "</td>";
}
}

mysql_close($con);
?>

<input type="submit" value="Submit" onclick="hello.php"/>; //** NOT WORKING SUBMIT BUTTON

tomharto
05-09-2011, 07:34 AM
Should it not be this?


echo "<input type=\"submit\" value=\"Submit\" onclick=\"hello.php\"/>";

I dont know AJAX but dont you also need to open a form first and end it after the submit button?

<form action="hello.php" method="POST">All your inputs<input type="submit" value="Submit" /></form>

cyprusholidays
05-09-2011, 01:48 PM
No <form> tag in your code Cyborg. Add <form> in the beginning and close them at the end of code.

<form name=xxxx action="hello.php" method="post">
<your form fields here...
</form>

tangoforce
05-09-2011, 02:05 PM
Should it not be this?


echo "<input type=\"submit\" value=\"Submit\" onclick=\"hello.php\"/>";

No. He's already closed the php.



I dont know AJAX but dont you also need to open a form first and end it after the submit button?

No. For ajax he needs to specify a function in his onclick="" instead of hello.php. AJAX is basically a javascript object making an invisible http request.


No <form> tag in your code Cyborg. Add <form> in the beginning and close them at the end of code.

<form name=xxxx action="hello.php" method="post">
<your form fields here...
</form>

Ditto. Form submit buttons don't work unless the form is declared and its submit path specified.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum