•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,607 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,492 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 3521 | Replies: 6
![]() |
•
•
Join Date: Apr 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Hi,
I have this code. It works fine using PHP 4 and MySQL 5.0. but it doesn't work at all on my webhost (php4 mySQL 4) and I cannot for the life of me figure out why.
Here's my code:
/<?
// Connect database.
include("connectdb.php");
//if "Submit" button is clicked
if($_POST['Submit']){
//Get parameters from form
$id=$_GET['id'];
$name=$_POST['name'];
$email=$_POST['email'];
$tel=$_POST['tel'];
//Update database record
mysql_query("update phonebook set name='$name', email='$email', tel='$tel' where id='$id'");
//Redirect to record view page
header("location:select.php");
exit;
}
// ************* End update part *************
//Get record id to display data for record to be updated
$id=$_GET['id'];
//Put all the results from the query into $result
$result=mysql_query("select * from phonebook where id='$id'");
//Split result into rows and put in $row
$row=mysql_fetch_assoc($result);
?>
<!-- END PHP. This is the HTML form for updating the record -->
<html>
<body>
<!-- set this form to POST method and target itself ($PHP_SELF
-->
<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
<p>Name :
<!-- name of this text field is "name" -->
<input name="name" type="text" id="name" value="<? echo $row['name']; ?>"/>
<br />
Email :
<!-- name of this text field is "email" -->
<input name="email" type="text" id="email" value="<? echo $row['email']; ?>"/>
<br />
Tel :
<!-- name of this text field is "tel" -->
<input name="tel" type="text" id="tel" value="<? echo $row['tel']; ?>"/>
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>
---end update.php----
For some reason this fails to update the db, but doesn't give an error. The exact same code works perfectly on my development system (php4 and mysql 5.0).
When I try to do the following in phpmyadmin on my webhost it works fine:
UPDATE phonebook SET name='test', email='test', tel='123' WHERE id='2';
But somehow it doesn't work when i use the update.php script.
The weirdest thing is that I can do a lookup query just fine, for example the code below works just fine and it also uses the same $id variable.
$result=mysql_query("select * from phonebook where id='$id'");
$row=mysql_fetch_assoc($result);
I'm at my wits end and don't know what else to try. Do you have any suggestions?
I have this code. It works fine using PHP 4 and MySQL 5.0. but it doesn't work at all on my webhost (php4 mySQL 4) and I cannot for the life of me figure out why.
Here's my code:
/<?
// Connect database.
include("connectdb.php");
//if "Submit" button is clicked
if($_POST['Submit']){
//Get parameters from form
$id=$_GET['id'];
$name=$_POST['name'];
$email=$_POST['email'];
$tel=$_POST['tel'];
//Update database record
mysql_query("update phonebook set name='$name', email='$email', tel='$tel' where id='$id'");
//Redirect to record view page
header("location:select.php");
exit;
}
// ************* End update part *************
//Get record id to display data for record to be updated
$id=$_GET['id'];
//Put all the results from the query into $result
$result=mysql_query("select * from phonebook where id='$id'");
//Split result into rows and put in $row
$row=mysql_fetch_assoc($result);
?>
<!-- END PHP. This is the HTML form for updating the record -->
<html>
<body>
<!-- set this form to POST method and target itself ($PHP_SELF
--><form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
<p>Name :
<!-- name of this text field is "name" -->
<input name="name" type="text" id="name" value="<? echo $row['name']; ?>"/>
<br />
Email :
<!-- name of this text field is "email" -->
<input name="email" type="text" id="email" value="<? echo $row['email']; ?>"/>
<br />
Tel :
<!-- name of this text field is "tel" -->
<input name="tel" type="text" id="tel" value="<? echo $row['tel']; ?>"/>
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
</body>
</html>
---end update.php----
For some reason this fails to update the db, but doesn't give an error. The exact same code works perfectly on my development system (php4 and mysql 5.0).
When I try to do the following in phpmyadmin on my webhost it works fine:
UPDATE phonebook SET name='test', email='test', tel='123' WHERE id='2';
But somehow it doesn't work when i use the update.php script.
The weirdest thing is that I can do a lookup query just fine, for example the code below works just fine and it also uses the same $id variable.
$result=mysql_query("select * from phonebook where id='$id'");
$row=mysql_fetch_assoc($result);
I'm at my wits end and don't know what else to try. Do you have any suggestions?
•
•
Join Date: Aug 2007
Location: Morrisdale, PA
Posts: 52
Reputation:
Rep Power: 2
Solved Threads: 5
•
•
Join Date: Apr 2007
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
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.
•
•
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 643
Reputation:
Rep Power: 3
Solved Threads: 72
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);
?> Last edited by kkeith29 : Nov 8th, 2007 at 10:13 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- [For Hire] Php, Mysql, ASP, AJAX, DHTML programmer (Post your Resume)
- WANTED : PHP/Mysql programmer (US time zone) (Web Development Job Offers)
- PHP Mysql HELP PLEASE (PHP)
- I m a beginner in PHP-Mysql (PHP)
- free php/mysql programming (Web Development Job Offers)
- php mysql problem (PHP)
- SEO PHP MYSQL How to promote? (Promotion and Marketing Plans)
- PHP and MySQL Web Development (PHP)
- php mysql help (PHP)
Other Threads in the PHP Forum
- Previous Thread: validatiom
- Next Thread: A little help please


Linear Mode