954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Tearing my hair out over PHP mysql update script




Name :



Email :



Tel :



bling_bling_vr6
Newbie Poster
7 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

I don't see anywhere in your form the value of 'id'
Place a hidden field in your form to hold this value so the SQL statement will read the value and update.

JeniF
Junior Poster in Training
52 posts since Aug 2007
Reputation Points: 10
Solved Threads: 5
 

Hmm, I tried that. I added a hidden field with the called record with the value of id and then tried to pick it up at the beginning of the if statement instead of $id=$_GET[id] i now have $id = $_POST[record]. But still I don't get my record updated. I even tried to see if my variables even receive the $_POST data and they do...I can echo the data out...just can't update it to the db somehow.

bling_bling_vr6
Newbie Poster
7 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

try this:

<?php

include("connectdb.php");

if(isset($_POST['Submit'])){

$id = $_REQUEST['id'];
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$tel = $_REQUEST['tel'];

$sql = "UPDATE phonebook SET name = '" . $name . "', email = '" . $email . "', tel = '" . $tel . "' WHERE id = '" . $id . "'";
$query = mysql_query($sql);

if ($query) {
header("location:select.php");
exit;
}
}

$id = $_REQUEST['id'];

$result=mysql_query("select * from phonebook where id='$id'");

$row=mysql_fetch_assoc($result);

?>
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

Did you check the user/passw/database and privileges on your MySQL 5.0 ?

chmazur
Light Poster
30 posts since Sep 2007
Reputation Points: 10
Solved Threads: 3
 

why do you put ' ' to assign numbers to the variables. it usually gives error.

where id=$id")

fatihpiristine
Posting Whiz in Training
283 posts since Sep 2007
Reputation Points: 6
Solved Threads: 19
 

it has never given me an error

kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You