Jump to content

Update problem


lloydje

Recommended Posts

I'm having some problems with the update syntax.

 

I'm populating a form with data from a db, but when i change anything and then try to update it doesn't seem to work. There are no error messages, it just fails to do anything;

 

Here's my code - thanks for any help;

 

(at the top of the page)

 


<?php
    $usr = "user";
    $pwd = "pass";
    $db = "community";
    $host = "host";

    # connect to database
    $cid = mysql_connect($host,$usr,$pwd);
    if (!$cid) { echo("ERROR: " . mysql_error() . "\n");    }

?>

 

(within the page)

 


<?

    # processed when form is submitted back onto itself
    if ($REQUEST_METHOD=="POST") {

        # setup SQL statement
        $SQL = " UPDATE mn_upcomingEvents SET";
        $SQL = $SQL . " eventName = '$eventName', ";
        $SQL = $SQL . " date = '$date', ";
        $SQL = $SQL . " time = '$time', ";
        $SQL = $SQL . " location = '$location' ";
        $SQL = $SQL . " travelInfo = '$travelInfo' ";
        $SQL = $SQL . " url = '$url' ";
        $SQL = $SQL . " WHERE id = $id ";

        # execute SQL statement
        $result = mysql_db_query($db,"$SQL",$cid);

        # check for errors
        if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n");    }

        echo ("<P><strong>Link Updated</strong></P>\n");

    }
    else { # display edit form (not post method)

        # setup SQL statement to retrieve link
        # that we want to edit
        $SQL = " SELECT * FROM mn_upcomingEvents ";
        $SQL = $SQL . " WHERE id = $id ";

        # execute SQL statement
        $ret = mysql_db_query($db,$SQL,$cid);

        # retrieve values
        $row = mysql_fetch_array($ret);
	$eventName = $row['eventName'];
	$date = $row['date'];
	$time = $row['time'];
	$location = $row['location'];
	$travelInfo = $row['travelInfo'];
	$url = $row['url'];
?>

<FORM NAME="fa" ACTION="editEvent.php" METHOD="POST">
<INPUT TYPE="hidden" NAME="id" VALUE="<?php echo("$id"); ?>">
    
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Event Name</td>
<td><input name="eventName" type="text" value="<?php echo("$eventName"); ?>"/></td>
</tr>

<tr>
<td>Date</td>
<td><input name="date" type="text" value="<?php echo("$date"); ?>"/></td>
</tr>

<tr>
<td>Time</td>
<td><input name="time" type="text" value="<?php echo("$time"); ?>"/></td>
</tr>

<tr>
<td>Location</td>
<td><input name="location" type="text" value="<?php echo("$location"); ?>"/></td>
</tr>

<tr>
<td>Travel Info</td>
<td><input name="travelInfo" type="text" value="<?php echo("$travelInfo"); ?>"/></td>
</tr>

<tr>
<td>URL</td>
<td><input name="url" type="text" value="<?php echo("$url"); ?>"/></td>
</tr>
</table>

<INPUT TYPE="submit" VALUE="Update Link"></form>

<?php    }

mysql_close($cid);

?>

 

Thanks again.

Lloyd

Link to comment
Share on other sites

  • 2 weeks later...
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.