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')"); ?> 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 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 :'( 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"); ?> 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
Archived
This topic is now archived and is closed to further replies.