0

Below is a form that is supposed to submit information into a MySQL database.

The submission form below and its corresponding queries file aren't working. I fill out all the fields and I click submit, and I get no error message.

On submit2a.php, I have mysql_connect() or die(mysql_error()); and mysql_select_db() or die(mysql_error()); and I don't get an error, so I assume it's connecting to MySQL.

But when I check the MySQL database, the new information I'm adding is not there.

Does anyone see any glaring mistakes in the code below?

Thanks in advance,

John

The form:

echo '<form enctype="multipart/form-data" action="http://www...com/.../submit2a.php" method="post"> 
    <input type="hidden" value="'.$_SESSION['loginid'].'" name="uid">  

    <div class="submissiontitle"><label for="title">Blog Post Title:</label></div> 
    <div class="submissionfield"><input class="checkMax3" name="title" type="title" id="title" maxlength="80"></div>  


    <div class="texttitle"><label for="text1">Blog Post Text 1:</label></div> 
    <div class="textfield"><textarea class="checkMax" name="text1" type="comment" id="text1" maxlength="10000"></textarea></div>

    <div class="imagetitle"><label for="image1">Image 1:</label></div> 
    <div class="imagefield"><input type="file" name="image1" /></div>   

    <div class="hyperlinktitle"><label for="url1">Hyperlink 1:</label></div> 
    <div class="hyperlinkfield "><input name="url1" type="title" id="url1" maxlength="200"></div>



    <div class="texttitle2"><label for="text2">Blog Post Text 2:</label></div> 
    <div class="textfield2"><textarea class="checkMax" name="text2" type="comment" id="text2" maxlength="10000"></textarea></div>

    <div class="imagetitle2"><label for="image2">Image 2:</label></div> 
    <div class="imagefield2"><input type="file" name="image2" /></div>  

    <div class="hyperlinktitle2"><label for="url2">Hyperlink 2:</label></div> 
    <div class="hyperlinkfield2"><input name="url2" type="text" id="url2" maxlength="200"></div>



    <div class="texttitle3"><label for="text3">Blog Post Text 3:</label></div> 
    <div class="textfield3"><textarea class="checkMax" name="text3" type="comment" id="text3" maxlength="10000"></textarea></div>

    <div class="imagetitle3"><label for="image3">Image 3:</label></div> 
    <div class="imagefield3"><input type="file" name="image3" /></div>  

    <div class="hyperlinktitle3"><label for="url3">Hyperlink 3:</label></div> 
    <div class="hyperlinkfield3"><input name="url3" type="text" id="url3" maxlength="200"></div>



    <div class="texttitle4"><label for="text4">Blog Post Text 4:</label></div> 
    <div class="textfield4"><textarea class="checkMax" name="text4" type="comment" id="text4" maxlength="10000"></textarea></div>

    <div class="imagetitle4"><label for="image4">Image 4:</label></div> 
    <div class="imagefield4"><input type="file" name="image4" /></div>  

    <div class="hyperlinktitle4"><label for="url4">Hyperlink 4:</label></div> 
    <div class="hyperlinkfield4"><input name="url4" type="text" id="url4" maxlength="200"></div>





    <div class="submissionbutton"><input name="submit" type="submit" value="Submit"></div> 
</form>
';

The queries on submit2a.php:

$remove_array = array('http://www.', 'http://', 'https://', 'https://www.', 'www.');

$uid = $_POST['uid'];

$title = $_POST['title'];

$text1 = $_POST['text1'];

$image1 = $_POST['image1'];

$image1 = $_FILES['image1'];

$url1 = $_POST['url1'];



$text2 = $_POST['text2'];

$image2 = $_POST['image2'];

$image2 = $_FILES['image2'];

$url2 = $_POST['url2'];



$text3 = $_POST['text3'];

$image3 = $_POST['image3'];

$image3 = $_FILES['image3'];

$url3 = $_POST['url3'];



$text4 = $_POST['text4'];

$image4 = $_POST['image4'];

$image4 = $_FILES['image4'];

$url4 = $_POST['url4'];







$cleanurl1 = str_replace($remove_array, "", $_POST['url1']);
$cleanurl1 = strtolower($cleanurl1);
$cleanurl1 = preg_replace('/\/$/','',$cleanurl1);
$cleanurl1 = stripslashes($cleanurl1);
$cleanurl1 = mysql_real_escape_string(trim($cleanurl1));

$cleanurl2 = str_replace($remove_array, "", $_POST['url2']);
$cleanurl2 = strtolower($cleanurl2);
$cleanurl2 = preg_replace('/\/$/','',$cleanurl2);
$cleanurl2 = stripslashes($cleanurl2);
$cleanurl2 = mysql_real_escape_string(trim($cleanurl2));


$cleanurl3 = str_replace($remove_array, "", $_POST['url3']);
$cleanurl3 = strtolower($cleanurl3);
$cleanurl3 = preg_replace('/\/$/','',$cleanurl3);
$cleanurl3 = stripslashes($cleanurl3);
$cleanurl3 = mysql_real_escape_string(trim($cleanurl3));

$cleanurl4 = str_replace($remove_array, "", $_POST['url4']);
$cleanurl4 = strtolower($cleanurl4);
$cleanurl4 = preg_replace('/\/$/','',$cleanurl4);
$cleanurl4 = stripslashes($cleanurl4);
$cleanurl4 = mysql_real_escape_string(trim($cleanurl4));



//$url = $_POST['url'];

//$subcheck = (isset($_POST['subcheck'])) ? 1 : 0;
$title = mysql_real_escape_string($title);
$title = stripslashes($title);
$slug = str_replace(' ', '-', $title);




echo '-'.$site1.'-';



$site1 = 'http://' . $cleanurl1;
$site2 = 'http://' . $cleanurl2;
$site3 = 'http://' . $cleanurl3;
$site4 = 'http://' . $cleanurl4;

$displayurl = parse_url($site1, PHP_URL_HOST);




    $query = sprintf("INSERT INTO submission VALUES (NULL, '$title', '$text1', '$text2', '$text3', '$text4', '$site1', '$site2', '$site3', '$site4', NULL)")or die(mysql_error());


mysql_query($query, $db);

        $id = (int) mysql_insert_id($db);   

$submissionid = $id;        



$info1 = getImageSize($image1['tmp_name']);

$queryimage1 = sprintf(
            "insert into images (NULL, submissionid, filename, mime_type, file_size, file_data)
                values ('%s', '%s', '%s', %d, '%s')",
            $submissionid,
            mysql_real_escape_string($image1['name']),
            mysql_real_escape_string($info1['mime']),
            $image1['size'],
            mysql_real_escape_string(
                file_get_contents($image1['tmp_name'])
            )
        )or die(mysql_error());





$info2 = getImageSize($image2['tmp_name']);

$queryimage2 = sprintf(
            "insert into images (NULL, ubmissionid, filename, mime_type, file_size, file_data)
                values ('%s', '%s', '%s', %d, '%s')",
            $submissionid,
            mysql_real_escape_string($image2['name']),
            mysql_real_escape_string($info2['mime']),
            $image2['size'],
            mysql_real_escape_string(
                file_get_contents($image2['tmp_name'])
            )
        )or die(mysql_error());     




 $info3 = getImageSize($image3['tmp_name']);

$queryimage3 = sprintf(
            "insert into images (NULL, submissionid, filename, mime_type, file_size, file_data)
                values ('%s', '%s', '%s', %d, '%s')",
            $submissionid,
            mysql_real_escape_string($image3['name']),
            mysql_real_escape_string($info3['mime']),
            $image3['size'],
            mysql_real_escape_string(
                file_get_contents($image3['tmp_name'])
            )
        )or die(mysql_error());



 $info4 = getImageSize($image4['tmp_name']);

$queryimage4 = sprintf(
            "insert into images (NULL, submissionid, filename, mime_type, file_size, file_data)
                values ('%s', '%s', '%s', %d, '%s')",
            $submissionid,
            mysql_real_escape_string($image4['name']),
            mysql_real_escape_string($info4['mime']),
            $image4['size'],
            mysql_real_escape_string(
                file_get_contents($image4['tmp_name'])
            )
        )or die(mysql_error());     










header("Location: http://www...com/.../");
exit(); 
1
  • First off: try naming your vars better and secondly, cleaner code is manageable code! That being said, if you have output buffering, header("Location: ") will work and you won't see any errors. You sure you ain't getting any errors from the script ? Commented Apr 2, 2011 at 2:26

2 Answers 2

1

At the first instance it seems to me you have not called "mysql_query" on most of your statements. i.e $queryimage1, queryimage2, ......

Current Statement:

$queryimage1 = sprintf(
            "insert into images (NULL, submissionid, filename, mime_type, file_size, file_data)
                values ('%s', '%s', '%s', %d, '%s')",
            $submissionid,
            mysql_real_escape_string($image1['name']),
            mysql_real_escape_string($info1['mime']),
            $image1['size'],
            mysql_real_escape_string(
                file_get_contents($image1['tmp_name'])
            )
        )or die(mysql_error());

Would be:

$queryimage1 = mysql_query(sprintf(
            "insert into images (NULL, submissionid, filename, mime_type, file_size, file_data)
                values ('%s', '%s', '%s', %d, '%s')",
            $submissionid,
            mysql_real_escape_string($image1['name']),
            mysql_real_escape_string($info1['mime']),
            $image1['size'],
            mysql_real_escape_string(
                file_get_contents($image1['tmp_name'])
            )
        ))or die(mysql_error());
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks... this helps a lot. It seems to guide me in the right direction.
0

you should use MYSQLI or MYSQLI_PREPARE !

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.