Jump to content
Larry Ullman's Book Forums

Recommended Posts

This codes works on local server(XAMPP) but does not seems to work on live server. And I can't really figure out what the problem is since there no error is output in the errorlog. In the script, I tried to use the--pre--tag but also nothing gets displayed

 

<?php session_start();?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Testimony</title>
</head>
<body>
<?php
try {
$linkas = 2;
require_once 'db/DBConnect.php';
$errors = [];
$good = true;
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['testimony'])):
$testimony = /*filter_input(INPUT_POST, 'testimony', FILTER_SANITIZE_STRING)*/$_POST['testimony'];
echo $testimony;
if (strlen($testimony) < 20):
//report error and do not go
$errors[] = 'It has to be more than 20 characters' . '<br>';
$good = false;
else:
echo $testimony;
$good = true;
if ($good):
$insertTestimony = 'INSERT INTO testimony(content, j_member_id) ';
$insertTestimony .= 'VALUES (:testimony, :user_id)';
$insert = $conn1->prepare($insertTestimony);
$insert->bindValue(':testimony', $testimony, PDO::PARAM_STR);
$insert->bindValue(':user_id', $linkas, PDO::PARAM_INT);
$insert->execute();
if ($insert->rowCount() == 1):
//success message
//$_SESSION['msg'] = 'Thanks for the testimony';
header('Location: index.php');
else:
//fail message
echo 'Something is wrong, please resubmit';
endif;
endif;
endif;
endif;
} catch (Exception $e) {
echo 'Database error: ' . $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine();
}
?>
<section class="">
<article>
<form action="" method="post" id="testimony" accept-charset="utf-8">
<fieldset>
<legend>Your testimony</legend>
<label for="testimony"></label>
<textarea id="testimony" name="testimony" maxlength="300"><?php
if (isset($_POST['testimony'])):
echo htmlspecialchars($testimony);
endif;
?></textarea>
</fieldset>
<input type="submit" name="testify" id="testify" value="Testify">
</form>
</article>
</section>
</body>
</html>

 

And this is the database connection string which I used to connect to the database and its located inside the db folder

 

<?php

//Db connection 1
$username ="XXXXX"; // censored for SO
$password = "XXXXX"; // censored for SO
//$database = "xzelanet_180days";
//$server="localhost";
$conn1 = new PDO('mysql:host=localhost;dbname=xzeere_30days; charset=utf8', $username, $password);
$conn1->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

 

After the form submission, the form refuses to insert into the database(the form displayed but does not submit[i think the problem should be inside the code processing the form])

Share this post


Link to post
Share on other sites

Hmmm...it's most likely b/c the live server isn't configured the same way, likely not having the same extensions, I imagine. You should turn on display_errors or look at the error logs to see the actual error occurring. Knowing the actual error is the only way to debug this. 

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...