Insert into Mysql and get unique id [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have following:
index.php
<form method="get" action="rezultat.php" name="form-area" id="form-area" class="form-area" />
<h4>Informatii despre prieten</h4>
<input type="text" id="name" name="nu" placeholder="" maxlength="25" required />
<input type="text" id="name" name="pr" placeholder="" maxlength="25" required />
<input type="text" id="name" name="va" placeholder="" maxlength="2" required />
<input type="text" id="name" name="lo" placeholder="" maxlength="25" required />
<h4>Informatii despre tine</h4>
<input type="text" id="name" name="np" placeholder="" maxlength="25" required />
<input type="text" id="name" name="pn" placeholder="" maxlength="4" required />
<select name="stire" required >
<option value="Nu ai selectat">Selecteaza</option>
<option value="0">................................ </option>
<option value="Bautor de sperma">[MASCULIN] - Bautor de sperma </option>
<option value="Protest in chiloti">[MASCULIN] - Protest in chiloti </option>
<option value="Si-a taiat penisul">[MASCULIN] - Si-a taiat penisul </option>
<option value="Masturbare in public">[MASCULIN] - Masturbare in public </option>
<option value="Fan Facebook">[MASCULIN] - Fan Facebook </option>
<option value="0">................................ </option>
<option value="Prostituata anului">[FEMININ] - Prostituata anului </option>
<option value="Cu sanii la vedere">[FEMININ] - Cu sanii la vedere </option>
<option value="Sex oral in public">[FEMININ] - Sex oral in public </option>
<option value="A violat un mos">[FEMININ] - A violat un mos </option>
<option value="Miss Urzica">[FEMININ] - Miss Urzica </option>
</select>
<input type="submit" name="submit" value="Submit" />
</form>
rezultat.php
<?php include 'config.php'; include 'colectare.php'; ?>
<? echo $link; ?> //that show url link
config.php
<?php
$host="localhost";
$user_name="USER";
$pwd="PWD";
$database_name="DB";
$conexiune = mysql_connect($host,$user_name,$pwd) or die("Nu ma pot conecta la MySQL!");
mysql_select_db($database_name, $conexiune) or die("Nu gasesc baza de date");
$adresa="http://site.com/";
?>
colectare.php
<?
$host="localhost";
$user_name="USER";
$pwd="PWD";
$database_name="DB";
$db=mysql_connect($host, $user_name, $pwd);
if (mysql_error() > "") print mysql_error() . "<br>";
mysql_select_db($database_name, $db);
if (mysql_error() > "") print mysql_error() . "<br>";
$find = array ("/ /");
$replace = array ("+");
$link = $adresa.'stiri.php? pn='.ucwords($_GET["pn"]).'&nu='.ucwords($_GET["nu"]).'&pr='.ucwords($_GET["pr"]).'&va='.ucwords($_GET["va"]).'&lo='.ucwords($_GET["lo"]).'&stire='.$_GET["stire"];
$link = preg_replace($find,$replace,$link);
$stire = $_GET["stire"];
$np = htmlentities($_GET['np'], ENT_QUOTES | ENT_HTML5);
$pn = $_GET["pn"];
$datetime = gmDate('Y-m-d H:i:s');
$query = "insert into stiri (url, stire, np, pn, hits, datetime) values ('" . $link . "', '" . $stire . "', '" . $np . "', '" . $pn . "', '" . $hits . "', NOW())";
$result = mysql_query($query);
?>
stiri.php
<? include_once "config.php"; ?>
<?
$find = array ("+");
$replace = array ("/ /");
$pn = ucwords($_GET["pn"]);
$nu = ucwords($_GET["nu"]);
$pr = ucwords($_GET["pr"]);
$va = ucwords($_GET["va"]);
$lo = ucwords($_GET["lo"]);
$stire = $_GET["stire"];
?>
<?php
if($stire == "Bautor de sperma"){ // TITLUL FARSEI
echo include("bautor-de-sperma.php"); // PAGINA PHP A FARSEI
}
elseif($stire == "Protest in chiloti"){ // TITLUL FARSEI
echo include("protest.php"); // PAGINA PHP A FARSEI
}
elseif($stire == "Si-a taiat penisul"){ // TITLUL FARSEI
echo include("taiat.php"); // PAGINA PHP A FARSEI
}
elseif($stire == "Masturbare in public"){ // TITLUL FARSEI
echo include("masturbare.php"); // PAGINA PHP A FARSEI
}
elseif($stire == "Fan Facebook"){ // TITLUL FARSEI
echo include("facebook.php"); // PAGINA PHP A FARSEI
}
elseif($stire == "Prostituata anului"){ // TITLUL FARSEI
echo include("prostituata.php"); // PAGINA PHP A FARSEI
}
elseif($stire == "Cu sanii la vedere"){ // TITLUL FARSEI
echo include("sani.php"); // PAGINA PHP A FARSEI
}
elseif($stire == "Sex oral in public"){ // TITLUL FARSEI
echo include("sex.php"); // PAGINA PHP A FARSEI
}
elseif($stire == "A violat un mos"){ // TITLUL FARSEI
echo include("viol.php"); // PAGINA PHP A FARSEI
}
elseif($stire == "Miss Urzica"){
echo include("urzica.php");
}
else
{
echo "Ne pare rau, insa aceasta stire nu mai exista. Vezi mai multe <a href='http://site.ro'>AICI</a>";
}
?>
and i give u and one page, urzica.php for example wich contain following::
<? echo $nu; ?> , <? echo $pr; ?> , <? echo $va; ?> , <? echo $lo; ?>
With that metod, all informations are stored in database, but link it's show all informations, cuz i use get method .
The link its offered like that:
http://site.ro/stiri.php?pn=SOMETHING&nu=SOMETHING&pr=SOMETHING&va=SOMETHING&lo=SOMETHING&stire=SELECTED-ONE
I want to use post method, and that complicated my brain, and to show me something like that:
http://site.ro/stire.php?nume=NAME-FROM-SELECT-FORM
I hope to understand something guys

I'm not 100% certain what you're after, but this MySQL class should help. Basically, all your operations on the database go through here, and you will get that unique id you want on MySQL INSERT commands:
https://gist.github.com/jbnunn/6297071
To use it, set up your connection parameters:
$db_host = 'localhost';
$db_username = 'USER';
$db_password = 'PWD';
$db_database = 'DB';
$GLOBALS['db'] = new MySQL($db_host, $db_username, $db_password, $db_database);
if(!function_exists("getDB")) {
function getDB() {
return($GLOBALS['db']);
}
}
Then, in your code, require that MySQL class,
require_once('mysql.php')
and make inserts like:
$db = getDB();
$id = $db->insert("insert into stiri (url, stire, np, pn, hits, datetime) values ('" . $link . "', '" . $stire . "', '" . $np . "', '" . $pn . "', '" . $hits . "', NOW())");
and get the row's ID from the $id variable.
To get data out of your database, you could make queries via methods like this:
$result = $db->execute("SELECT * FROM stiri WHERE id = '$id'");

Related

My SQL Update query won't update the specified record [duplicate]

This question already has answers here:
What to do with mysqli problems? Errors like mysqli_fetch_array(): Argument #1 must be of type mysqli_result and such
(2 answers)
Closed 3 years ago.
I'm making a system where you can assign guests to certain rooms. To unassign a guest, two UPDATE queries must be executed in two different tables, but only one of these is actually executing. The one that doesn't work, doesn't put out an error message, but doesn't seem to do anything.
I've already printed out all the variables I'm using in my query to check for mistakes, but I haven't found any data in those which was wrong. I also checked if there were errors in my query using phpMyAdmin, but they properly executed there. I used the same type of method on another page, updating something else, and that worked. Could someone take a look in my code and tell me what I've done wrong?
Thanks in advance!
if(isset($_GET['view'])) {
$viewid = $_GET['view'];
$sql = "SELECT * FROM renterinfo LEFT JOIN apartments ON apartments.renterid = renterinfo.renterid WHERE renterinfo.renterid = $viewid";
$xresult = mysqli_query($conn, $sql);
$xrow = mysqli_fetch_array($xresult);
}
$freeroomquery = "SELECT * FROM apartments WHERE status = 1 ORDER BY apartmentno ASC";
$freerooms = mysqli_query($conn, $freeroomquery);
$rentername = $xrow['name'];
$renteremail = $xrow['email'];
$roomno = $xrow['apartmentno'];
$enddate = $xrow['leaveroom'];
if(isset($_POST['submit'])){
//------------------------------------
$name = $_POST['newNaam'];
$email = $_POST['newEmail'];
$room = $_POST['newKamer'];
$leaveroom = $_POST['newEinde'];
$insertSql = "UPDATE renterinfo SET name = '$name', email = '$email', leaveroom = '$leaveroom'";
$updateRoom = "UPDATE apartments SET renterid = NULL WHERE apartmentno = '$roomno'";
The second UPDATE query doesn't update the renterid. The first UPDATE query does work.
if ($conn->query($insertSql) === TRUE) {
$success = "Huurder <strong>'" . $name . " - CobbenCampus'</strong> is succesvol toegevoegd.";
} else {
$error = "Er is een fout opgetreden bij het toevoegen van appartement <strong>'" . $apartmentno . " - CobbenCampus'</strong>. Zijn alle velden ingevuld?<br><strong>Foutmelding:</strong> " . $sql . "<br>" . $conn->error;
}
if ($conn->query($updateRoom) === TRUE) {
echo "Succeeded.";
} else {
echo "Query unsuccessfull.";
}
$conn->close();
}
HTML-code:
<form action="viewrenter.php" method="POST" enctype="multipart/form-data">
<label id="first">Voor- en achternaam huurder:</label><br>
<input type="text" name="newNaam" value="<?php echo $rentername ?>"><br><br>
<hr class="line-black">
<label id="first">E-mailadres van huurder:</label><br>
<input type="text" name="newEmail" value="<?php echo $renteremail ?>"><br><br>
<hr class="line-black">
<label id="first">Kamernummer:</label><br/>
<p>Een kamer toewijzen aan een huurder, zal de kamer automatisch op bezet zetten.</p>
<select name="newKamer">
<option value="<?php echo $roomno ?>"><?php echo $roomno ?></option>
<option value="0">Geen kamer</option>
<?php
while($rooms = mysqli_fetch_array($freerooms)) {
echo "<option value='" . $rooms['apartmentno'] . "'>" . $rooms['apartmentno'] . "</option>";
}
?>
</select><br><br>
<hr class="line-black">
<label id="first">Afloopdatum huurdersovereenkomst:</label><br>
<input type="text" name="newEinde" placeholder="Als: 25-04-2019" value="<?php echo $enddate ?>"><br><br>
<button class="spaced btn btn-primary btn-wide" type="submit" name="submit">Voeg huurder toe</button>
<hr class="bigspacer">
</form>
UPDATE apartments SET `renterid` = NULL WHERE `apartmentno` = `$roomno`
Write query like this. I think it will work.

Calendar in php and html

I'm developing a calendar with reservations in HTML and PHP (I do not know how to do otherwise). Only I have a problem with formats and data.
First of all I have problems regarding the date, I had to set it as "integer" on Postgresql and consequently on the form html as text (and this is the first thing I would like to change).
Same thing regarding the timetable.
form.php
<?php
if (isset($_POST['submit']) && $_POST['submit']=="invia")
{
$titolo = addslashes($_POST['titolo']);
$testo = addslashes($_POST['testo']);
$str_data = strtotime($_POST['data']);
include 'config.php';
$sql = "INSERT INTO appuntamenti (titolo,testo,str_data ) VALUES ('$titolo', '$testo', '$str_data')";
if($result = pg_query($sql))
{
echo "Inserimento avvenuto con successo.<br>
Vai al Calendario";
}
}else{
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Titolo:<br>
<input name="titolo" type="text"><br>
Testo:<br>
<textarea name="testo" cols="30" rows="8"></textarea><br>
Data:<br>
<input name="data" type="text" value="gg-mm-aaaa"><br>
Orario:<br>
<input name="hour" type="time" ><br> -->
<input name="submit" type="submit" value="invia">
</form>
<?php
}
?>
appuntamenti.php
<?php
if(isset($_GET['day']) && is_numeric($_GET['day']))
{
$day = $_GET['day'];
include 'config.php';
$sql = "SELECT * FROM appuntamenti WHERE str_data=$day";
$result = pg_query($sql);
if(pg_num_rows($result) > 0)
{
while($fetch = pg_fetch_array($result))
{
$id = stripslashes($fetch['id']);
$titolo = stripslashes($fetch['titolo']);
$testo = stripslashes($fetch['testo']);
$data = date("d-m-Y", $fetch['str_data']);
$hour = date("hh-mm", $fetch['hour']);
echo "Appuntamenti del <b>$data</b> delle <b>$hour</b><br>" . $titolo . "<br>" . $testo . "<br>
Cancella |
Modifica
<hr>";
}
}
}
?>
In this case i receive the date in the correct way ( but the user inserts this like text, and i don't want to do this. ) and the hours likes 0101-0101.
How can i solve?
Thanks you all

how can i insert records of the option that was selected from database?

so as you all can see this is a little piece of the form that is causing a problem.
i am getting all the records in the form with a dropdown and want to send the selected result to the database.
after submitting records are inserted correct except this two: $locatie =$_POST["locatie"]; and $vestiging = $_POST["vestiging"];
are inserted as NULL.
i would like it to send the records that was selected in the form.
can someone help me?
<form name="nieuwTicket" action="nieuwTicketNieuwKlant.php" method="POST">
<label class="hidden02">locatie:</label>
<select name="locatie" class="hidden2">
<option value = "">---Select---</option>
<?php
$ophaall = "SELECT * FROM locatie ";
$resultl = mysqli_query($connectie, $ophaall);
while ($l = mysqli_fetch_assoc($resultl)) {
echo "<option value='{" . $l['locatieId'] . "}'>" . $l['locatieId'] . " " . $l['locOmschrijving'] . "</option>";
}
?>
</select><br>
<label class="hidden02">vestiging:</label>
<select name="vestiging" class="hidden2"> <!-- Disabled, gaan we nog niets mee doen-->
<option value = "">---Select---</option>
<?php
$ophaalv = "SELECT * FROM vestigingen ";
$resultv = mysqli_query($connectie, $ophaalv);
while ($v = mysqli_fetch_assoc($resultv)) {
echo "<option value='{" . $v['vestigingId'] . "}'>" . $v['vestigingId'] . " " . $v['vesOmschrijving'] . "</option>";
}
?>
</select><br>
<input type="submit" name="submit1" value="invoeren" class="hidden" />
</form>
<!--submit insert to database-->
<?php
$locatie = $_POST["locatie"];
$vestiging = $_POST["vestiging"];
if (isset($_POST['submit1'])) {
// nieuwe klant
$insertklant = $connectie->prepare("INSERT INTO klant (klantId, klantAchternaam, klantNaam, klantTel,
klantAdres, klantPostc, klantStad, klantEmail, instantieId, locatieId)
VALUES ('',?,?,?,?,?,?,?,?,?)");
if ($insertklant) {
$insertklant->bind_param('sssssssii', $achternaam, $naam, $tel, $adres, $postcode, $stad, $email, $locatie, $vestiging);
if ($insertklant->execute()) {
echo ' klant gemaakt!';
}
}
?>

Var not affected on mysql

Good morning all !
I have a problem with a var in my code :
<?Php
error_reporting(E_ALL);
//Si IP correspond pas au PC autorisé, on retourne au debut.
include "./_protection.php";
$data='';
$rep='';
$requete='';
$val = '';
$Reference= '';
echo '<h2><u>Commander des pièces</u></h2><br>';
/*****************************************************************************************************
* AJOUT DE PIECE DANS LA BASE DE DONNEES
*****************************************************************************************************/
if(#$_POST['action'] == "ajouter")
{
if(!empty($_POST['choix'])){
foreach($_POST['choix'] as $val){
$Reference.="$val,";
}
//Injection dans la base SQL
include "./../connexion.inc";
mysql_query("INSERT INTO `tbl_commandes` ( `id`, `Eleve`, `Reference`, `Quantite`, `Date`, `Statut` )
VALUES ( '', '".$_POST['Eleve']."', '".$_POST['Reference']."', '".$_POST['Quantite']."', '".$_POST['Date']."', '".$_POST['Statut']."' )");
mysql_close();
}
}
/*****************************************************************************************************
* FORMULAIRE POUR L'AJOUT DE PIECE
*****************************************************************************************************/
echo '
<fieldset>
<legend>Commander des Pièces</legend>
<FORM action="./?page=commande_piece_full_php" method="POST">
<p align="left">
<H2>Pièces :</h2>
<br>';
echo $Reference;
include "./../connexion.inc";
$rep = mysql_query("SELECT id_categorie_piece, categorie_piece FROM tbl_categorie_piece ORDER BY categorie_piece");
mysql_close();
include "./../connexion.inc";
while($data = mysql_fetch_array($rep))
{
echo $data['categorie_piece'];
echo '<br>';
$requete = $data['id_categorie_piece'];
$reponse = mysql_query("SELECT id_piece, piece FROM tbl_piece WHERE idr_categorie_piece='$requete' ORDER BY piece");
while($donnees = mysql_fetch_array($reponse)){
?> <input type="checkbox" name="choix[]" value="<? echo $donnees['id_piece'] ?>"><? echo $donnees['piece'] ?><br> <?
}
echo '<br>';
}
mysql_close();
echo '
Elève :
<select name="Eleve">';
include "./../connexion.inc";
$reponse2 = mysql_query("SELECT id_client, client FROM tbl_client ORDER BY client");
while($donnees2 = mysql_fetch_array($reponse2))
{
?> <option value="<? echo $donnees2['client'] ?>"><? echo $donnees2['client'] ?></option> <?
}
mysql_close();
echo '
</select>
<br>
Date souhaitée : <input type="textbox" name="Date">
<br>
Quantité : <input type="textbox" name="Quantite">
<br>
<input type="submit" value="ajouter">
<input type="hidden" name="action" value="ajouter">
</form>
</fieldset>';
?>
my var $reference is Ok, i can echo $reference; and get the content rightly
BUT when i wanna send $reference to my mysql table .. that doesn't send it
When i submit, i get this notice from the parser : Notice:
Undefined index: Reference in /home/bddstock/www/admin/commande_piece_full_php.php on line 27
but when it is submited i get the right content in my echo line under PIECES
so i really don't understand ..
can someone help me ?
Change your insert statement to
mysql_query("INSERT INTO `tbl_commandes` ( `id`, `Eleve`, `Reference`,
`Quantite`, `Date`, `Statut` )
VALUES ( '', '".$_POST['Eleve']."', '".$Reference."', '".$_POST['Quantite']."', '".$_POST['Date']."', '".$_POST['Statut']."' )");
i.e change $_POST['Reference'] to $Reference as you have not posted this field and it seems you derive it from looping $_POST['choix'].
Note : use mysqli instead of mysql and refer How can I prevent SQL injection in PHP?

mysqli_real_escape_query, query seems ok, but nothing written in database

I have a form, method="post" where users can input info like their name and email, that then get's inserted in a database. For safety I tried to use mysqli_real_escape_string.
Now, the query says it worked but no data get's inserted in my database. Without the escape everything worked allright too (except for not being escaped)
CODE:
(Updated missing quote, it's there in my original code, so that's not the problem. Sry for that)
if(isset($_POST['submit'])) {
$email = explode('#',$_POST['mail']); //explode because I only need the prefix
$maila = mysqli_real_escape_string($link,$email[0]);
$name = mysqli_real_escape_string($link,$_POST['name']);
$query = "INSERT INTO base(mail,name) VALUES ('$maila','$name')";
if(mysqli_query($link,$query)) {
echo "SUCCES";
}
else {
echo "FAIL";}
}
So when I process the query, SUCCES comes up but the mail and name don't arrive in my table.
I googled and searched here, but couldn't find a solution (excuse me if I overlooked it). I also hope I posted enough of my code.
Extra info:
Before the SQL-query goes into action the form is checked in a way like
if($_POST['name'] == null){echo "an error message";}
EDIT; FULL CODE (I am aware that there are mistakes/stupid things in my if-statements, but these work fine without escaping so I will check these later)
<?php
if(isset($_POST['submit'])) {
if($_POST['ios'] == null ) {$resios = 0;} else {$resios = $_POST['ios'];}
if($_POST['android'] == null) {$resand = 0;} else {$resand = $_POST['android'];}
if($_POST['windows'] == null) {$reswin = 0;} else {$reswin = $_POST['windows'];}
//Check for errors
if($_POST['naam'] == null) {echo "<span class=\"error\">Gelieve een naam in te vullen</span><br />";}
if($_POST['opleiding'] == 0) {echo "<span class=\"error\">Selecteer een opleiding</span><br />";}
if($resios > $ios) {$resios = $ios; echo "<span class=\"error\">Aantal iOS tablets overschreden. Maximum " . $ios . " tablets beschikbaar.</span><br />";}
if($resand > $android) {$resand = $android; echo "<span class=\"error\">Aantal Android tablets overschreden. Maximum " . $android . " tablets beschikbaar.</span><br />";}
if($reswin > $windows) {$reswin = $reswin; echo "<span class=\"error\">Aantal Windows tablets overschreden. Maximum " . $windows . " tablets beschikbaar.</span><br />";}
if($resios < 0) {$resios = 0; echo "<span class=\"error\">Aantal tablets kan niet lager zijn dan 0!</span><br />";}
if($resand < 0) {$resand = 0; echo "<span class=\"error\">Aantal tablets kan niet lager zijn dan 0!</span><br />";}
if($reswin < 0) {$reswin = 0; echo "<span class=\"error\">Aantal tablets kan niet lager zijn dan 0!</span><br />";}
if($_POST['terms'] != 'on') {echo "<span class=\"error\">Reglement moet aanvaard worden.</span><br />";}
if($resios == 0 && $resand == 0 && $reswin == 0) {echo "<span class=\"error\">Er moet minstens 1 tablet gereserveerd worden</span>";}
else {
//ESCAPE + INSERT
$email = explode('#',$_POST['mail']);
$maila = mysqli_real_escape_string($link,$email[0]);
$opleiding = mysqli_real_escape_string($link,$_POST['opleiding']);
$naam = mysqli_real_escape_string($link,$_POST['naam']);
$datum = mysqli_real_escape_string($link,$datum);
$resios = mysqli_real_escape_string($link,$resios);
$resand = mysqli_real_escape_string($link,$resand);
$reswin = mysqli_real_escape_string($link,$reswin);
$opmerking = mysqli_real_escape_string($link,$_POST['opmerking']);
$query = "INSERT INTO reservaties(oplid,naam,datum,ios,android,windows,emailname,opmerking) VALUES ('$opleiding','$naam','$datum','$resios','$resand', '$reswin','$maila', '$opmerking')";
if(mysqli_query($link,$query)) {
echo "<p class=\"succes\">U hebt succesvol " . $resios . " iOS-tablets, " . $resand . " Android-tablets en " . $reswin . " Windows-tablets gereserveerd op " . $disdate . "</p>";
echo "<p>Een bevesting van uw reservatie via mail? <form style=\"display:inline;\" target=\"_blank\" action=\"print.php\" method=\"post\"><input type=\"text\" name=\"mail\" value=\"".$maila."\" />#arteveldehs.be <input type=\"hidden\" name=\"naam\" value=\"".$_POST['naam']."\"/><input type=\"hidden\" name=\"datum\" value=\"". $datum . "\"/><input type=\"submit\" name=\"print\" value=\"mail\"></form></p>";
}
else {
echo "<p class=\"error\">Er is een fout opgetreden. Probeer opnieuw, of neem contact op met de Mediatheek.</p>";}
}
}
?>
<!-- my form-->
<form action="#" method="post">
<table>
<tr><td colspan="3"><span class="required">*</span> = verplicht veld</td></tr>
<tr><td>Naam:<span class="required">*</span></td><td><input type="text" name="naam" placeholder="Naam" /></td></tr>
<tr><td>Email:</td><td><input type="text" name="mail" placeholder="voornaam.naam" />#arteveldehs.be</td></tr>
<tr><td>Opleiding:<span class="required">*</span></td><td colspan="2">
<select name="opleiding">
<option value="0">Selecteer een opleiding</option>
<?php
$sql2 = "SELECT SUM(ios) as iostotal,SUM(android) as androidtotal,SUM(windows) as windowstotal FROM reservaties WHERE '$datum' = datum";
$check2 = mysqli_query($link,$sql2) or die(mysql_error());
while ($free2 = mysqli_fetch_array($check2)) {
$iosall = 16;
$andall = 18;
$winall = 20;
$ios2 = $iosall - $free2['iostotal'];
$android2 = $andall - $free2['androidtotal'];
$windows2 = $winall - $free2['windowstotal'];
}
$opleidingen = "SELECT * FROM opleidingen";
$values = mysqli_query($link,$opleidingen) or die(mysql_error());
while ($row = mysqli_fetch_array($values)) {
$oplid = $row['oplid'];$opleiding = $row['opleiding'];
echo "<option value=\"".$oplid."\">".$opleiding."</option>";
}
?>
</select>
</td></tr>
<tr><td>Aantal iOS</td><td><input type="text" name="ios" placeholder="<?= $ios2;?>" ><span class="max">(maximum <?= $ios2;?> beschikbaar)</span></td></tr>
<tr><td>Aantal Android</td><td><input type="text" name="android" placeholder="<?= $android2;?>" ><span class="max">(maximum <?= $android2;?> beschikbaar)</span></td></tr>
<tr><td>Aantal Windows</td><td><input type="text" name="windows" placeholder="<?= $windows2;?>" ><span class="max">(maximum <?= $windows2;?> beschikbaar)</span></td></tr>
<tr><td>Opmerking:</td><td colspan="2"><textarea maxlength="512" rows="5" cols="50" name="opmerking" placeholder="Bv. Tijdstip van oppikken/terugbrengen - vraag aan de mediatheek - ..." ></textarea></td></tr></table>
<input type="checkbox" name="terms" value="on" /> Hiermee verklaar ik me akkoord met het <a target="_blank" href="reglement.php">reglement</a> dat geldt voor het gebruik van deze tablets.<span class="required">*</span>
<p><input type="submit" name="submit" value="Reserveer"/></p>
</form>
<?php }
?>
DATABASE reservaties
resid int(9) PRIMARY KEY
oplid int(9)
naam varchar(55) latin1_swedish_ci
datum date
ios varchar(3)
android varchar(3)
windows varchar(3)
emailname
opmerking varchar(512) latin1_swedish_ci
As per OP's original posted question
You have a missing quote for your query:
$query = "INSERT INTO base(mail,name) VALUES ('$maila','$name') ;
// right there --^
do:
$query = "INSERT INTO base(mail,name) VALUES ('$maila','$name')";
Using error reporting would have helped shown the error http://www.php.net/mysqli_error
Since no error was thrown (at you), this tells me that you are not using error reporting.
if (!mysqli_query($link,$query))
{
die('Error: ' . mysqli_error($link));
}
These or die(mysql_error()) need to be changed to or die(mysqli_error()) since mysql_* and mysqli_* based functions do not mix with each other.
Try this, You have missed to close "
$query = "INSERT INTO `base` (`mail`,`name`) VALUES ('$maila','$name')";
you have missed end " in your query string.
replace this line:
$query = "INSERT INTO base(mail,name) VALUES ('$maila','$name');
by this:
$query = "INSERT INTO base(mail,name) VALUES ('$maila','$name')";

Categories