craigeves Posted July 29, 2008 Share Posted July 29, 2008 in my PHP mySQL database i have a row called 'enablecontent'. I want to be able to change a drop down box on my HTML page from 'yes' to 'no' and back again. My code looks like this so far: <select name=enablecontent><option value=1 <? if($row['enablecontent']==1) echo "selected";?>>Yes</option> <option value=0 selected <? if($row['enablecontent']==0);?>>No</option> </select> But it does not update the mySQL for some reason. Am I doing anything wrong. The rest of the content on the page connects to the database and updates the content. Any help much appreciated. Thanks Craig Quote Link to comment Share on other sites More sharing options...
Xurion Posted July 29, 2008 Share Posted July 29, 2008 The problem is in the script which your form submits too. Post that code. Quote Link to comment Share on other sites More sharing options...
craigeves Posted July 30, 2008 Author Share Posted July 30, 2008 Here is my code. Thanks <?php session_start(); extract($_REQUEST, EXTR_OVERWRITE); include ("func.php"); $uname= $_SESSION['uname']; $upass= $_SESSION['upass']; if(!auth_adm($uname, $upass)>0) header('Location:logadm.php?err=1'); $sql="select photo_path,width from rsvp_set"; $rez=mysql_query($sql,$dblnk); $row=mysql_fetch_array($rez); $folder=$row['photo_path']; $adminid=auth_adm($uname, $upass); for ($num=1;$num<=1;$num++){ @move_uploaded_file($_FILES['photo'.$num]['tmp_name'], "./".$folder."/photo1.jpg"); //$photo1= $_FILES['photo'.$num]['name']; $photo1="photo.jpg"; $image_path="./".$folder."/photo1.jpg"; $thumb_path="./".$folder."/photo.jpg"; $thumb_width=$row['width']; $thumb_height=0; createthumbnailjpg($image_path,$thumb_path,$thumb_width,$thumb_height); } $content=mysql_escape_string(stripslashes($content)); $date=$year."-".$month."-".$day; $sql="update rsvp_set set regintro='$regintro', email_address='$email_address', content='$content', content2='$content2', content3heading='$content3heading', enablecontent='$enablecontent', content3='$content3', heading='$heading',wedding_date='$date',photo='$photo1'"; $rez=mysql_query($sql,$dblnk); header('location: edit_content.php'); ?> Quote Link to comment Share on other sites More sharing options...
Xurion Posted July 31, 2008 Share Posted July 31, 2008 In your update SQL you reference the $enablecontent variable. But this isn't set. Quote Link to comment Share on other sites More sharing options...
craigeves Posted July 31, 2008 Author Share Posted July 31, 2008 In your update SQL you reference the $enablecontent variable. But this isn't set. How would i set it? Sorry, im new to PHP and adapting a code that someone wrote for me. Thanks Quote Link to comment Share on other sites More sharing options...
Xurion Posted July 31, 2008 Share Posted July 31, 2008 Set the variable to the value of the drop down: <?php session_start(); extract($_REQUEST, EXTR_OVERWRITE); include ("func.php"); $uname= $_SESSION['uname']; $upass= $_SESSION['upass']; $enablecontent = $_POST['enablecontent']; //new line added here if(!auth_adm($uname, $upass)>0) header('Location:logadm.php?err=1'); $sql="select photo_path,width from rsvp_set"; $rez=mysql_query($sql,$dblnk); $row=mysql_fetch_array($rez); $folder=$row['photo_path']; $adminid=auth_adm($uname, $upass); for ($num=1;$num<=1;$num++){ @move_uploaded_file($_FILES['photo'.$num]['tmp_name'], "./".$folder."/photo1.jpg"); //$photo1= $_FILES['photo'.$num]['name']; $photo1="photo.jpg"; $image_path="./".$folder."/photo1.jpg"; $thumb_path="./".$folder."/photo.jpg"; $thumb_width=$row['width']; $thumb_height=0; createthumbnailjpg($image_path,$thumb_path,$thumb_width,$thumb_height); } $content=mysql_escape_string(stripslashes($content)); $date=$year."-".$month."-".$day; $sql="update rsvp_set set regintro='$regintro', email_address='$email_address', content='$content', content2='$content2', content3heading='$content3heading', enablecontent='$enablecontent', content3='$content3', heading='$heading',wedding_date='$date',photo='$photo1'"; $rez=mysql_query($sql,$dblnk); header('location: edit_content.php'); ?> Quote Link to comment Share on other sites More sharing options...
craigeves Posted July 31, 2008 Author Share Posted July 31, 2008 it didn't work for some reason.... ?? Set the variable to the value of the drop down: <?php session_start(); extract($_REQUEST, EXTR_OVERWRITE); include ("func.php"); $uname= $_SESSION['uname']; $upass= $_SESSION['upass']; $enablecontent = $_POST['enablecontent']; //new line added here if(!auth_adm($uname, $upass)>0) header('Location:logadm.php?err=1'); $sql="select photo_path,width from rsvp_set"; $rez=mysql_query($sql,$dblnk); $row=mysql_fetch_array($rez); $folder=$row['photo_path']; $adminid=auth_adm($uname, $upass); for ($num=1;$num<=1;$num++){ @move_uploaded_file($_FILES['photo'.$num]['tmp_name'], "./".$folder."/photo1.jpg"); //$photo1= $_FILES['photo'.$num]['name']; $photo1="photo.jpg"; $image_path="./".$folder."/photo1.jpg"; $thumb_path="./".$folder."/photo.jpg"; $thumb_width=$row['width']; $thumb_height=0; createthumbnailjpg($image_path,$thumb_path,$thumb_width,$thumb_height); } $content=mysql_escape_string(stripslashes($content)); $date=$year."-".$month."-".$day; $sql="update rsvp_set set regintro='$regintro', email_address='$email_address', content='$content', content2='$content2', content3heading='$content3heading', enablecontent='$enablecontent', content3='$content3', heading='$heading',wedding_date='$date',photo='$photo1'"; $rez=mysql_query($sql,$dblnk); header('location: edit_content.php'); ?> Quote Link to comment Share on other sites More sharing options...
fenway Posted July 31, 2008 Share Posted July 31, 2008 Please don't post your entire code. Echo $sql for us. And all mysql_error() to check for anything wrong. Then add a WHERE clause, because otherwise you're updating every record in your table. Quote Link to comment 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.