Forum Moderators: coopster

Message Too Old, No Replies

my php script isn't adding my posting data to mysql

script that i have created to add a mailer template to my db

         

riggerz29

12:52 pm on Jan 6, 2010 (gmt 0)

10+ Year Member



Hi i have a script that ive made to upload a mailing template to my database, the problem im having is when i submit the form it nothing happens well the page displays correctly but no information is posted to my database

Here is my code any help would be greatly appriciated

$target = "../Assets/newsletter_attach/";
$target = $target . basename( $_FILES['attach']['name']);

if (isset ($_POST['name']))
{//1
$name = $_POST['name'];
$body = $_POST['body'];
$attach = ($_FILES['attach']['name']);

//$name = stripslashes($name);
//$body = stripslashes($body);

//$nameCHecker = mysqli_real_escape_string($myConnection, $name);
//$nameCHecker = eregi_replace("`", "", $nameCHecker);

$sql_name_check = mysqli_query($myConnection,"SELECT newletter_name FROM newsletters WHERE newletter_name='$name'");
$name_check = mysqli_num_rows($sql_name_check);

if ((!$name) ¦¦ (!$body) ¦¦ (!$attach))
{
$msg = "You have not entered the following information:<br />";

if(!$name){
$msg .= "* Please enter the name of your mailer<br />";
}
if(!$body) {
$msg .= "* Please enter the body for your mailer<br />";
}
if(!$attach) {
$msg .= "* Please attach an image for your mailer<br />";
}
else if($name_check > 0){
$msg = "The name for your emailer already exists, Please change emailer name &amp; try again.";
}
else {

$sql = mysqli_query($myConnection,"INSERT INTO newsletters (newletter_name, body, attach) VALUES ('$name', '$body', '$attach')") or die (mysqli_error($myConnection));

$movefile = (move_uploaded_file($_FILES['attach']['tmp_name'], $target));

$msg = "Your new emailer &quot; $name &quot; has been uploaded, you can now select this mailer to send to users";

}

}
}

?>

andrewsmd

8:29 pm on Jan 6, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the page displays fine but nothing is getting inserted into your database, then check your sql insert statement. First off I can see you don't have a ; on the end. But try this
$sql = mysqli_query($myConnection,"INSERT INTO newsletters (newletter_name, body, attach) VALUES ('$name', '$body', '$attach');") or die
echo("INSERT INTO newsletters (newletter_name, body, attach) VALUES ('$name', '$body', '$attach');");

Insert that echo query straight into a mysql shell and see if it returns an error.
(mysqli_error($myConnection));

riggerz29

12:20 pm on Jan 7, 2010 (gmt 0)

10+ Year Member



thanks for your reply andrewsmd ive fixed the problem now i had one of the curly brackets in the wrong place, i original tried adding ; where you said but i had an error saying that there was an unexpected ";"

andrewsmd

2:59 pm on Jan 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yea, I never am sure on if you need the ; or not. Some mysql packages require it and some don't. Whenever you have problems where your php page is loading, but it is not doing what it should to the database, always echo your sql query and paste it into a mysql shell. It will surprise you how many times your sql syntax is wrong and that is what is fouling you up. Just a tip from someone who has been doing this for a while, happy hunting :).

riggerz29

11:18 pm on Jan 7, 2010 (gmt 0)

10+ Year Member



thanks for the tip andrewsmd i really appericiate it :)