Jump to content

Sooth

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Sooth's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi! I've made this program to display permutations of a specified number. Anyone knows how should I change the line for(i=1;i<=k-1;i++)if(x[i]==x[k])ev=0; so that it will display combinations instead of permutations? Here is the program for permutations: #include<iostream.h> #include<conio.h> int x[20],i,k,as,ev,n,m; void succ(int k, int&as) { if(x[k]<m) { as=1; x[k]=x[k]+1; } else as=0; } void valid(int k, int &ev) { ev=1; for(i=1;i<=k-1;i++)if(x[i]==x[k])ev=0; } void afis(int k) { for(i=1; i<=k;i++)cout<<x[i]; cout<<endl; } void main() { cout<<"permutations of "; cin>>n; m=n; k=1; x[k]=0; while(k>0) { do { succ(k,as); if(as)valid(k,ev); } while(as&&!ev); if(as)if(k==m)afis(k); else { k=k+1; x[k]=0; } else k=k-1; } getche(); }
  2. Hi! I'm making a PMs script for an website and I get an error regarding mysql_numrows. I dont know if the error is in the database or in the script, so I'm showing them both. Here is the database table <i>pms</i>: Here is the script: <?php mysql_connect($db_hostname,$db_username,$db_password); @mysql_select_db($db_database)or die($db_error); $query="SELECT * FROM pms WHERE to='$_SESSION[username]'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> This is the error: Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/a3033866/public_html/myprofile_messages.php on line 14 Line 14 is the one where mysql_numrows is called.
  3. Yes. I can echo the query. It looks OK.
  4. Hi! I made this code to edit news on an website. The query looks OK, but it is not updating the news. <?php session_start(); include "config.inc.php"; include "header.inc.php"; ?> <h1>Admin » News » Edit</h1> <?php if($_SESSION[admin]) { ?> <?php include "admin_menu.inc.php"; ?> <?php if($_POST[e]) { mysql_connect($db_hostname,$db_username,$db_password); @mysql_select_db($db_error); $query="UPDATE news SET title='$_POST[title]', content='$_POST[content]' WHERE id='$_GET[n]'"; mysql_query($query); mysql_close(); echo "<p>News updated.</p>"; } else { mysql_connect($db_hostname,$db_username,$db_password); @mysql_select_db($db_database)or die($db_error); $query="SELECT * FROM news WHERE id='$_GET[n]'"; $result=mysql_query($query);mysql_close(); while($row=mysql_fetch_array($result)) {?> <form action="<?php echo $site_address; ?>admin/news/edit/<?php echo $_GET[n]; ?>/" method="post"> <p>Title</p> <p><input type="text" name="title" value="<?php echo $row[title]; ?>" style="width: 200px;" /></p> <p>Content</p> <p><textarea name="content" cols="100" rows="10"><?php echo $row[content]; ?></textarea></p> <p><input type="hidden" name="e" value="1" /><input type="submit" value="OK" /></p> </form> <?php } } } else echo "<p>You must be an Administrator to view this page.</p>"; ?> <?php include "footer.inc.php"; ?> The URLs are rewritted and ...news/edit/xxxx/ becomes ...edit.php?n=xxxx, so the problem isn't at the $_GET[n] neither. I've made a similar page to write news and it works perfectly. What could be wrong?
  5. Sooth

    query

    I have session_start(); and the query looks alright when I echo it. But it's not chaning the database.
  6. Sooth

    query

    What's wrong with this script. It doesn't update as required. include "config.php"; mysql_connect($db_hostname,$db_username,$db_password); @mysql_select_db($db_database)or die("<p>Unable to select database.</p>"); $query="UPDATE users SET email='$_POST[update_email]', firstname='$_POST[update_firstname]', lastname='$_POST[update_lastname]', birthday='$_POST[update_birthday]', birthmonth='$_POST[update_birthmonth]', birthyear='$_POST[update_birthyear]', genre='$_POST[update_genre]', nationality='$_POST[update_nationality]', config='$_POST[update_config]' WHERE username='$_SESSION[username]'"; mysql_query($query); mysql_close();
  7. Its not working. The page is white.
  8. Hi. I'm trying to make a registration script but it doesnt work. <?php $show_error1='0'; $show_error2='0'; $show_error3='0'; if($_POST['reg_username']==''||$_POST['reg_password1']==''||$_POST['reg_password2']==''||$_POST['reg_email']=='')$show_error1='1'; if($_POST['reg_password1']!=$_POST['reg_password2'])$show_error2='1'; mysql_connect($host,$user,$pass); @mysql_select_db($db)or die("<h2>Error</h2><p>Unable to select database.</p>"); $query="SELECT * FROM users WHERE nick='$_POST[reg_username]'"; mysql_close(); $result=mysql_query($query); $num=mysql_num_rows($result); if($num>0) { $show_error3='1'; } if($show_error1=='0'&&$show_error2=='0'&&$show_error3=='0') { mysql_connect($host,$user,$pass); @mysql_select_db($db)or die("<h2>Error</h2><p>Unable to select database.</p>"); $query="INSERT INTO users VALUES ('','$_POST[reg_username]','$_POST[reg_password1]','$_POST[reg_email]','','','','','','$_POST[reg_nationality]','$_POST[reg_sex]','','','','','','0')"; mysql_query($query); mysql_close(); ?> <h2>Register</h2> <p>Registration succesful! You may now login.</p> <?php } else { ?> <h2>Error</h2> <?php } if($show_error1=='1')echo "<p>You must complete all fields.</p>"; if($show_error2=='1')echo "<p>The password fields must match.</p>"; if($show_error3=='1')echo "<p>The username is already in the database.</p>"; ?> Whats the easiest way to check if the user is already in the database? I cant make an working script to do this.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.