<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[impostazione di un if su query]]></title><description><![CDATA[<p dir="auto">Ciao a tutti,<br />
Vorrei chiedervi un consiglio su come fare una cosa, dovendo far prendere una decisione con un if. Ho 3 campi in un db: Tel, nome, indirizzo.<br />
Quando l'utente immette in un form il tel, devo fare in modo che se quel n° è già presente ne db venga visualizzato insieme a nome ed indirizzo e lo faccio con una query select:<br />
&lt;?php<br />
if(isset($_POST['tel']) ){<br />
$tel= $_POST['tel'];<br />
$sql =  "SELECT * FROM clienti WHERE tel=$tel ";<br />
$query = mysql_query($sql);<br />
while($row = mysql_fetch_array($query,MYSQL_ASSOC)){<br />
}<br />
if($_POST['tel'] == $row['tel'])<br />
echo $tel;<br />
echo $ind;<br />
echo $nome;<br />
}<br />
?&gt;<br />
se invece quel numero di tel non è ancora nel db deve essere prma inserito e poi visualizzato insieme sempre a nome ed indirizzo:<br />
&lt;?php<br />
$tel=$_POST['tel'];<br />
$ind=$_POST['ind'];<br />
$nome=$_POST['nome'];</p>
<p dir="auto">$query="INSERT INTO clienti (  tel, ind, nome)<br />
VALUES<br />
( '$tel','$ind','$nome')";<br />
mysql_query($query,$db);<br />
echo $tel;<br />
echo $ind;<br />
echo $nome;<br />
?&gt;<br />
Come imposto l'if?, cioè come faccio a fargli capire che se $_POST['tel'] ha un valore uguale nel db deve fare una cosa, altrimenti ne deve fare un'altra?<br />
cioè:<br />
if { $_POST['tel'] == A COSA?......<br />
grazie 1000</p>
]]></description><link>https://dev.connect.gt/topic/101450/impostazione-di-un-if-su-query</link><generator>RSS for Node</generator><lastBuildDate>Wed, 25 Nov 2026 10:37:35 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/101450.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 14 May 2009 08:10:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to impostazione di un if su query on Thu, 14 May 2009 09:15:27 GMT]]></title><description><![CDATA[<p dir="auto">garzie tante adesso lo provo <img src="https://dev.connect.gt/assets/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=f1cecb658d8" class="not-responsive emoji emoji-android emoji--slightly_smiling_face" style="height:1.4em;width:auto;vertical-align:middle" title=":)" alt="🙂" /></p>
]]></description><link>https://dev.connect.gt/post/830631</link><guid isPermaLink="true">https://dev.connect.gt/post/830631</guid><dc:creator><![CDATA[popeye]]></dc:creator><pubDate>Thu, 14 May 2009 09:15:27 GMT</pubDate></item><item><title><![CDATA[Reply to impostazione di un if su query on Thu, 14 May 2009 09:10:06 GMT]]></title><description><![CDATA[<p dir="auto">Prova in questo modo:</p>
<pre><code class="language-php">&lt;?php
$tel=$_POST['tel'];
$ind=$_POST['ind'];
$nome=$_POST['nome'];

$sql = "SELECT * FROM clienti WHERE tel='$tel'";
$query = mysql_query($sql);

//IF(Numero esistente) ELSE (Numero inesistente)
if(mysql_num_rows($query) &gt; 0)
{
    //Inutile usare un while vuoto, visto che restituisce un solo risultato
    $row = mysql_fetch_array($query, MYSQL_ASSOC);
    
    echo $row["tel"];
    echo $row["ind"];
    echo $row["nome"];
}
else
{
    $query="INSERT INTO clienti (tel, ind, nome) VALUES ('$tel','$ind','$nome');";
    mysql_query($query, $db);
}
?&gt;
</code></pre>
<p dir="auto">Ciao!</p>
]]></description><link>https://dev.connect.gt/post/830632</link><guid isPermaLink="true">https://dev.connect.gt/post/830632</guid><dc:creator><![CDATA[sups]]></dc:creator><pubDate>Thu, 14 May 2009 09:10:06 GMT</pubDate></item></channel></rss>