Jump to content

Recommended Posts

Hey

I tried everything now and i just cant find what is wrong. This code should update my database, but it doesnt, plz help.

[code]
<?php
include('../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]
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
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.
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.)
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.