Page 1 of 1

Why is my INSERT not working?

Posted: Tue Nov 15, 2011 4:17 pm
by Linkjuice57
Hi,

I've been struggling on this for a couple of hours now, why is my INSERT not working? I've done similair things before, and I figure i'm missing something pretty obvious. Can someone point it out?

add.php
<?php include '../includes/connect.php'; ?>



<?php
if($_POST['coupon']){
		
		$coupon = $_POST['coupon'];
		$waarde = $_POST['waarde'];
		$datum = $_POST['datum'];
				
	$insert = "INSERT INTO adwords (coupon, waarde, datum) VALUES ('$coupon', '$waarde', '$datum ')" or die(mysql_error());
	echo "Succes. <br />";
	echo "<a href=\"index.php\">Terug</a>";

							}							
?>
index.php
<?php include 'add.php'; ?>
<!DOCTYPE HTML> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="nl"> 
<title>/Adwords/</title>
<style>
h1, h2 { margin:0px; padding:0px; }
body { margin:120px auto 0 auto; width:960px; }
label { width:100px; float:left; }
</style>
</head>

<body>

<h1>Adwords Coupon Advertentietegoed</h1>



<form action="add.php" method="post">
	<label for="coupon">Couponcode: </label><input type="text" name="coupon" /><br />
    <label for="waarde">Waarde: </label><input type="text" name="waarde" /><br />
    <label for="datum">Geldig t/m: </label><input type="text" name="datum" /><br />
    <input type="submit" name="submit" id="submit" />
</form>

<?php

$query = mysql_query("SELECT * FROM adwords") or die(mysql_error()); 


?>

<table border="1">
	<tr>
    	<td>Couponcode</td>
        <td>Waarde</td>
        <td>Geldig tot</td>
        <td> </td>
    </tr>
    
    <?php while($row = mysql_fetch_array($query)) { ?>
    
    <tr>
    	<td><?= $row['coupon']; ?></td>
        <td>€ <?= $row['waarde']; ?>,-</td>
        <td><?= $row['datum']; ?></td>
        <td><a href="">Verbruikt?</a></td>
    </tr>
    
    <? } ?>
</table>

</body>
</html>
Table is being made, and echo's stuff from the DB just fine, but I can't seem to add anything new to it.

Re: Why is my INSERT not working?

Posted: Tue Nov 15, 2011 8:37 pm
by JelvinJS7
You're storing the insert code into a variable, and not calliing it. You should either initially run the INSERT, or out the code in a variable, then run it (which isn't that helpful).
       mysql_query("INSERT INTO adwords (coupon, waarde, datum) VALUES ('$coupon', '$waarde', '$datum ')") or die(mysql_error());

Or
        $insert = "INSERT INTO adwords (coupon, waarde, datum) VALUES ('$coupon', '$waarde', '$datum ')";
        mysql_query($insert) or die(mysql_error());


Re: Why is my INSERT not working?

Posted: Wed Nov 16, 2011 12:14 pm
by Linkjuice57
Thank you very much Jelvin.

Silly me.