0

I'm making a website. I want it so that I can put records into the database via my website. So first I need to select the id from which record I want to change. Then I want to put the values of the selected id into a variable. The I want to put the variable into a form value.
I'm trying to make something similar to phpmyadmin. If you click on the pencil you go to a form were everything is complete and you can just change the things you want to change and save it into the database.
wijzigen.php:

<form id="form1" name="form1" method="post" action="set_wijziging.php">
  <h1>Selecteer het vuurwerkid van het product dat u wilt wijzigen</h1>
  <p>Vuurwerkid <br>
    <input  type="text" name="vuurwerkid" id="vuurwerkid" />

  <input type="submit" name="wijzigen" id="wijzigen" value="wijzigen"/>
</form>

and here is the part were I put what I typed in in the form into a variable.

<?php
$vuurwerkid=$_POST["vuurwerkid"];
?>

Then I'm trying to make a query wich only selects the things were vuurwerkid='$vuurwerkid' So here I try to put the results of the query into a variable. But this doesn't seem to work.
set_wijziging.php:

 <?php
                include("connect.php");
            $vuurwerkid=$_POST["vuurwerkid"];

        $query = "SELECT * FROM vuurwerk_info WERE vuurwerkid='$vuurwerkid'";
        $resultaat = MySQL_query($query);
    while ($row = MySQL_fetch_array($resultaat))
    {
    $vuurwerkid="$row["vuurwerkid"]";
    $naam=$row["naam"];
    $prijs=$row["prijs"];
    $soort=$row["soort"]; 
    $cat_vuurwerk=$row["cat_vuurwerk"]; 
    $aantal=$row["aantal"]; 


}
?>

I'm just started learning PHP

TKSS3
  • 3
  • 2
  • Can you read the post variable correctly – shamon shamsudeen Oct 25 '14 at 08:29
  • If you're just starting to learn PHP, please be wise and look into PDO immediately and discard the mysql_* functions. They will be deprecated soon, and if you're new and learning you'd better start learning the 'new' way. – stUrb Oct 25 '14 at 08:34
  • Little Bobby Tables -- http://bobby-tables.com/ – Ali Oct 25 '14 at 08:39

2 Answers2

0

You should change your $query to

 $query = "SELECT * FROM vuurwerk_info WHERE vuurwerkid='$vuurwerkid'"; 

Also try to echo your query to see if it's correct. Finally as others pointed out you should stop using mysql_* and switch to msqli or PDO.

geoandri
  • 2,360
  • 2
  • 15
  • 28
  • If it's a string column it needs the quotes. If it's an integer, MySQL will convert the string automatically. – Barmar Oct 25 '14 at 08:35
  • @Barmar no, it doesn't. The variable will be interpreted as the string '$vuurwerkid' with single quotes. Check this http://stackoverflow.com/questions/10512452/php-using-a-variable-inside-a-double-quotes – geoandri Oct 25 '14 at 08:42
  • I don't see anythiing there that supports your claim. PHP never adds extra characters when it interpolates a variable into a string. – Barmar Oct 25 '14 at 08:45
  • @Ali I was just answering his question on the exact problem. I didn't evaluate his code in terms of security. – geoandri Oct 25 '14 at 08:45
0

Your where spelling is wrong in your query

Try this

$query = "SELECT * FROM vuurwerk_info WHERE vuurwerkid='$vuurwerkid'";

I miss that last time Change this line as well

$vuurwerkid="$row["vuurwerkid"]";

To this

`$vuurwerkid=$row["vuurwerkid"];

//Remove the Double queite. As its variable not string`

although function name are case-incensitive. But change theese lines as well

chnage this

$resultaat = MySQL_query($query);
    while ($row = MySQL_fetch_array($resultaat))

To this

$resultaat = mysql_query($query);
        while ($row = mysql_fetch_array($resultaat))

Note I change nothing in the below line. I just used the small letter to right those function

Please learn MYSQLI_ OR PDO

As mysql function are depriciated.

arif_suhail_123
  • 2,509
  • 2
  • 12
  • 16