Jump to content
php.lv forumi

Forums


Recommended Posts

Oi, atvainojos - reku ir

<?php
$mysqli = new mysqli('hosts','users','pass');
$mysqli -> select_db('index');
$result = $mysqli->query("SELECT * FROM teible ORDER BY id DESC");
while($row = $result->fetch_assoc()) {
print $row['1'] . ' <br/> ' . $row['2'] . '<br/>'.'<br>';
}
$result->close();
?>

Link to comment
Share on other sites

  • Replies 31
  • Created
  • Last Reply

Top Posters In This Topic

pirms ķerties pie datubāzēm iesaku KAUT NEDAUDZ palasīt par tām. kā tur viss notiek, etc.

 

+ tā mysql classe izskatās pēc varianta:

13394[/snapback]

Tā mysqli klase ir standarta PHP5 klase, ja kas.. Ka tik tev ne pašam ir jāpalasa php manuālis :) (http://lv.php.net/manual/en/ref.mysqli.php#mysqli.classes) Edited by bubu
Link to comment
Share on other sites

Ņāā atkal esmu nonācis strupceļā, un ceru uz jūsu palīdzību, jo pats netieku galā :).

Jautājums i šāds:

Kur īsti man te ir tā šitā kļūda: Warning: mysqli_query() expects at least 2 parameters, 1 given in c:\web\test\gb.php on line 8 ???

 

Izmēģināju viskko, nestrādā

 

<?php
if($_POST['submit'])
{
	 $mysqli = new mysqli('host','user','pass');
	 $mysqli->select_db('index');

$sql[addpost] = mysqli_query("INSERT INTO guestbook (name, email, message, date)
VALUES ('$_POST[name]','$_POST[email]','$_POST[message]',time())");

mysqli_close($mysqli);

echo "Thanks ".$_POST['name']." your message has been added\n";
}

?>

 

Nu šī ir 8. rindiņa:

$sql[addpost] = mysqli_query("INSERT INTO guestbook (name, email, message, date)
VALUES ('$_POST[name]','$_POST[email]','$_POST[message]',time())");

Link to comment
Share on other sites

Tu angļu valodu saproti?

Warning: mysqli_query() expects at least 2 parameters, 1 given in c:\web\test\gb.php on line 8 ???

Latviski tas nozīme: mysqli_query() sagaida vismaz 2 parametrus, bet iedots tikai 1!

Skaties šeit kādi parametri jānodot mysqli_query() funkcijai: http://lv.php.net/mysqli_query

Eh... kad reiz beidzot cilvēki iemācīsies lasīt kļūdu paziņojumus...

Link to comment
Share on other sites

HTML:

<form method="post" action="gb.php">
<table cellpadding="6" cellspacing="0">
<tr>
 <td>Vвrds :</td>
 <td><input type="text" name="name" /></td>
</tr>

<tr>
 <td>E-Mails :</td>
 <td><input type="text" name="email" /></td>
</tr>

<tr>
 <td valign="top">Ziņa:</td>
 <td><textarea name="message" cols="30" rows="6"></textarea></td>
</tr>

<tr>
 <td> </td>
 <td>
 <input type="submit" name="submit" value="Piemзslot" />
 <input type="reset" name="reset" value="Ne-Piemзslot" />
 </td>
</tr>
</table>
</form>

PHP:

<?php
if($_POST['submit'])
{
 $mysqli = new mysqli('localhost','root','074');
 $mysqli->select_db('index');
 
 $result = $mysqli->query("SELECT * FROM guestbook ORDER BY id DESC");
 while($row = $result->fetch_assoc()) {
 print '<p>' . $row['name'] . ' <br/> ' . $row['message'] . '<br/>'.'<br>'.'</p>';
 }
 $result->close();

$sql[addpost] = mysqli_query($mysqli, "INSERT INTO guestbook (name, email, message, date)
     or die(mysqli_errno()'. : .'mysqli_error());
VALUES ('$_POST[name]','$_POST[email]','$_POST[message]',time())");

mysqli_close($mysqli);
echo "Paldies, ".$_POST['name']." Jыsu ieraksts ir pievienots\n";
}

?>

Nu neiet, vinjsh nepievieno ierakstus DB, izmeegjinaaju visu ko, nekaadu eroru aaraa nemet, ilgi un dikti jau sezhu - neiet..... arii manuaalii tajaa lv.php.net/manual/en neko neatradu kas man palidzetu :( prasishu gudraakiem, kads var paliidzeet izprast kas te iisti ir pa kljuudu ka nepievieno db???

Edited by Forbidden
Link to comment
Share on other sites

Neko netesteeju, bet manupraat shitam vajadzeetu iet, ja tev ar teiblu viss ok.

viesugraamata.php:

<p><h1>Es miilu Kristabs</h1></p>
 <form method="post" action="gb.php">
<table cellpadding="6" cellspacing="0">
<tr>
<td>Vвrds :</td>
<td><input type="text" name="name" /></td>
</tr>

<tr>
<td>E-Mails :</td>
<td><input type="text" name="email" /></td>
</tr>

<tr>
<td valign="top">Ziņa:</td>
<td><textarea name="message" cols="30" rows="6"></textarea></td>
</tr>

<tr>
<td> </td>
<td>
<input type="submit" name="submit" value="Piemзslot" />
<input type="reset" name="reset" value="Ne-Piemзslot" />
</td>
</tr>
</table>
</form>
 
<?php
$hostname="localhost";
$mysql_login="root";
$mysql_password="074";
$database="index";
if (!($db = mysql_connect("$hostname", "$mysql_login" , "$mysql_password")))
{
 print("Nav konekcijas ar mysql vai kkas taads.");    
}
else
{
 if (!(mysql_select_db("$database",$db)))
 {
   print("nevar atrast DB.");
 }
}


$query  = "SELECT * FROM guestbook";  
 $result = mysql_query($query); 

 echo "<b>Mani vienreizeejie ieraksti viesu graamataa:</b><br><br>";

 while ($row = mysql_fetch_array($result)) {
 
    echo "<a href='mailto:$row['email']'><b>$row['name']</b></a><br>$row['message']\n"; 
 echo date('d.m.Y. H:i', $row['date']);
 } 
 ?>

gb.php:

<?php
$hostname="localhost";
$mysql_login="root";
$mysql_password="074";
$database="index";
if (!($db = mysql_connect("$hostname", "$mysql_login" , "$mysql_password")))
{
 print("Nav konekcijas ar mysql vai kkas taads.");    
}
else
{
 if (!(mysql_select_db("$database",$db)))
 {
   print("nevar atrast DB.");
 }
}

$name     = htmlspecialchars($_POST['name'],     ENT_QUOTES);
$email    = htmlspecialchars($_POST['email'],    ENT_QUOTES);
  
$message = wordwrap($_POST['message'], 55, ' ', 1);
$message = htmlspecialchars($kmessage, ENT_QUOTES);
  
$date       = mktime();

  if ($name && $message) {
    @mysql_query("INSERT INTO guestbook values(0, '$name', '$email', '$message', '$date')") or die(EJ BETONEET);     
  }
//to nulli ieliec pareizajaa vietaa, kura kolona tev peec kaartas ir id, tajaa vietaa arii liec shajaa rindaa
header("location: viesugraamata.php");
}


 ?>

Ja iet, tad no tevis alinsh.

Edited by Kristabs
Link to comment
Share on other sites

  • 2 weeks later...

jau atkal griežos pēc palīdzības pie jums. Laikam vel mazliet un mani vairs te neieredzēs ne ar acu galu...

Nu ka nepievieno DB, ta nepievieno, nedalec man :(

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table cellpadding="6" cellspacing="0">
<tr>
 <td>Vвrds :</td>
 <td><input type="text" name="name" /></td>
</tr>

<tr>
 <td>E-Mails :</td>
 <td><input type="text" name="email" /></td>
</tr>

<tr>
 <td valign="top">Ziтa:</td>
 <td><textarea name="message" cols="30" rows="6"></textarea></td>
</tr>

<tr>
 <td> </td>
 <td>
 <input type="submit" name="$_POST[submit]" value="Piemзslot" />
 <input type="reset" name="reset" value="Ne-Piemзslot" />
 </td>
</tr>
</table>
</form>

<?php
error_reporting(E_ALL);
if($_POST['submit'])
{
 $mysqli = new mysqli('host','usr','pass');
 $mysqli->select_db('index');
 
 $result = $mysqli->query("SELECT * FROM guestbook ORDER BY id DESC");
 while($row = $result->fetch_assoc()) {
 print '<p>' . $row['name'] . ' <br/> ' . $row['message'] . '<br/>'.'<br>'.'</p>';
 }
 $result->close();

$sql['addpost'] = mysqli_query($mysqli, "INSERT INTO guestbook (name, email, message, date)
     or die(mysqli_errno()'. : .'mysqli_error());
VALUES ('$_POST[name]','$_POST[email]','$_POST[message]',time())");

mysqli_close($mysqli);
echo "Paldies, ".$_POST['name']." Jыsu ieraksts ir pievienots\n";
}

?>

 

Ieliku ari HTML jo laikam kautko ne taa esmu salicis. Nu lieta tada ka name, email, message jams saprot kaa nodefineetus, bet submit nee :( kas par vainu?

Edited by Forbidden
Link to comment
Share on other sites

Es rakstitu shadi:

<?php
error_reporting(E_ALL);
if(!isset($_GET['darbiba']))
{
echo' 
<form method="post" action="$_SERVER['PHP_SELF']?darbiba=pievienot>

... nak parejais, html kods 

 <input type="submit" name="submit" value="Piemзslot" />
 <input type="reset" name="reset" value="Ne-Piemзslot" />
 </td>
</tr>
</table>
</form>'; 
elseif($_GET['darbiba'] == 'pievienot')
{
 $mysqli = new mysqli('host','usr','pass');
 $mysqli->select_db('index');
 
 $result = $mysqli->query("SELECT * FROM guestbook ORDER BY id DESC");
 while($row = $result->fetch_assoc()) {
 print '<p>' . $row['name'] . ' <br/> ' . $row['message'] . '<br/>'.'<br>'.'</p>';
 }
 $result->close();

$sql['addpost'] = mysqli_query($mysqli, "INSERT INTO guestbook (name, email, message, date)
     or die(mysqli_errno()'. : .'mysqli_error());
VALUES ('$_POST[name]','$_POST[email]','$_POST[message]',time())");

mysqli_close($mysqli);
echo "Paldies, ".$_POST['name']." Jыsu ieraksts ir pievienots\n";
}

?>

 

Neesmu testejis, bet vajadzetu stradat. Pats shadu variantu lietoju. Iespejams ka ir efektivaki varianti, bet tur varetu kadi profesionalaki koderi palidzet...

Link to comment
Share on other sites

Pag, es nesaprotu: vai tad šitais ir sintaktiski korekts (izpildoties neizmet nekādu kļūdas paziņojumu?)

$sql['addpost']= mysqli_query($mysqli, "INSERT INTO guestbook (name, email, message, date)

    or die(mysqli_errno()'. : .'mysqli_error());

VALUES ('$_POST[name]','$_POST','$_POST[message]',time())");

Manuprāt tur absolūts sviests.

Link to comment
Share on other sites


×
×
  • Create New...