Help with a simple php problem

by 9 replies
11
OK I have a slight problem that I think can be easily fixed...
The code I am about to display is supposed to display a table filled with lead information, which it does just fine. Each lead has a select box to change the status of the lead in the db. HEREIN LIES THE PROBLEM.
I do not know how to tell my sql query which lead to update... The leadID is supposed to be the lead to change but I dont know how to tell my sql that the action being taken is supposed to be done to this specific lead... Here is the code:



<?

function ticket_connect() {
$db_host = "localhost";
$db_user = "notgonnashowuthis";
$db_password ="notgonnashowuthis";
$db_name = "notgonnashowuthis";
//create database connection
$connection = @mysql_connect($db_host,$db_user,$db_password);
//if there is no connection then display a message letting the user know.
if($connection) {
@mysql_select_db($db_name, $connection);
}
else{
echo "ERROR!! Could not connect to the database at this time, we are sorry for the inconvenience. Please try again later.";
}
} // end function db_connect()

function changestatus($leadID,$status) {
ticket_connect();
$sql = mysql_query('UPDATE mynewci_ticket SET lead_status="$newstatus" WHERE ticketID="$lead2change"') or die(mysql_error());
}
$selstatus = "<select onchange='changestatus()'><option value='Renter Keep'>Renter Keep<option value='Renter Reject'>Renter Reject<option value='SPAM'>SPAM<option value='Sold Buyer'>Sold Buyer<option value='Sold Seller'>Sold Seller<option value='Not Moving'>Not Moving<option value='Listed Home'>Listed Home";
?>
<body>

<?
if(!$agentemail) {
?>
<script type="text/javascript">
window.location="notgonnashowuthis";
</script>

<?
}
ticket_connect();
$result = mysql_query("SELECT ticketID,created,lead_status,subject,lo_franchise, email,name,lead_email,lead_name FROM mynewci_ticket WHERE email='$agentemail'") or die(mysql_error());

echo "<table id='gettickettable' border='1'>";
echo "<form method='post' action='notgonnashowuthis'>";
echo "<th>Ticket Number</th><th>Capture Date</th><th>Status</th><th>Subject</th><th>Franchise</th><th>Lead Owner</th><th>Owner Name</th><th>Lead Email</th><th>Lead Name</th>";

while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>";
echo $row['ticketID'];
echo "</td><td>";
echo $row['created'];
echo "</td><td>";
echo $selstatus;
echo "</td><td>";
echo $row['subject'];
echo "</td><td>";
echo $row['lo_franchise'];
echo "</td><td>";
echo $row['email'];
echo "</td><td>";
echo $row['name'];
echo "</td><td>";
echo $row['lead_email'];
echo "</td><td>";
echo $row['lead_name'];
echo "</td></tr>";
}
echo "</table>";
?>





Keep in mind this code is not fully complete simply b/c i cannot make the SPECIFIC change so the changestatus function is not written as it will be.
I know it is a simple thing probably but I just dont know how to make it happen... Several thousand people are waiting on this and I am sweating bullets right now.... Please help if you can, it will be much appreciated
#programming #database #php #select
  • Are you trying to call a php function from javascript?
    • [ 1 ] Thanks
    • [2] replies
    • Im not sure... All I know is that this code displays a table that has a dropdown box on every row. I want the dropdown box to change the db entry for status FOR that specific row, when someone clicks the select box and selects one of the options option.
    • I didnt know you could call a js func from php...
      I was trying to use the onchange event handler to make it update the db but the research I did only yeilded non specific results and absolutely no code examples. I am looking for a type of... Consultant who I can pay a retainer fee to to help me with stupid things like this so I dont have to spend 3 hrs looking for a simple solution to a simple problem. If anyone is interested please send rates to me either by PM or to my email which it wont let me post... with the subject: WARRIOR FOR HIRE
      Thanks in advance for all your help warriors!
      • [1] reply
  • It's easily done. It's done all the time, but your code above doesn't show any form fields.
    • [ 1 ] Thanks
    • [1] reply
    • No, you can't call the php function from javascript, which is what it looks like you are trying to do. You'll have to submit the form to actually do the update, or submit data using ajax.
      • [ 1 ] Thanks
  • Thank you guys! I just needed someone to put it into perspective for me!



    onchange="document.getElementById('form1').submit( );"

    <?

    function ticket_connect() {
    $db_host = "localhost";
    $db_user = "notgonnashowuthis";
    $db_password ="notgonnashowuthis";
    $db_name = "notgonnashowuthis";
    //create database connection
    $connection = @mysql_connect($db_host,$db_user,$db_password);
    //if there is no connection then display a message letting the user know.
    if($connection) {
    @mysql_select_db($db_name, $connection);
    }
    else{
    echo "ERROR!! Could not connect to the database at this time, we are sorry for the inconvenience. Please try again later.";
    }
    } // end function db_connect()
    *****NOTICE THE CHANGE---
    $selstatus = "
    <form id="form1" name="form1" method="post" action="pagetoinserttodb">
    <select onchange="document.getElementById('form1').submit( );"><option value='Renter Keep'>Renter Keep<option value='Renter Reject'>Renter Reject<option value='SPAM'>SPAM<option value='Sold Buyer'>Sold Buyer<option value='Sold Seller'>Sold Seller<option value='Not Moving'>Not Moving<option value='Listed Home'>Listed Home
    </select>
    <input name="submit" type="hidden" value="submit">
    </form>
    ";
    ---***CHANGE ENDS
    ?>
    <body>

    <?
    if(!$agentemail) {
    ?>
    <script type="text/javascript">
    window.location="notgonnashowuthis";
    </script>

    <?
    }
    ticket_connect();
    $result = mysql_query("SELECT ticketID,created,lead_status,subject,lo_franchise, email,name,lead_email,lead_name FROM mynewci_ticket WHERE email='$agentemail'") or die(mysql_error());

    echo "<table id='gettickettable' border='1'>";
    echo "<form method='post' action='notgonnashowuthis'>";
    echo "<th>Ticket Number</th><th>Capture Date</th><th>Status</th><th>Subject</th><th>Franchise</th><th>Lead Owner</th><th>Owner Name</th><th>Lead Email</th><th>Lead Name</th>";

    while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row into a table
    echo "<tr><td>";
    echo $row['ticketID'];
    echo "</td><td>";
    echo $row['created'];
    echo "</td><td>";
    echo $selstatus;
    echo "</td><td>";
    echo $row['subject'];
    echo "</td><td>";
    echo $row['lo_franchise'];
    echo "</td><td>";
    echo $row['email'];
    echo "</td><td>";
    echo $row['name'];
    echo "</td><td>";
    echo $row['lead_email'];
    echo "</td><td>";
    echo $row['lead_name'];
    echo "</td></tr>";
    }
    echo "</table>";
    ?>

    But now since the whole page will be full of forms with the same name how does the onchange js event know which one to submit? AND how does that select box know which leadID to send to be processed...
  • I need to share a link... Is there a moderator who can grant me access?
  • Banned
    [DELETED]
  • try this one:

    <?php

    function ticket_connect() {
    $db_host = "localhost";
    $db_user = "notgonnashowuthis";
    $db_password = "notgonnashowuthis";
    $db_name = "notgonnashowuthis";
    //create database connection
    $connection = @mysql_connect($db_host, $db_user, $db_password);
    //if there is no connection then display a message letting the user know.
    if ($connection) {
    @mysql_select_db($db_name, $connection);
    }
    else {
    echo "ERROR!! Could not connect to the database at this time, we are sorry for the inconvenience. Please try again later.";
    }
    } // end function db_connect()
    //*****NOTICE THE CHANGE---
    $selstatus = <<<eof
    <form id="form1" name="form1" method="post" action="pagetoinserttodb">
    <select onchange="document . getElementById('form1') . submit();"><option value='Renter Keep'>Renter Keep<option value='Renter Reject'>Renter Reject<option value='SPAM'>SPAM<option value='Sold Buyer'>Sold Buyer<option value='Sold Seller'>Sold Seller<option value='Not Moving'>Not Moving<option value='Listed Home'>Listed Home
    </select>
    <input name="submit" type="hidden" value="submit">
    </form>
    eof;

    //---***CHANGE ENDS
    ?>
    <body>

    <?
    if (!$agentemail) {
    ?>
    <script type="text/javascript">
    window.location = "notgonnashowuthis";
    </script>

    <?
    }
    ticket_connect();
    $result = mysql_query("SELECT ticketID,created,lead_status,subject,lo_franchise, email,name,lead_email,lead_name FROM mynewci_ticket WHERE email='$agentemail'") or die(mysql_error());

    echo "<table id='gettickettable' border='1'>";
    echo "<form method='post' action='notgonnashowuthis'>";
    echo "<th>Ticket Number</th><th>Capture Date</th><th>Status</th><th>Subject</th><th>Franchise</th><th>Lead Owner</th><th>Owner Name</th><th>Lead Email</th><th>Lead Name</th>";

    while ($row = mysql_fetch_array($result)) {
    // Print out the contents of each row into a table
    echo "<tr><td>";
    echo $row['ticketID'];
    echo "</td><td>";
    echo $row['created'];
    echo "</td><td>";
    echo $selstatus;
    echo "</td><td>";
    echo $row['subject'];
    echo "</td><td>";
    echo $row['lo_franchise'];
    echo "</td><td>";
    echo $row['email'];
    echo "</td><td>";
    echo $row['name'];
    echo "</td><td>";
    echo $row['lead_email'];
    echo "</td><td>";
    echo $row['lead_name'];
    echo "</td></tr>";
    }
    echo "</table>";
    ?>

    Im not sure if that is the only issue, but you cant mix " and ' and expect it all to work.

    It looks like what your trying to do is
    $selstatus = "some value";

    Thats fine. and single quotes are too:
    $selstatus = 'some value';

    but when you have a bunch of quotes INSIDE the other quotes, you confuse php....

    $selstatus = 'some (this won't work) value';

    it wont work because of the single quote inside the word " won't ".

    Php thinks thats the end of the = ''; statement.

    In the above code i changed it to use <<<eof. The other option is to escape your apostrophies.

    to make this work you would escape the apostrophy in won't
    $selstatus = 'some (this won't work) value';

    to this:
    $selstatus = 'some (this won\'t work) value';

    Then it would work.

Next Topics on Trending Feed

  • 11

    OK I have a slight problem that I think can be easily fixed... The code I am about to display is supposed to display a table filled with lead information, which it does just fine. Each lead has a select box to change the status of the lead in the db. HEREIN LIES THE PROBLEM. I do not know how to tell my sql query which lead to update... The leadID is supposed to be the lead to change but I dont know how to tell my sql that the action being taken is supposed to be done to this specific lead... Here is the code: