I have this code: if($_GET['action'] == "edit") { $id = $_GET["id"]; $ntitle = $_POST['title']; $nurl = $_POST['url']; $ncategory = $_POST['category']; $nimage = $_POST['image']; $nvalidate = $_POST['validate']; $ndescription = $_POST['description']; $ncount = $_POST['count']; $sql = mysql_query("UPDATE tutorials SET id='NULL', title='$ntitle', url='$nurl', category='$ncategory', validate='$nvalidate', image='$nimage', count='$ncount', description='$ndescription' WHERE id='$id'") or die (mysql_error()); echo "Tutorial Edited, Redirecting..."; echo "<meta http-equiv=Refresh content=3;url=?x=check>"; exit(); } else { ?> <form name="message" method='post' action='?x=edittutorial&action=edit'> <b>ID:</b> <? echo''.$id.''; ?><br><BR> <b>Title:</b><BR> <input name='title' value='<? echo''.$title.''; ?>' size='36' maxlength='255'><br><BR> <b>URL:<br></b> <input name='url' value='<? echo''.$url.''; ?>' size='36' maxlength='255'><br><BR> <b>Category:</b><Br> <select size="1" name='category' size='36' maxlength='255'> <? echo''.$cat.''; ?> </select> <br><br> <b>Hits:<br></b> <input name='count' value='<? echo''.$count.''; ?>' size='36' maxlength='255'><br><BR> <b>Image:<br></b> <input name='image' size='36' maxlength='255' value='<? echo''.$image.''; ?>'><br><br> <b>Description:</b><br> <input name='description' size='36' maxlength='255' value='<? echo''.$description.''; ?>'><br><br> <b>Validate:</b> 0 - Not Validated; 1 - Validated<br> <select size='1' name='validate' size='36' maxlength='255'> <option>1</option> <option>0</option> </select><br><br> <input type="submit" name="submit" value="Edit Tutorial"> <input type="reset" name="Reset" value="Reset"></form> <?php } } ?> PHP: But it isnt updating the row when i click on submit. Whats wrong with it?
You need to connect to the mysql database before doing any queries using: mysql_connect('localhost',"your username","your password"); mysql_select_db('your database'); Look here for more info: http://www.tizag.com/mysqlTutorial/mysqlconnection.php
Does it get as far as saying "Tutorial Edited, Redirecting..."? If so, try doing a SELECT using the ID you're passing in to see if any records match. What type is the id column? If it's an integer, take off the '' around $id in the SQL query.
The first part of it is: <? include('admin_header.php'); ?> <b>Edit a Tutorial</b><br> <hr noshade size="1"> <?php include '../database.php'; $sql_query_cat = "SELECT * FROM tutorials WHERE id='$id' ORDER BY category ASC"; //store the SQL query in the result variable $result_cat = mysql_query($sql_query_cat); if(mysql_num_rows($result_cat)) { //output as long as there are still available fields while($row = mysql_fetch_array($result_cat)) { $category = stripslashes($row["category"]); $cat.='<OPTION VALUE="___" selected>'.$category.'</OPTION>'; $categ = $row[category]; $categ = stripslashes($categ); $cat.='<option>'.$categ.'</option>'; $title = $row["title"]; $url = $row["url"]; $id = $row["id"]; $image = $row["image"]; $description = $row["description"]; $count = $row["count"]; } PHP:
No i dont get up to Tutorial Edited, and yes the ID is an integer. (also tried taking off the ", didnt do anything)
In which case, it's a problem with if($_GET['action'] == "edit") and action='?x=edittutorial&action=edit'> I've nveer tried passing parameters into action, but I'd always try to avoid mixing GETs and POSTs. Try sticking this in instead of action='?x=edittutorial&action=edit'> <input type="hidden" name="x" value="edittutorial" /> <input type="hidden" name="action" value="edit" /> then change $_GETs to $_POST Let me know if that helps.
Change if(mysql_num_rows($result_cat)) to if(mysql_num_rows($result_cat) != 0) You shouldn't have to, but that has fixed things like that before in my code.
if you put : echo "<pre>"; print_r($_GET); print_r($_POST); //before if($_GET['action'] == "edit") PHP: what do you get?
I get a bunch of array stuff... I have <? include('admin_header.php'); ?> <b>Edit a Tutorial</b><br> <hr noshade size="1"> <?php include '../database.php'; $sql_query_cat = "SELECT * FROM tutorials WHERE id='$id' ORDER BY category ASC"; //store the SQL query in the result variable $result_cat = mysql_query($sql_query_cat); if(mysql_num_rows($result_cat)) { //output as long as there are still available fields while($row = mysql_fetch_array($result_cat)) { $category = stripslashes($row["category"]); $cat.='<OPTION VALUE="___" selected>'.$category.'</OPTION>'; $categ = $row[category]; $categ = stripslashes($categ); $cat.='<option>'.$categ.'</option>'; $title = $row["title"]; $url = $row["url"]; $id = $row["id"]; $image = $row["image"]; $description = $row["description"]; $count = $row["count"]; } if($_POST['action'] == "edit") { $id = $_POST['id']; $ntitle = $_POST['title']; $nurl = $_POST['url']; $ncategory = $_POST['category']; $nimage = $_POST['image']; $nvalidate = $_POST['validate']; $ndescription = $_POST['description']; $ncount = $_POST['count']; $sql = mysql_query("UPDATE tutorials SET id='$id',title='$ntitle',url='$nurl',category='$ncategory',validate='$nvalidate',image='$nimage',count='$ncount',description='$ndescription' WHERE id='$id'") or die (mysql_error()); echo "Tutorial Edited, Redirecting..."; echo "<meta http-equiv=Refresh content=3;url=?x=check>"; exit(); } else { ?> <form name="message" method='post'> <input type="hidden" name="x" value="edittutorial" /> <input type="hidden" name="action" value="edit" /> <b>ID:</b> <? echo''.$id.''; ?><br><BR> <b>Title:</b><BR> <input name='title' value='<? echo''.$title.''; ?>' size='36' maxlength='255'><br><BR> <b>URL:<br></b> <input name='url' value='<? echo''.$url.''; ?>' size='36' maxlength='255'><br><BR> <b>Category:</b><Br> <select size="1" name='category' size='36' maxlength='255'> <? echo''.$cat.''; ?> </select> <br><br> <b>Hits:<br></b> <input name='count' value='<? echo''.$count.''; ?>' size='36' maxlength='255'><br><BR> <b>Image:<br></b> <input name='image' size='36' maxlength='255' value='<? echo''.$image.''; ?>'><br><br> <b>Description:</b><br> <input name='description' size='36' maxlength='255' value='<? echo''.$description.''; ?>'><br><br> <b>Validate:</b> 0 - Not Validated; 1 - Validated<br> <select size='1' name='validate' size='36' maxlength='255'> <option>1</option> <option>0</option> </select><br><br> <input type="submit" name="submit" value="Edit Tutorial"> <input type="reset" name="Reset" value="Reset"></form> <?php } } ?> </div></div> <? include('admin_footer.php'); ?> PHP: and now it will show the Tutorial Edited, Redirecting... but it doesnt update the mysql row. Edit nvm, i removed: <input type='hidden' name='id' value='<? echo''.$id.''; ?>' /> PHP: When i was working on the things you suggestion, and forgot to put it back in