1.11M Members

Latest Posts in PHP

Re: in PHP

What type of SMTPSecure you add into the email prefix? And the port number would need to be matched with the SMTPSecure type (25 is not really what gmail currently used to authenticate because it could be blocked). The port number for SSL is 465 and TSL is 587. Also, does the email account require 2-step authentications? Are you sure that the password is correct? It looks like the failure is right at authenticating the sender account. You could check this link for further info on how to email on PHP.

in PHP

Dear all,

I have done a website that I need to integrate emailing functionality.
I have done this before, and it worked perfectly, and still does.
However, when I attempted to use the same code to test the emailing functionality for the new site, I get an error message as below;

"Mailer Error: The following From address failed: recipient@gmail.com : Called Mail() without being connected"

Here is the code that I am using.

    $mail = new PHPMailer();
    $mail->Host = "localhost";
    $mail->From = $_POST['email'];
    $mail->FromName  =  $_POST['sender_name'];
    $email_add = $_POST['email'];
    $phone_number = $_POST['phone_number'];
    $name = $_POST['name'];
    $subject = $_POST['subject'];
    $msg = $_POST['email_message']."\n".$name.".";


    $mail->SMTPAuth = "true";
    $mail->Username = "my_gmail@gmail.com";
    $mail->Password =  "my_gmail_password";
    $mail->Port  =  "25";

    $mail->name = $name;
    $mail->phone_number = $phone_number;
    $mail->Subject = $subject;
    $mail->Body = $msg;
    $mail->WordWrap = 50;

echo "<script language='javascript'>
alert('Your email was NOT sent! Please try again.')
    echo "<script language='javascript'>
alert('Mail Successfully sent! Thank you for contacting us.')

//  $email = $_REQUEST['email'] ;
//  $message = $_REQUEST['message'] ;


I added the line;

echo 'Mailer Error: ' . $mail->ErrorInfo;

to identify the problem, and it shows me the error mentioned above.
I dunno what I am doing wrong since the same code is working fine elsewhere.

Re: in PHP

Before asking if it is possible, perhaps you should ask why you're doing it. These are not common requests, so that should tell you that it's probably the wrong approach. Incrementing a character-based field is certainly possible, but again, why would you want to do it? If you need to create a custom 'id' - purely 'visual' for the use of screen or reports, then you can store an id as an autoincrement and create conversion functions. However, what a palaver.

An autoincrement is used to give a table row "uniqueness" and provide a "hook" in order to relate that row of data to another set of data in another table, why would you want two "uniquenesses"? BTW - there are other uses for autoincs, but those are the ones that usually come to the fore.

Some table types allow setting an autoinc field to a secondary field within a compound index (see the link from pritaeas), and this may be useful for you. BUT not all table types allow this - InnoDB, the new default type, does not AFAIK.

Re: in PHP

I'm not sure that this is possible. But why not redirect first and then force the download?

Re: in PHP
  1. Because, you cannot increment a character.
  2. There can only be one auto increment column.
in PHP

Hey guys
I have some problem for counting (products) in cart dynamically with ajax when clicking on (add to cart) "button":
for example: consider that there's only one product in cart, user clicks (add to cart) "button", show div with message added plus count products in cart dynmically

Here's my php code (counter of products in cart):

<span class="products-in-cart">
( <?= isset($cart_id) ? $cartObj->countProductsInCartByCartId($cart_id) : "0" ?> )

and here's jquery code (ajax):

$(document).ready(function () {
    var addToCart = $('input[name=addToCart]');
    addToCart.on('click', function () {
    var productId = $(this).parent().find('input[name=productId]').val();
    var data = {
    productId: productId,
    addToCart: true
    var url = "addToCart.php";
    $.post(url, data, function () {
    var div = $("<div></div>");
    div.addClass('addedToCart'); $("body").append(div.hide().text("added").fadeIn(500).delay(1000).fadeOut(500));
    var speed = 500;
    $("body").append(div.css('display','none').text("added").css({'display':'block', 'opacity':'0'}).animate({'opacity':'1'}, speed).delay(1000).animate({'opacity':'0'}, speed,function(){


    $('form.cartOperations').submit(function () {
    return false;
in PHP

i have a website which i sell my books on, now i want to redirect my users to the home page (index.html) when they click the download link and the file starts to download.

Will really appreciate the help and support thanks.

this is the php code i wrote

$fakeFileName= "e-book_mobi.mobi";
$realFileName = "e-book_mobi.mobi";

$file = "book/". $realFileName;
$fp = fopen($file, 'rb');

header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$fakeFileName");
header("Content-Length: " . filesize($file));

this is the download link

<li><a href="mobi_download.php?id=<?php echo $_GET['id']; ?>" target="_blank"/><b>.mobi</b></a></li>
in PHP

1) why autoincrement is not working for varchar in phpmyadmin?
2)can we set two autoincrement in a table in phpmyadmin?

Solved in PHP

hey guys. i have this table that lists contacts that are stored in database. the data is selected from 2 tables using join which i have already got working:

FROM contact1 c
LEFT JOIN spouse1 s
ON c.contact_id = s.my_spouse

what im having trouble with is selecting another column based on data in one column. okay so this is my contact1 table:


column 'othersalutation' i just added it in today as requested by my supervisor. 'salutation' is only for one salutation like 'Mr.' or 'Mrs.' etc(its a dropdown in the html form) while 'othersalutation' allows user to insert multiple salutations as they want(textbox in html form)(coz just having one isn't enough) like 'Dato Sri Haji'; Dato Sri and Haji being 2 salutations.

so what i want to do is modify the above query like a conditional select like

select othersalutation if salutation = 'Other' else select salutation

something like that. there are alot of these kinda questions on the internet but coz mine is using a join as well to display data im not so sure how to put that into the query.


Re: in PHP

oh.sorry..its like this sir
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DESCLIMIT 0,5' at line 1...

Re: in PHP

Presuming this is the connect-mysql.php


DEFINE ('DB_HOST', 'ip');
DEFINE ('DB_USER', 'user');
DEFINE ('DB_PSWD', 'pass');
DEFINE ('DB_NAME', 'dbname');

$dbcon = mysqli_connect(DB_HOST, DB_USER, DB_PSWD, DB_NAME);

if (!$dbcon) {
    die('error connecting to database');


and this is the samepage.php

<form method="post" action="samepage.php">

<select size="1" name="whatever">

$sql3="SELECT * FROM table";
$results = mysqli_query($dbcon,$sql3) or die('123');

while($row = mysqli_fetch_array($results)) {

      echo '<option value="'.$row['rowname'].'">'.htmlspecialchars($row['rowname']).'</option>'; 
<input type="submit" value="Insert Info"></p>
<input type="hidden" name="submitted" value="true" />


if (isset($_POST['submitted'])) {

    $whatever= mysqli_real_escape_string($dbcon, $_POST['whatever']);

    $sqlinsert = "INSERT INTO table2 (whatever) VALUES ('$whatever')";

    if (!mysqli_query($dbcon, $sqlinsert)) {
        die('error inserting new record');
        }//end of nested if statement
$newrecord = "Entry Successful";

} //end of main if

echo $newrecord // New record added statement added at the top

you can do that with multiple drop menus. UPDATING is slightly a different story but this would at least let you insert new records.

Re: in PHP

I think this was intimated earlier:

Are there any quotes in the dob value?

This is happening because you are using php to spit out all your html. This can be easily avoided if you're a bit more judicious with it, e.g.

<sometag><?php echo $somevalue;?></sometag>

or on modern versions of php:

<sometag><?= $somevalue ?></sometag>

Instead of

echo "<sometag>$somevalue</sometag>";

Minimise the amount of html you create via php, it rarely plays well.

PHP Tag Cloud