Current location: Hot Scripts Forums » Programming Languages » PHP » Mysql - Php Update Script


Mysql - Php Update Script

Reply
  #1 (permalink)  
Old 04-21-04, 12:06 AM
StormX StormX is offline
New Member
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Mysql - Php Update Script

Ok here is the script i have to update values in my database, the only problem is it doesnt do anything, doesnt even have any errors.

Ok the first one is the page that contains the form to fill out that you submit to update it.

<?

$id=$_GET['id'];

include("dbci.php");

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM xfact_pages WHERE id='$id'";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();


$i=0;
while ($i < $num) {

$data=mysql_result($result,$i,"data");

++$i;
}


?>

<form action="update_page.php" method="post">
Data
<textarea name="ud_data"></textarea>
<br>
ID #
<input type="text" name="ud_id">
<br>
<input type="Submit" value="Update">
</form>
<? echo ("$data"); ?>

Ok then it sends to this script.......


<?
$ud_data=$_POST['ud_data'];
$ud_id=$_POST['ud_id'];

include("dbci.php");
mysql_connect(localhost,$username,$password);

$query="UPDATE xfact_pages SET data='$ud_data' WHERE id='$ud_id'";
mysql_query($query);
echo "Record Updated";
mysql_close();
?>


Now i dont know if theres something wrong with this or whats goin on, if you can figure out whats wrong with it or just plain give me a new Update script i would really appreciate it =)

Thanks
Reply With Quote
  #2 (permalink)  
Old 04-21-04, 12:51 AM
PattonD PattonD is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
This is a script i use for Updateing my poll system in admin. What i did was i added the id to the end like so.... poll.php?id=1 or the editing features id. Simply just write a admin front page with id in result. then make a link like so in each row.... Echo "<a href='poll.php?id=$id'>Link</a>" or <a href="poll.php?id=<?php echo $myrow["id"] ?>">Link</a> . Depending on your preference

PHP Code:

<?php

include_once ('./../db.php');
$dbcnx mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db("$base");
include(
'header.php');
echo 
"<br><br><br>";
if (
$id) {

  if (
$submit) {

    
$sql "UPDATE poll SET Title='$Title',Question='$Question',Option1title='$Option1title',Option2title='$Option2title',Option3title='$Option3title',Option4title='$Option4title',Option5title='$Option5title',Votes='$Votes',Option1='$Option1',Option2='$Option2',Option3='$Option3',Option4='$Option4',Option5='$Option5' WHERE id=$id";

    
$result mysql_query($sql);

    echo 
"Thank you! Information updated.\n";

  } else {

    
// query the DB

    
$sql "SELECT * FROM poll WHERE id=$id";

    
$result mysql_query($sql);

    
$myrow mysql_fetch_array($result);

    
?>
<table cellspacing="2" cellpadding="2" width="590" align="center">
<form method="post" action="<?php echo $PHP_SELF?>">
<input type=hidden name="id" value="<?php echo $myrow["id"?>">
<tr>
<td valign="top" width="80"></td>
<td valign="top" width="210"><b><font size="-1">Title:</font></b></td>
<td width="200"><input size="20" maxlength="250" type="text" name="Title" value="<? echo $myrow["Title"?>"></td>
<td valign="top" width="80"></td>
</tr>
<tr>
<td valign="top" width="80"></td>
<td valign="top" width="210"><b><font size="-1">Question:</font></b></td>
<td width="200"><input size="20" maxlength="250" type="text" name="Question" value="<? echo $myrow["Question"?>"></td>
<td valign="top" width="80"></td>
</tr>
<tr>
<td valign="top" width="80"></td>
<td valign="top" width="210"><b><font size="-1">Option 1 Name:</font></b></td>
<td width="200"><input size="20" maxlength="250" type="text" name="Option1title" value="<? echo $myrow["Option1title"?>"></td>
<td valign="top" width="80"></td>
</tr>
<tr>
<td valign="top" width="80"></td>
<td valign="top" width="210"><b><font size="-1">Option 2 Name:</font></b></td>
<td width="200"><input size="20" maxlength="250" type="text" name="Option2title" value="<? echo $myrow["Option2title"?>"></td>
<td valign="top" width="80"></td>
</tr>
<tr>
<td valign="top" width="80"></td>
<td valign="top" width="210"><b><font size="-1">Option 3 Name:</font></b></td>
<td width="200"><input size="20" maxlength="250" type="text" name="Option3title" value="<? echo $myrow["Option3title"?>"></td>
<td valign="top" width="80"></td>
</tr>
<tr>
<td valign="top" width="80"></td>
<td valign="top" width="210"><b><font size="-1">Option 4 Name:</font></b></td>
<td width="200"><input size="20" maxlength="250" type="text" name="Option4title" value="<? echo $myrow["Option4title"?>"></td>
<td valign="top" width="80"></td>
</tr>
<tr>
<td valign="top" width="80"></td>
<td valign="top" width="210"><b><font size="-1">Option 5 Name:</font></b></td>
<td width="200"><input size="20" maxlength="250" type="text" name="Option5title" value="<? echo $myrow["Option5title"?>"></td>
<td valign="top" width="80"></td>
</tr>
<tr>
<td valign="top" width="80"></td>
<td valign="top" width="210"><b><font size="-1">Total Votes:</font></b></td>
<td width="200"><input size="20" maxlength="250" type="text" name="Votes" value="<? echo $myrow["Votes"?>"></td>
<td valign="top" width="80"></td>
</tr>
<tr>
<td valign="top" width="80"></td>
<td valign="top" width="210"><b><font size="-1">Option 1 Votes:</font></b></td>
<td width="200"><input size="20" maxlength="250" type="text" name="Option1" value="<? echo $myrow["Option1"?>"></td>
<td valign="top" width="80"></td>
</tr>
<tr>
<td valign="top" width="80"></td>
<td valign="top" width="210"><b><font size="-1">Option 2 Votes:</font></b></td>
<td width="200"><input size="20" maxlength="250" type="text" name="Option2" value="<? echo $myrow["Option2"?>"></td>
<td valign="top" width="80"></td>
</tr>
<tr>
<td valign="top" width="80"></td>
<td valign="top" width="210"><b><font size="-1">Option 3 Votes:</font></b></td>
<td width="200"><input size="20" maxlength="250" type="text" name="Option3" value="<? echo $myrow["Option3"?>"></td>
<td valign="top" width="80"></td>
</tr>
<tr>
<td valign="top" width="80"></td>
<td valign="top" width="210"><b><font size="-1">Option 4 Votes:</font></b></td>
<td width="200"><input size="20" maxlength="250" type="text" name="Option4" value="<? echo $myrow["Option4"?>"></td>
<td valign="top" width="80"></td>
</tr>
<tr>
<td valign="top" width="80"></td>
<td valign="top" width="210"><b><font size="-1">Option 5 Votes:</font></b></td>
<td width="200"><input size="20" maxlength="250" type="text" name="Option5" value="<? echo $myrow["Option5"?>"></td>
<td valign="top" width="80"></td>
</tr>
<tr>
<td colspan=2 align="right"><input type="Submit" name="submit" value="Update"></td>
</tr>
</form>
</table>
<?php
}
include(
'footer.php');
}
?>

Last edited by PattonD; 04-21-04 at 12:54 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 01:41 AM
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
MySql update form script? dihan PHP 8 01-10-04 03:35 AM
PHP to MySQL script question...(using a field to update info in MySQL) DisneyFan25863 PHP 4 11-02-03 03:31 AM
PHP + MySQL script help need andyinorbit2000 PHP 1 09-09-03 02:07 AM


All times are GMT -5. The time now is 10:27 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.