funkkube
asked on
PHP - BUTTON HTML question
I need to run the following
when a button is pressed on a page in Wordpress..
I have a bunch of if else statments that check for errors from the previous page and after that there are two buttons..
One to go back and correct the mistakes and then I want another button to appear if there are not any mistakes to correct and then run the above query then goto to the original page..
i have this
but it is not working exactly..
I know im eing dumb on this but can anyone help?
Thanks
Mat
<?php
$query = "insert into wp_posts (post_content,post_title) values ('{$final}','{$_POST["title"]}')";
mysql_query($query);
?>
when a button is pressed on a page in Wordpress..
I have a bunch of if else statments that check for errors from the previous page and after that there are two buttons..
One to go back and correct the mistakes and then I want another button to appear if there are not any mistakes to correct and then run the above query then goto to the original page..
i have this
<form> <input onclick="history.go(-1)" type="button" value="Go Back And Correct Entries" /> </form> <form> <input onclick="parent.location='http://www.rodbournehistory.org/?page_id=3279'" type="button" value="ADD ANOTHER RECORD" />
<?php
$query = "insert into wp_posts (post_content,post_title) values ('{$final}','{$_POST["title"]}')";
mysql_query($query);
?>
</form>
but it is not working exactly..
I know im eing dumb on this but can anyone help?
Thanks
Mat
ASKER
Sorry
I need it to only run the insert query when the ADD ANOTHER RECORD button is pressed..
I need it to only run the insert query when the ADD ANOTHER RECORD button is pressed..
any chance you could show us the values of the "$fianl" attributes? and also the names of the table headings in your database. thanks
Try this:
$query = "insert into wp_posts (post_content,post_title) values ('".$final."','".$_POST["t itle"]."') ";
Hope this helps
Addy
$query = "insert into wp_posts (post_content,post_title) values ('".$final."','".$_POST["t
Hope this helps
Addy
ASKER
the query is fine and it works I just need to run it when the button is pressed for ADD ANOTHER RECORD...
this may be my eyes but your form has no action?
try somethingl ike this.. this is all PHP dont know if its the same as ur code or not.
PART1 the button....
-------------------------- -
<form name="f" action="insert.php" method="POST" >
<tr><td colspan="2" bgcolor="#000000"><font size="+1" color="#FFFFFF"><b>Add Another Record</b></font></td></tr >
PART 2 Attached!! the inset to database,.
Please copy here any error codes you get thanks
try somethingl ike this.. this is all PHP dont know if its the same as ur code or not.
PART1 the button....
--------------------------
<form name="f" action="insert.php" method="POST" >
<tr><td colspan="2" bgcolor="#000000"><font size="+1" color="#FFFFFF"><b>Add Another Record</b></font></td></tr
PART 2 Attached!! the inset to database,.
Please copy here any error codes you get thanks
<?php
//Connect to database//
$con= mysql_connect("host name","username","password");
if(!$con)
{die('couldnt not connect: '.mysql_error());
}
mysql_select_db("database name", $con);
$query = "insert into wp_posts (post_content,post_title) values ('{$final}','{$_POST["title"]}')";
mysql_query($query);
if (!mysql_query($query,$con))
{die('Error:' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
sorry im talking complete balls talk.. the Form part was as follows...
<form method="post" action="insert.php" name="f">
<input type="Submit" name="submit" value="Add another">
<tr><td colspan="2" bgcolor="#000000"><font size="+1" color="#FFFFFF"><b>Add Another </b></font></td></tr>
<form method="post" action="insert.php" name="f">
<input type="Submit" name="submit" value="Add another">
<tr><td colspan="2" bgcolor="#000000"><font size="+1" color="#FFFFFF"><b>Add Another </b></font></td></tr>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
solved
Please tell us a little more, thanks.