0

選択した顧客ページがあり、テーブルの行をクリックすると、現在作成中の注文の顧客 ID が設定されます。

ここに私がすでに持っているものがありますが、代わりに顧客を0に設定する顧客のIDを取得しません

function selectcust(str)

{
if (str=="")
  {
  document.getElementByid("description").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("description").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","php/insertcust.php?order=<?php echo $order; ?>&id="+str,true);
xmlhttp.send();
}

phpは

$id = $_GET['id'];
$order = $_GET['order'];

include('config.php');

$sqlins = "UPDATE `sales` SET customernumber='$id' WHERE invoice = '".$order."'";

if (!mysql_query($sqlins,$con))
  {
  die('Error: ' . mysql_error());
  }
 echo $id;

テーブルの行は

echo"
<tr value='" . $row[id] . "' onclick='selectcust(this.value)'><td>" . $row['surname'] . "</td><td>" . $row['firstname'] . "</td><td>" . $row['Postcode'] . "</td><td>" . $row['Houseno'] . "</td><td>" . $row['org'] . "</td><td>" . $row[id] . "</td></tr>"

;
4

4 に答える 4

0

ここには多くの危険信号がありますが、対処できないものはありません...

$mysqli = new mysqli(URL, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME);
$id = $_GET['id'];
$order = $_GET['order'];

include('config.php');

//The old mysql_query is now depreciated. Users now are to switch to mysqli or PDO
//The below is in mysqli and uses a prepared statement to protect against SQL injection
//attacks
$stmt = $mysqli->prepare("UPDATE `sales` SET customernumber=? WHERE invoice=?") or die("Error: " . $mysqli->error); //Set-up query, die and return error if it fails
$stmt->bind_param('ii', $id, $order); //Bind the paramaters to the query
$stmt->execute() or die("Error: " . $mysqli->error); //Execute the query or die and return the error if it fails

echo $id;

次のセクション:

$stmt = $mysqli->prepare("SELECT id, surname, firstname, Postcode, Houseno, org FROM sales") or die("Error: " . $mysqli->error);
$stmt->execute() or die("Error: " . $mysqli->error);
$stmt->bind_result($custid, $surname, $firstname, $Postcode, $Houseno, $org); //Bind the results from the query to variables
$stmt->store_result(); //Store the result so you can do other queries without triggering errors
while($stmt->fetch()) {?>

    //Instead of echoing you can write the following OUTSIDE of the `<?php` tags and then
    //use the `<?= ?>` shortcut tags to output it where you need it.

    <tr value="<?=$custid?>" onclick="selectcust(<?=$custid?>)">
        <td>
            <input type='button' src='images/btn_delete.png' value="<?=$row[id]?>" onfocus="selectcust(<?=$custid?>)" height='30'/>
            <?=$surname?>
        </td>
        <td><?=$firstname?></td>
        <td><?=$Postcode?></td>
        <td><?=$Houseno?></td>
        <td><?=$org?></td>
        <td><?=$custid?></td>
    </tr>

また、削除画像の<input type='text'を使用するつもりでしたか? src=のことです<input type='button'か?

さて、あなたの問題に移りましょう...

id関数に直接配置することでid、問題なく通過するはずです。

于 2013-05-08T18:15:54.507 に答える
0

を使用して値を渡す代わりにthis.value

試す

selectcust(" . $row[id] . ")
于 2013-05-08T17:59:04.557 に答える
0

さて、いくつかのトリックで読みやすくしてください。

$tr = <<<HTML
<tr id="{$row["id"]}" onclick="selectcust(this.id)">
    <td> 
        <input type="text" src="images/btn_delete.png" value="{$row[id]}" onfocus="selectcust(this.value)" height="30"/>
        {$row["surname"]}
    </td>
    <td>
        {$row["firstname"]}
    </td>
    <td>
        {$row["Postcode"]}
    </td>
    <td>
        {$row["Houseno"]}
    </td>
    <td>
        {$row["org"]}
    </td>
    <td>
        {$row["id"]}
    </td>
</tr>
HTML;
于 2013-05-08T17:21:45.140 に答える