Jump to content

Recommended Posts

Okay, I am new to PHP and Mysql so there are a bunch of mistakes. Besides I used turingturnip scrip to generate the PHP and Mysql files and I will list where I am having problems.

 

I am running everything local using WAMPSERVER to test the script.

 

Here my problem: When running the script to add to the data base everything works fine. The data is stored in the database, but when I request to update the data it calls it the data fine and shows up on the screen properly. When I change the information and tell it to update it, it runs through the process and tells me the data was updated, but when review the data was not updated on show the original data not the updated data.

 

I have attached the script to this post.

The update does not work, yet it say is did update.

can anyone help with this?

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/247664-basic-update-new-to-php-mysql/
Share on other sites

My bad posting the script:

 

Update:

<?php
/// In order to use this script freely
/// you must leave the following copyright
/// information in this file:
/// Copyright 2006 [url=http://www.turningturnip.co.uk]www.turningturnip.co.uk[/url]
/// All rights reserved.

include("connect.php");
$id = $_GET['id'];

$qP = "SELECT * FROM test WHERE id = '$id'  ";
$rsP = mysql_query($qP);
$row = mysql_fetch_array($rsP);
extract($row);
$cityperfecture = trim($cityperfecture);
$firstname = trim($firstname);

mysql_close();
?>
<form id="FormName" action="updated.php" method="post" name="FormName">
<table width="448" border="0" cellspacing="2" cellpadding="0">
<tr><td width="150"><div align="right">
<label for="cityperfecture">cityperfecture</label></div>
</td>
<td>
<input type="cityperfecture" name="cityperfecture" type="text" size="25" value="<?php echo $cityperfecture ?>" maxlength="10"></td>
</tr>
<tr><td width="150"><div align="right">
<label for="firstname">firstname</label></div>
</td>
<td>
<input id="firstname" name="firstname" type="text" size="25" value="<?php echo $firstname ?>" maxlength="10"></td>
</tr>
<tr>
<td width="150"></td>
<td><input type="submit" name="submitButtonName" value="Update"><input type="hidden" name="id" value="<?=$id?>"></td>
</tr>
</table>
</form>

 

 

 

 

Updated:

<a href="index.php">Back to List</a><br>
<br>
<?php
/// In order to use this script freely
/// you must leave the following copyright
/// information in this file:
/// Copyright 2006 [url=http://www.turningturnip.co.uk]www.turningturnip.co.uk[/url]
/// All rights reserved.

include("connect.php");

$id = $_POST['id'];
$cityperfecture = trim($_POST['cityperfecture']);
$firstname = trim($_POST['firstname']);

$update = "UPDATE test SET
cityperfecture = '$cityperfecture',
firstname = '$firstname' WHERE id = '$id' ";
$rsUpdate = mysql_query($update);
if ($rsUpdate)
{
echo "Update successful.";
}
mysql_close();
?>

 

 

Connect:

<?php
/// For the following details,
/// please contact your server vendor

$hostname='LOCALHOST'; //// specify host, i.e. 'localhost'
$user='root'; //// specify username
$pass=''; //// specify password
$dbase='test'; //// specify database name
$connection = mysql_connect("$hostname" , "$user" , "$pass") 
or die ("Can't connect to MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");
?>

 

MOD EDIT: tags changed to


tags.

Ok try this at the top to stop error

 

 

include("connect.php");

if(isset($_GET['id'])){
$id = $_GET['id'];
}

$qP = "SELECT * FROM test WHERE id= '$id'  ";
$rsP = mysql_query($qP);
$row = mysql_fetch_array($rsP);
extract($row);
$cityperfecture = trim($cityperfecture);
$firstname = trim($firstname);

mysql_close();

Ok try this at the top to stop error

 

 

include("connect.php");

if(isset($_GET['id'])){
$id = $_GET['id'];
}

$qP = "SELECT * FROM test WHERE id= '$id'  ";
$rsP = mysql_query($qP);
$row = mysql_fetch_array($rsP);
extract($row);
$cityperfecture = trim($cityperfecture);
$firstname = trim($firstname);

mysql_close();

 

Tried it nothing happen no errors or database update...

in you update.php file look for this line:

 

<td><input type="submit" name="submitButtonName" value="Update"><input type="hidden" name="id" value="<?=$id?>"></td>

 

change the short tags for long one as in the rest of your scripts.

 

and after that... in your updated.php echo $update before execute the mysql_query to validate it

 

 

in you update.php file look for this line:

 

<td><input type="submit" name="submitButtonName" value="Update"><input type="hidden" name="id" value="<?=$id?>"></td>

 

change the short tags for long one as in the rest of your scripts.

 

and after that... in your updated.php echo $update before execute the mysql_query to validate it

 

 

 

Wow worked like a charm. I missed that.

 

Thanks for everyone's help.

 

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.