perezf Posted May 19, 2007 Share Posted May 19, 2007 I need help on updating two fields from a MySQL database through the use of a form I need it to update the heading field, and information field but all it does is add a new field Can someone please help me This is for the form <form id="form1" name="form1" method="post" action="pageupdate.php"> <label> <input type="radio" name="radio" id="mainpage" value="mainpage" /> Main Page </label> <label> <input type="radio" name="radio" id="ourmission" value="ourmission" /> Our Mission Page <input type="radio" name="radio" id="contactus" value="contactus" /> Contact Us Page</label> <p>Heading:<br /> <input name="heading" type="text" id="heading" size="50" /> </p> <p>Information: <br /> <textarea name="information" cols="60" rows="20" id="information"></textarea> </p> <p> <input type="submit" name="Submit" value="Edit Page" /> </p> </form> This is for the php update <?php $heading = $_POST['heading']; $information = $_POST['information']; $radio = $_POST['radio']; include('dbconnect.php'); mysql_query("INSERT INTO $radio (heading,information) VALUES ('$heading','$information')"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52154-php-mysql-update-2-fields/ Share on other sites More sharing options...
AndyB Posted May 19, 2007 Share Posted May 19, 2007 the INSERT query adds a record. What you need is an UPDATE ... SET ... WHERE something = something_else type of query Quote Link to comment https://forums.phpfreaks.com/topic/52154-php-mysql-update-2-fields/#findComment-257238 Share on other sites More sharing options...
perezf Posted May 19, 2007 Author Share Posted May 19, 2007 can you please show me how that would work in this case because im rather new to this, im trying to do it but it doesnt seem to update correctly :'( Quote Link to comment https://forums.phpfreaks.com/topic/52154-php-mysql-update-2-fields/#findComment-257240 Share on other sites More sharing options...
perezf Posted May 19, 2007 Author Share Posted May 19, 2007 I figured it out Thanks guys <?php $heading = $_POST['heading']; $information = $_POST['information']; $radio = $_POST['radio']; include('dbconnect.php'); mysql_query("UPDATE $radio SET heading = '$heading' WHERE heading = heading"); mysql_query("UPDATE $radio SET information = '$information' WHERE information = information"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52154-php-mysql-update-2-fields/#findComment-257243 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.