careym1989 Posted September 13, 2008 Share Posted September 13, 2008 When I click submit, it doesn't come up with any errors and redirects to the header page but doesn't update the record. Any help would be MUCH appreciated. <? // START PHP CODES. THIS PART MUST ON THE TOP OF THIS PAGE. // Connect database. include("connectdb.php"); // ***** This part will process when you Click on "Submit" button ***** // Check, if you clicked "Submit" button if($_POST['Submit']){ // Get parameters from form. $id=$_POST['id']; $n=$_POST['n']; $cc=$_POST['cc']; $st=$_POST['st']; $ea=$_POST['ea']; $cd=$_POST['cd']; $url=$_POST['url']; $approved=$_POST['approved']; // Do update statement. mysql_query("update candidatesubmit set n='$n', cc='$cc', st='$st', ea='$ea', cd='$cd', url='$url', approved='$approved' where id='$id'"); // Re-direct this page to select.php. header("location:ff_View.php"); exit; } // ************* End update part ************* // *** Select data to show on text fields in form. *** // Get id parameter (GET method) from select.php $id=$_GET['id']; // Get records in all columns from table where column id equal in $id and put it in $result. $result=mysql_query("select * from candidatesubmit where id='$id'"); // Split records in $result by table rows and put them in $row. $row=mysql_fetch_assoc($result); // Close database connection. mysql_close(); ?> <!-- END OF PHP CODES AND START HTML TAGS --> <html> <body> <!-- set this form to POST method and target this form to itself ($PHP_SELF;)--> <form method="post" action="<? echo $PHP_SELF; ?>"> <p>Name : <!-- name of this text field is "name" --> <input name="n" type="text" id="n" value="<? echo $row['n']; ?>"/> <br /> <p>City County Come From : <!-- name of this text field is "name" --> <input name="cc" type="text" id="cc" value="<? echo $row['cc']; ?>"/> <br /> <p>State : <!-- name of this text field is "name" --> <input name="st" type="text" id="st" value="<? echo $row['st']; ?>"/> <br /> <p>Email : <!-- name of this text field is "email" --> <input name="ea" type="text" id="ea" value="<? echo $row['ea']; ?>"/> <br /> <p>Office Held / Currently Running For : <!-- name of this text field is "tel" --> <input name="cd" type="text" id="cd" value="<? echo $row['cd']; ?>"/> <br /> <p>URL : <!-- name of this text field is "email" --> <input name="url" type="text" id="url" value="<? echo $row['url']; ?>"/> <br /> <p>Approved : <!-- name of this text field is "email" --> <input name="approved" type="text" id="approved" value="<? echo $row['approved']; ?>"/> <br /> </p> <p> <input type="submit" name="Submit" value="Submit" /> </p> </form> </body> </html> Regards, C Quote Link to comment Share on other sites More sharing options...
chronister Posted September 13, 2008 Share Posted September 13, 2008 <?php // Do update statement. $updateResult = mysql_query("update candidatesubmit set n='$n', cc='$cc', st='$st', ea='$ea', cd='$cd', url='$url', approved='$approved' where id='$id'"); if(mysql_affected_rows($updateResult) > 0) { // Re-direct this page to select.php. header("location:ff_View.php"); exit; } else { echo mysql_error(); } ?> I would start with this. This will keep the header from kicking in and redirecting, unless the query actually modifies a row, and if there is an error in the query it will show you that too. I would not keep the mysql_error() part in there for a live script. Nate Quote Link to comment Share on other sites More sharing options...
careym1989 Posted September 13, 2008 Author Share Posted September 13, 2008 Hello Nate! Thanks for the advice. Everything's fine except this shows up after hitting the "Update" button. Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/content/s/r/a/srasoul/html/content_Management/ff_VetProcess.php on line 24 Quote Link to comment Share on other sites More sharing options...
careym1989 Posted September 13, 2008 Author Share Posted September 13, 2008 FYI -- here's the code that I have: <? // START PHP CODES. THIS PART MUST ON THE TOP OF THIS PAGE. // Connect database. include("connectdb.php"); // ***** This part will process when you Click on "Submit" button ***** // Check, if you clicked "Submit" button if($_POST['Submit']){ // Get parameters from form. $id=$_POST['id']; $n=$_POST['n']; $cc=$_POST['cc']; $st=$_POST['st']; $ea=$_POST['ea']; $cd=$_POST['cd']; $url=$_POST['url']; $approved=$_POST['approved']; // Do update statement. $updateResult = mysql_query("update candidatesubmit set n='$n', cc='$cc', st='$st', ea='$ea', cd='$cd', url='$url', approved='$approved' where id='$id'"); if(mysql_affected_rows($updateResult) > 0) { // Re-direct this page to select.php. header("location:ff_View.php"); exit; } else { echo mysql_error(); } } // *** Select data to show on text fields in form. *** // Get id parameter (GET method) from select.php $id=$_GET['id']; // Get records in all columns from table where column id equal in $id and put it in $result. $result=mysql_query("select * from candidatesubmit where id='$id'"); // Split records in $result by table rows and put them in $row. $row=mysql_fetch_assoc($result); // Close database connection. mysql_close(); ?> <!-- END OF PHP CODES AND START HTML TAGS --> <html> <body> <!-- set this form to POST method and target this form to itself ($PHP_SELF;)--> <form method="post" action="<? echo $PHP_SELF; ?>"> <p>Name : <!-- name of this text field is "name" --> <input name="n" type="text" id="n" value="<? echo $row['n']; ?>"/> <br /> <p>City County Come From : <!-- name of this text field is "name" --> <input name="cc" type="text" id="cc" value="<? echo $row['cc']; ?>"/> <br /> <p>State : <!-- name of this text field is "name" --> <input name="st" type="text" id="st" value="<? echo $row['st']; ?>"/> <br /> <p>Email : <!-- name of this text field is "email" --> <input name="ea" type="text" id="ea" value="<? echo $row['ea']; ?>"/> <br /> <p>Office Held / Currently Running For : <!-- name of this text field is "tel" --> <input name="cd" type="text" id="cd" value="<? echo $row['cd']; ?>"/> <br /> <p>URL : <!-- name of this text field is "email" --> <input name="url" type="text" id="url" value="<? echo $row['url']; ?>"/> <br /> <p>Approved : <!-- name of this text field is "email" --> <input name="approved" type="text" id="approved" value="<? echo $row['approved']; ?>"/> <br /> </p> <p> <input type="submit" name="Submit" value="Submit" /> </p> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
careym1989 Posted September 14, 2008 Author Share Posted September 14, 2008 Give this a little bump Don't mean to annoy anyone. -C Quote Link to comment Share on other sites More sharing options...
chronister Posted September 14, 2008 Share Posted September 14, 2008 Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in /home/content/s/r/a/srasoul/html/content_Management/ff_VetProcess.php on line 24 Ok, that is what you wanted to see.... sorta.... This is telling you that the link to the database failed and therefore could not run the query... So now you need to check on the connectdb.php script and take a look at it and figure out why the connection is not making it. Nate Quote Link to comment Share on other sites More sharing options...
careym1989 Posted September 14, 2008 Author Share Posted September 14, 2008 Right -- but the connection retrieved the information stored and displayed it in the Database. I don't see why it would connect for one and not work for the other. Quote Link to comment Share on other sites More sharing options...
careym1989 Posted September 14, 2008 Author Share Posted September 14, 2008 Modest bump. FYI -- I'm running php 4.x if that changes anything. Quote Link to comment Share on other sites More sharing options...
chronister Posted September 14, 2008 Share Posted September 14, 2008 Right -- but the connection retrieved the information stored and displayed it in the Database. I don't see why it would connect for one and not work for the other. That's the $64,000 question here. Why does it connect for one but not the other. Post the connectdb.php script. Star out or otherwise remove username & password & host information If we can see that we may be able to help more. Quote Link to comment Share on other sites More sharing options...
careym1989 Posted September 14, 2008 Author Share Posted September 14, 2008 Absolutely. Here's my current page: <?php include("cdb.php"); if($_POST['Submit']){ $id=$_POST['id']; $n=$_POST['n']; $cc=$_POST['cc']; $st=$_POST['st']; $ea=$_POST['ea']; $cd=$_POST['cd']; $url=$_POST['url']; $approved=$_POST['approved']; if (mysql_affected_rows($cdb) > 0) { mysql_query("UPDATE candidatesubmit SET n='$n', cc='$cc', st='$st', ea='$ea', cd='$cd', url='$url', approved='$approved' WHERE id='$id'"); header("location:ff_View.php"); exit; } else { echo mysql_error(); } } $id=$_GET['id']; $result=mysql_query("SELECT * FROM candidatesubmit WHERE id='$id'"); $row=mysql_fetch_assoc($result); mysql_close(); ?> <html> <body> <form method="post" action="<? echo $PHP_SELF; ?>"> <p>Name : <input name="n" type="text" id="n" value="<? echo $row['n']; ?>"/> <br /> <p>City County Come From : <input name="cc" type="text" id="cc" value="<? echo $row['cc']; ?>"/> <br /> <p>State : <input name="st" type="text" id="st" value="<? echo $row['st']; ?>"/> <br /> <p>Email : <input name="ea" type="text" id="ea" value="<? echo $row['ea']; ?>"/> <br /> <p>Office Held / Currently Running For : <input name="cd" type="text" id="cd" value="<? echo $row['cd']; ?>"/> <br /> <p>URL : <input name="url" type="text" id="url" value="<? echo $row['url']; ?>"/> <br /> <p>Approved : <input name="approved" type="text" id="approved" value="<? echo $row['approved']; ?>"/> <br /> </p> <p> <input type="submit" name="Submit" value="Submit" /> </p> </form> </body> </html> Here's my database connect include -- cdb.php: <? $cdb = mysql_connect("xxx", "xxx", "xxx"); mysql_select_db("xxx"); ?> Regards, Carey Quote Link to comment Share on other sites More sharing options...
chronister Posted September 15, 2008 Share Posted September 15, 2008 <?php if ($cdb) // if database connected. { // there is no affected rows here yet, as there has been no query. mysql_query("UPDATE candidatesubmit SET n='$n', cc='$cc', st='$st', ea='$ea', cd='$cd', url='$url', approved='$approved' WHERE id='$id'"); header("location:ff_View.php"); exit; } else { echo mysql_error(); } ?> Try that.... the myql_affected_rows line was not correct. That is only used on an update/delete or insert query ( I don't think that a select query changes this variable.) Let me know what you get here. Nate Quote Link to comment Share on other sites More sharing options...
careym1989 Posted September 15, 2008 Author Share Posted September 15, 2008 It loads up the form. I change approved to 0. It reloads the view candidates page (ff_View.php) and approved (anything for that matter) has not changed. Here's my code so far: <?php include("cdb.php"); if($_POST['Submit']){ $id=$_POST['id']; $n=$_POST['n']; $cc=$_POST['cc']; $st=$_POST['st']; $ea=$_POST['ea']; $cd=$_POST['cd']; $url=$_POST['url']; $approved=$_POST['approved']; if ($cdb) // if database connected. { // there is no affected rows here yet, as there has been no query. mysql_query("UPDATE candidatesubmit SET n='$n', cc='$cc', st='$st', ea='$ea', cd='$cd', url='$url', approved='$approved' WHERE id='$id'"); header("location:ff_View.php"); exit; } else { echo mysql_error(); } } $id=$_GET['id']; $result=mysql_query("SELECT * FROM candidatesubmit WHERE id='$id'"); $row=mysql_fetch_assoc($result); mysql_close(); ?> <html> <body> <form method="post" action="<? echo $PHP_SELF; ?>"> <p>Name : <input name="n" type="text" id="n" value="<?php echo $row['n']; ?>"/> <br /> <p>City County Come From : <input name="cc" type="text" id="cc" value="<?php echo $row['cc']; ?>"/> <br /> <p>State : <input name="st" type="text" id="st" value="<?php echo $row['st']; ?>"/> <br /> <p>Email : <input name="ea" type="text" id="ea" value="<?php echo $row['ea']; ?>"/> <br /> <p>Office Held / Currently Running For : <input name="cd" type="text" id="cd" value="<?php echo $row['cd']; ?>"/> <br /> <p>URL : <input name="url" type="text" id="url" value="<?php echo $row['url']; ?>"/> <br /> <p>Approved : <input name="approved" type="text" id="approved" value="<?php echo $row['approved']; ?>"/> <br /> </p> <p> <input type="submit" name="Submit" value="Submit" /> </p> </form> </body> </html> 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.