Jump to content

why isnt this working?


failchicken

Recommended Posts

<form action="cat.php" method="post">
Cat name: <input type="text" name="cat" />
<input type="submit" name="submit">
</form>
<?php
if (isset($_POST['submit'])){
$con = mysql_connect("localhost", "root", "pass");
if (!$con){
die("can not connect: " . mysql_error());    
}
mysql_select_db("database",$con);
$sql = "INSERT INTO gallery_category (category_id,category_name) VALUES (''',$_POST[cat]')";
mysql_query($sql,$con);
mysql_close($con);
}
?>

Link to comment
Share on other sites

@fatsol

What code are you reading? The submit button does have a name, it is "submit". The problem is the single quotes inside the query:

 

@failchicken

$sql = "INSERT INTO gallery_category (category_id,category_name) VALUES (''',$_POST[cat]')";
If you look close you see three quotes before the comma and no quote after the comma before the category value.

 

Of course, the debug message is showing nothing after the comma and only two single quotes before it, so somthing was changed before that run.

Link to comment
Share on other sites

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.