Jump to content

problem with adding to the database


Goldi90

Recommended Posts

Hi,

how to make this form + php to make it work this way

 

from the drop-down box choose the database title, or ID, and then the form in which I write some content will be added to the database that matches the title or ID that is sometimes so as not to invade a mistake and content that I type is not added to another title or ID

 

I created something like this:

 

<?php
$db = new mysqli('localhost','xxxxx','xxxx','xxxx');
mysqli_query($db,'SET NAMES `utf8`');
$sqlnowe = mysqli_query($db,'SELECT * FROM `cc` ORDER BY `id` DESC  ');

		?>

<form action="formu.php" method="post">
<select name="tytul">
<?php while ($rownowe = mysqli_fetch_array($sqlnowe)) { ?>
	<option><? echo $rownowe['tytul']; ?></option><?php };?>

</select>


opismax:<br />
<input type="text" name="opismax" /><br />
<textarea name="opismax" cols="50" rows="10">Proszę, wpisz tutaj jakiś komentarz...</textarea>

<input type="submit" value="dodaj" />
</form>

<?php

// odbieramy dane z formularza
$tytul = $_POST['tytul'];
$opismax = $_POST['opismax'];

if($tytul and $opismax) {
    
   
    
    // dodajemy rekord do bazy
    $ins = mysqli_query("INSERT tytul='$tytul' INTO publications SET  opismax='$opismax'");
    
    if($ins) echo "Good";
    else echo "Bad";
    

}

?>

 

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.