hellonoko Posted April 23, 2007 Share Posted April 23, 2007 Here is my code again. Not sure what im missing. But it is not inserting. No errors either... Thanks. <?php include 'dbconnect.php'; $title = $HTTP_GET_VARS[title]; $description = $HTTP_GET_VARS[description]; $media = $HTTP_GET_VARS[media]; $price = $HTTP_GET_VARS[price]; $imagelink = $HTTP_GET_VARS[image_link]; $action = $HTTP_GET_VARS[action]; echo $title; echo "<br>"; echo $description; echo "<br>"; echo $media; echo "<br>"; echo $price; echo "<br>"; echo $image_link; echo "<br>"; if ($action == "Add") { $query = "INSERT INTO gallery (title, description, media, price, image) VALUES ($title, $description, $media, $price, '.jpg')" or die (mysql_error('Error, insert query failed')); $result = mysql_query($query); } ?> <form name="add_gallery_item" method="get" action="add_gallery_item.php"> <label> title: <input type="text" name="title" id="title"> </label> <p>description: <label> <input type="text" name="description" id="description"> </label> </p> <p>media: <label> <input type="text" name="media" id="media"> </label> </p> <p>price: <label> <input type="text" name="price" id="price"> </label> </p> <p>imagelink: <label> <select name="image_link" id="image_link"> </select> </label> </p> <p> <label> <input type="submit" name="action" id="add_item" value="Add"> </label> </p> </form> Link to comment https://forums.phpfreaks.com/topic/48197-solved-insert-query-not-inserting/ Share on other sites More sharing options...
GeXus Posted April 23, 2007 Share Posted April 23, 2007 Remove the "$result =" - so it's just mysql_query($query) Link to comment https://forums.phpfreaks.com/topic/48197-solved-insert-query-not-inserting/#findComment-235616 Share on other sites More sharing options...
Psycho Posted April 23, 2007 Share Posted April 23, 2007 That's not the problem. The problem is that you are putting the OR DIE part when you are defining the query variable. The OR DIE needs to follow the running of the query: $query = "INSERT INTO gallery (title, description, media, price, image) VALUES ($title, $description, $media, $price, '.jpg')"; $result = mysql_query($query) or die (mysql_error()); Link to comment https://forums.phpfreaks.com/topic/48197-solved-insert-query-not-inserting/#findComment-235621 Share on other sites More sharing options...
AndyB Posted April 23, 2007 Share Posted April 23, 2007 Remove the "$result =" - so it's just mysql_query($query) Nothing wrong with that at all. Change: $query = "INSERT INTO gallery (title, description, media, price, image) VALUES ($title, $description, $media, $price, '.jpg')" or die (mysql_error('Error, insert query failed')); $result = mysql_query($query); To: $query = "INSERT INTO gallery (title, description, media, price, image) VALUES ($title, $description, $media, $price, '.jpg')"; $result = mysql_query($query) or die ("Error: ". mysql_error(). " with query ". $query); The .jpg looks a little suspect. Not sure what you're trying for. Link to comment https://forums.phpfreaks.com/topic/48197-solved-insert-query-not-inserting/#findComment-235622 Share on other sites More sharing options...
trq Posted April 23, 2007 Share Posted April 23, 2007 You dont really have much in the way of error handling and your use of mysql_error is invalid. Lots of errors in this code really, try.... <?php include 'dbconnect.php'; // these will also generate warnings if they don't exist, better to use... // $title = $_GET['title'] ? mysql_real_escape_string($_GET['title']) : ''; $title = mysql_real_escape_string($_GET['title']); $description = mysql_real_escape_string($_GET['description']); $media = mysql_real_escape_string($_GET['media']); $price = mysql_real_escape_string($_GET['price']); $imagelink = mysql_real_escape_string($_GET['image_link']); $action = mysql_real_escape_string($_GET['action']); echo $title; echo "<br>"; echo $description; echo "<br>"; echo $media; echo "<br>"; echo $price; echo "<br>"; echo $image_link; echo "<br>"; if ($action == "Add") { $query = "INSERT INTO gallery (title, description, media, price, image) VALUES ('$title', '$description', '$media', '$price', '.jpg')"; if ($result = mysql_query($query)) { echo "success."; } else { echo "Failed" . mysql_error(); } } ?> Link to comment https://forums.phpfreaks.com/topic/48197-solved-insert-query-not-inserting/#findComment-235623 Share on other sites More sharing options...
hellonoko Posted April 23, 2007 Author Share Posted April 23, 2007 The .JPG is just filler for a where a imagine link will go later. Got it working. Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/48197-solved-insert-query-not-inserting/#findComment-235627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.