Jump to content

[SOLVED] script won't post to mysql


andr923

Recommended Posts

	$connect = new connector();
$caption = $_POST['caption'];
$caption = htmlentities($caption);
$img = $_POST['img'];
$by = $_POST['by'];
$by = htmlentities($by);

$insertQuery = "INSERT INTO gallery (img, caption, by) VALUES ('$img','$caption','$by')";
	if ($connect->query($insertQuery)){
		echo "<center><h4>pic added</h4></center>";
		}else{
		echo "<center><h4>pic did not get added</h4></center>";
		}
	$connect->close();

 

That is the code I'm using to try and post the image information into my gallery's database.  I mostly copied the code exactly from a similar script I use for my blog table but for some reason this won always fails to insert the query and gives me the "did not get added" message. 

 

This is the code for the form that submits the information:

 

<form name="form1" method="post" action="postpic.php">
<p>
<input name="img" type="text" value="filename (without .jpg)" size="30">
</p>
<p>
<input name="by" type="text" value="by" size="30">
</p>
<p><br>
<textarea name="caption" cols="40" rows="10">caption</textarea>
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>

 

I know it's gotta be a small thing 'cause this works for my blog script.

Link to comment
https://forums.phpfreaks.com/topic/64240-solved-script-wont-post-to-mysql/
Share on other sites

I changed all the instances of 'img' or '$img' to 'pic' and '$pic' and all the instances of 'by' and '$by' to 'author' and '$author' and I guess now it works.  So i guess maybe one of those variables is reserved by either the php or mysql system?

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.