Jump to content

Update records -- redirects to header but doesn't update record


careym1989

Recommended Posts

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

Link to comment
Share on other sites

<?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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.