Sunday, 15 September 2013

php - Update data from a form to table -



php - Update data from a form to table -

i have form on page gets info table in database. want able alter info in from, , post updates table new information.

so far got form working, , getting info table displayed in well. can't update info table; press update button, , success reply, info same before. it's not updating - no errors or warnings code.

this form:

<span id="main-content"> <?php $sql = "select * settings id=1"; if(!$result = $db->query($sql)){ die('there error running query [' . $db->error . ']'); } if(!empty($_post)) { update_settings($_post['info']); } if ($result = mysqli_query($db, $sql)) { while ($row = mysqli_fetch_assoc($result)) { echo "<form action='' method='post'>"; echo "<label>overskrift</label>"; echo "<textarea name='info' required>".$row['info']."</textarea>"; echo "<input type='submit' value='update'>"; echo "</form>"; } mysqli_free_result($result); } mysqli_close($db); ?>

and here function sending to.

//update settings function update_settings($info) { global $db; $query = "update settings set info = '$info' id = '$1'"; $result = $db->query($query); echo "<div class='success wow fadeindown'><b>success:</b> dit oplæg er nu opdateret.</div>"; }

php mysql forms post

No comments:

Post a Comment