Jump to content

Update script not working correcly, whats wrong?


JJohnsenDK

Recommended Posts

Hey

Why do i have to refesh the browser to view the text in the form? I cant see the error. Also when i hit the submit button the text again disapires, why?

[code]<?php
function forside(){

include('../config_sit00045.php');
$hent = mysql_query("SELECT * FROM forside");
while ($vis = mysql_fetch_array($hent)){
$overskrift = $vis['side_overskrift'];
$tekst = $vis['side_tekst'];
}
?>

<form method='POST'>
Overskrift:
<br />
<TEXTAREA rows="1" cols="40" name="side_overskrift"><?php echo $overskrift; ?></TEXTAREA>
<br />
<br />
Tekst:
<br />
<TEXTAREA rows="8" cols="75" name="side_tekst"><?php echo $tekst; ?></TEXTAREA>
<br />
<br />
<input type='submit' value='Ændre'>
</form>

<?php
$hent = mysql_query("SELECT * FROM forside");

$overskrift = $_POST['side_overskrift'];
$tekst = $_POST['side_tekst'];

$query = mysql_query("UPDATE `forside` SET `side_overskrift` = '".$overskrift."', `side_tekst` = '".$tekst."'");

}
?>[/code]
Link to comment
Share on other sites

Hi

Your not using the function code you have created to do anything with

does this need to be a function ?
does it need to be there at all?

[code]function forside(){

include('../config_sit00045.php');
$hent = mysql_query("SELECT * FROM forside");
while ($vis = mysql_fetch_array($hent)){
$overskrift = $vis['side_overskrift'];
$tekst = $vis['side_tekst'];
}[/code]

you are pulling the same information as if you would with the function here but your not including the db_name ,db_pass ect ect
[code] $hent = mysql_query("SELECT * FROM forside");

$overskrift = $_POST['side_overskrift'];
$tekst = $_POST['side_tekst'];
[/code]

then for the update maybe you could do with something like

[code]if (isset($_POST['submit'])){
$query = mysql_query("UPDATE 'forside' SET 'side_overskrift' = '".$_POST['side_overskrift']."', `side_tekst` = '".$_POST['ide_tekst']."'");
}[/code]

does this file also include a mysql_connect () config_sit00045.php
if not you will also need to connect to the db with the username, password , database name , database address

hope this point you in the right direction.
Link to comment
Share on other sites

Well... Im using the function in anohter script page. You know the code i have posted is in functions.php and then the functions in functions.php gets called in main.php. So im using the function.

I dont understand this:
[quote]you are pulling the same information as if you would with the function here but your not including the db_name ,db_pass ect ect[/quote]

what do you mean?

config_00045.php is the mysql_connect, just have anohter name  :P
Link to comment
Share on other sites

is it just me? or is this just overkill?
[code]
while($vis = mysql_fetch_array($hent)){
  $overskrift = $vis['side_overskrift'];
  $tekst = $vis['side_tekst'];
}
[/code]

and why are you trying to take information from a database that was already passed from the form?
[code]<?
function forside(){
include('../config_sit00045.php');
$hent = mysql_query("SELECT * FROM forside limit 1");
$vis = mysql_fetch_array($hent);
$overskrift = $vis['side_overskrift'];
$tekst = $vis['side_tekst'];
?>
<form method='POST'>
Overskrift:
<br />
<TEXTAREA rows="1" cols="40" name="side_overskrift"><?=$_POST[overskrift];?></TEXTAREA>
<br />
<br />Tekst:
<br />
<TEXTAREA rows="8" cols="75" name="side_tekst"><?=$_POST[tekst];?></TEXTAREA>
<br />
<br /><input type='submit' value='Ændre'>
</form>
<?
$hent = mysql_query("SELECT * FROM forside");
$overskrift = $_POST['side_overskrift'];
$tekst = $_POST['side_tekst'];
$query = mysql_query("UPDATE `forside` SET `side_overskrift` = '".$overskrift."', `side_tekst` = '".$tekst."'");
}
?>[/code]
if i understand what your trying to do that is :-)
Link to comment
Share on other sites

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.