FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


make a backoffice





Reyntjensw
hi,

i want to make a backoffice system, can someone tell me how i can update my mysql database true a php script?


grtz
Code:
<?php



if ($submit) {

  // process form

  $db = mysql_connect("localhost", "username", "psword");

  mysql_select_db("dbname",$db);

  $sql = "UPDATE vragenlijst SET voornaam = '$voornaam'";

  $result = mysql_query($sql);

  echo "Bedankt voor de gegevens in te vullen, klik op index om terug naar de hoofdpagina te gaan.\n";

} else{



  // display form



  ?>


<table>

<tr>
  <form method="post" action="<?php $_POST['voornaam']"?>

  <td class="style1">Voornaam:</td><td><input type="Text" name="voornaam"><br></td></tr>
     
 </table>



  <input type="Submit" name="submit" value="Verzend">

  </form>



  <?php



} // end if



?>


whats wrong with this script?
simplyw00x
This assumes register_globals is on. IMO it's not. You need to set the variables manually. Like so:
Code:
  // process form

  $db = mysql_connect("localhost", "username", "psword");

  mysql_select_db("dbname",$db);

  $voornaam = $_POST['voornaam'];

  $sql = "UPDATE vragenlijst SET voornaam = '$voornaam'";

  $result = mysql_query($sql);
Reyntjensw
Is this correct?
Code:
<?php
if ($submit) {


  // process form

  $db = mysql_connect("localhost", "dbuser", "pasword");

  mysql_select_db("db",$db);

  $voornaam = $_POST['voornaam'];

  $sql = "UPDATE vragenlijst SET voornaam = '$voornaam'";

  $result = mysql_query($sql);


  // display form


  ?>


<table>

<tr>
  <form method="post" action="<?php $_POST['voornaam']"?>

  <td class="style1">Voornaam:</td><td><input type="Text" name="voornaam"><br></td></tr>
     
 </table>



  <input type="Submit" name="submit" value="Verzend">

  </form>



  <?php



} // end if



?>


this is the link http://chismoor.ahplace.com/test2.php
mathiaus
This lines messed up
<form method="post" action="<?php $_POST['voornaam']"?>


Don't know what your trying to do with the action but either leave it blank
<form method="post" action="">
or move the quote
<form method="post" action="<?php $_POST['voornaam']; ?>">
Reyntjensw
i've changed it but it still doesn't work!
for an example click on the previous link


grtz
mathiaus
I should've checked the whole code sorry. You have told it to only show the form when its submitted (impossible) Rolling Eyes

This way will show the form all the time
http://frihost.pastebin.com/749924

And this way only when it isnt submitted
http://frihost.pastebin.com/749923
Reyntjensw
thanks mathiaus, it's just what i needed!
i've got just 2 more questions:

1) i've got a script that displays whats in the database, is it possible to do the folowing things:

* i've changed the input field into a textarea can i display the content of the database (so whats in it) when i go to the page you gave me? if yes, how?

* if you click on submit, can you display whats in it with the script i posted below?

Code:

<?php
// Make a MySQL Connection
mysql_connect("localhost", "user", "pasword") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());

// Get all the data from the "example" table
$result = mysql_query("SELECT * FROM vragenlijst ORDER BY voornaam")
or die(mysql_error());



echo "<table border='1'>";
echo "<tr> <th>Voornaam</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['voornaam'];
}
echo "</table>";

?>


thanks a lot
Related topics
NEED HELP IN VIEWS AND TRIGGERSTa sumindo tópicos?Collecting Coins ?The ethics of firing someone for off-the-job bad behaviour
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.