JJohnsenDK Posted January 3, 2007 Share Posted January 3, 2007 HeyI tried everything now and i just cant find what is wrong. This code should update my database, but it doesnt, plz help.[code]<?phpinclude('../config_sit00045.php');?><form method="POST" name="form1" action="<?php $_SERVER['PHP_SELF']; ?>"> <p> Nyheds overskrift:<br /> <input type="text" name="name" /> </p> <br /> <p> Nyheds tekst:<br /> input type="text" name="price" /> </p> <br /> <input type="submit" name="submit" value="Indsæt" /></form><?php if(isset($_POST['submit'])){ $_POST['name'] = strip_tags($_POST['name']); $_POST['price'] = strip_tags($_POST['price']); if (empty($_POST['name'])){ echo "<br /><br /><font color='#FF0000'>Du har ikke skrevet en Nyheds overskrift.</font>"; } if (empty($_POST['price'])){ echo "<br /><br /><font color='#FF0000'>Du har ikke skrevet en Nyheds tekst.</font>"; } else{ if (isset($_POST['submit'])){ if (!empty($_POST['name'])){ echo "Nyheden ".$_POST['name']." er blevet tilføjet."; } $hent = mysql_query("SELECT * FROM products"); $name = $_POST['name']; $price = $_POST['price']; $vis = mysql_query("INSERT INTO `products` SET `products_id` = NULL, `products_name` = '".$name."', `products_type = '0'`, `products_quality` = '', `products_artist = '0'`, `products_price` = '".$price."', `products_pic` = '', `products_info` = '', `products_link` = '', `products_length` = ''"); } } }}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32710-solved-why-doesnt-this-insert-into-database/ Share on other sites More sharing options...
ober Posted January 3, 2007 Share Posted January 3, 2007 That's because you're using UPDATE syntax in a INSERT statement. INSERT statements look like this:[code]INSERT INTO tablexyz (column1, column2, column3) VALUES ('1', '2', '3')[/code] Quote Link to comment https://forums.phpfreaks.com/topic/32710-solved-why-doesnt-this-insert-into-database/#findComment-152241 Share on other sites More sharing options...
craygo Posted January 3, 2007 Share Posted January 3, 2007 I use the SET function to insert data into my database and it works fine. Should I be doing this????Might want to add some debugging so you can see what's going on. Also why are you querying the database if you are inserting something into it. What you should be doing is querying the database to see if the item already exists then insert it if it does not.[code]$insert = "INSERT INTO `products` SET `products_id` = NULL, `products_name` = '".$name."', `products_type = '0'`, `products_quality` = '', `products_artist = '0'`, `products_price` = '".$price."', `products_pic` = '', `products_info` = '', `products_link` = '', `products_length` = ''";$vis = mysql_query($insert) or die("Error with your query<br>SQL:".$sql."<br>Error: ".mysql_error());[/code]Ray Quote Link to comment https://forums.phpfreaks.com/topic/32710-solved-why-doesnt-this-insert-into-database/#findComment-152246 Share on other sites More sharing options...
ober Posted January 3, 2007 Share Posted January 3, 2007 I'm not sure WHY you would want to do that... so I'd suggest using the correct syntax. Maybe MySQL or whatever DBMS you're using allows that, but to follow the SQL standards, I think you'd want to use the right syntax for the right function. Quote Link to comment https://forums.phpfreaks.com/topic/32710-solved-why-doesnt-this-insert-into-database/#findComment-152248 Share on other sites More sharing options...
JJohnsenDK Posted January 3, 2007 Author Share Posted January 3, 2007 Right i will follow the standards from now on :)Both of your replys helped alot, so thanks to both of you :D Quote Link to comment https://forums.phpfreaks.com/topic/32710-solved-why-doesnt-this-insert-into-database/#findComment-152256 Share on other sites More sharing options...
ober Posted January 3, 2007 Share Posted January 3, 2007 Don't forget to mark the topic as solved if it is solved (lower left above the quick reply). Quote Link to comment https://forums.phpfreaks.com/topic/32710-solved-why-doesnt-this-insert-into-database/#findComment-152257 Share on other sites More sharing options...
PFMaBiSmAd Posted January 3, 2007 Share Posted January 3, 2007 I have a question, does [quote]This code should update my database[/quote] mean you are trying to update an existing recored (which is [b]not[/b] what your query is attempting) or are you trying to insert a new record (which [b]is[/b] what your query is attempting)?The INSERT ... SET syntax is valid for MySQL.craygo's suggestion for error checking and reporting will probably find why the query is not working (unless the server and database is being connected/selected in config_sit00045.php, there does not appear to be any code doing this.) Quote Link to comment https://forums.phpfreaks.com/topic/32710-solved-why-doesnt-this-insert-into-database/#findComment-152258 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.