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
https://forums.phpfreaks.com/topic/281478-why-isnt-this-working/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.