Jump to content

Recommended Posts

Everything works, but it just doesn't create a new table or enter it in the database.

 

Here's the file:

 

<?
include("./config.php");

check_login($login);

switch($action){

case "challenge":
start_challenge($login);
break;



default:
check_login($login);
break;
}


function check_login($login){
global $config;

if(!mysql_num_rows(mysql_query("SELECT id FROM teams WHERE id='$login[id]' AND password='$login[pass]'"))){
$out[body].="
<center>
<table width='100%' border='0' cellspacing='1' cellpadding='1' bgcolor='#00000'>
<form method='post'>
<tr bgcolor='$config[altcolora]'>
<td width='100%' valign='center' align='left' colspan='2' background='$config[bg]'>
<strong><font face='verdana' color='#c7c7c7'>Comment</strong>";
if($login[failchallenge]){
$out[body].=" <font color='#c7c7c7' size='1'>(Incorrect Login)</font>";
}
$out[body].="
</td>
</tr>
<tr bgcolor='$config[altcolorb]'>
<td width='40%' valign='center' align='left'><font face='verdana' size='-2' color='#c7c7c7'>Your ID</td>
<td width='60%' valign='center' align='center'><input type='text' name='login[id]' class='button' value='$login[id]' size='25' maxlength='10'></td>
</tr>
<tr bgcolor='$config[altcolora]'>
<td width='40%' valign='center' align='left'><font face='verdana' size='-2' color='#c7c7c7'>Password</td>
<td width='60%' valign='center' align='center'><input type='password' name='login[pass]' class='button' value='' size='25' maxlength='10'></td>
</tr>
<tr bgcolor='$config[altcolorb]'>
<td width='40%' valign='center' align='left'><font face='verdana' size='-2' color='#c7c7c7'>Teams ID</td>
<td width='60%' valign='center' align='center'><input type='text' name='login[cid]' class='button' value='$login[cid]' size='25' maxlength='10'></td>
</tr>
<tr bgcolor='$config[altcolora]'>
<td width='40%' background='$config[tablex]' valign='center' align='left'><font color='#c7c7c7'>Comment:</td>
<td width='60%' background='$config[tablex]' valign='center' align='center'><TEXTAREA NAME='login[comment]' ROWS=15 COLS=37 WRAP=virtual></TEXTAREA></td>
</tr>
<tr bgcolor='$config[altcolora]'>
<td width='100%' valign='top' align='right' colspan='2'>
<input type='hidden' name='login[failchallenge]' value='1'>
<input type='hidden' name='action' value='challenge'>
<input type='submit' name='submit' value='Comment >>'></td>
</form>
</tr>
</table>
<br>
</center>";


include("$config[html]");
exit;
}
}



function start_challenge($login){
global $config;



if($login[id]=="$login[cid]"){
error("You cannot comment yourself.");
}

$challgdteam=mysql_query("SELECT ladderid,email FROM teams WHERE id='$login[cid]'");
$challgdteam=mysql_fetch_array($challgdteam);

if(!$challgdteam[ladderid]){
error("Unable to find the commented team.");
}

$ladder=mysql_query("SELECT * FROM ladders WHERE id='$challgdteam[ladderid]'");
$ladder=mysql_fetch_array($ladder);

if(!$ladder[name]){
error("Unable to load the ladder information.");
}

$challgr=mysql_query("SELECT * FROM ladder_$ladder[id] WHERE teamid='$login[id]'");
$challgr=mysql_fetch_array($challgr);

$challgd=mysql_query("SELECT * FROM ladder_$ladder[id] WHERE teamid='$login[cid]'");
$challgd=mysql_fetch_array($challgd);

if(!$challgr[name]){
error("Unable to find your teams stats.");
}

if(!$challgd[name]){
error("Unable to find the commented teams stats.");
}

$sql = 'INSERT INTO `comments` (`commid`, `commrid`, `commdid`, `commrname`, `commdname`, `commcreated`, `comment`) 
VALUES (\'\', \'$login[id]\', \'$login[cid]\', \'$challgr[name]\', \'$challgd[name]\', NOW(), \'$login[comment]\');';

$out[body].="
<br>
<center>
<b><font color='c7c7c7'>
Your comment to $challgd[name] has been recorded!<br>
<br></b>
</center>";

include("$config[html]");
}

?>

 

Please help me....

Link to comment
https://forums.phpfreaks.com/topic/53094-solved-simple-problem-please-help-me/
Share on other sites

so it works fine.. but doesn't do what you want!..

 

OK whats the problem error etc  ?

what part have to added that doesn't work..

 

your to lazy to give details and i'm to lazy to read your whole script..

 

I said it doesnt add anything to the database,

 

im guessing its

$sql = 'INSERT INTO `comments` (`commid`, `commrid`, `commdid`, `commrname`, `commdname`, `commcreated`, `comment`) 
VALUES (\'\', \'$login[id]\', \'$login[cid]\', \'$challgr[name]\', \'$challgd[name]\', NOW(), \'$login[comment]\');';

 

Or somethings preventing that from running.

I assume you mean this line:

 

$sql = 'INSERT INTO `comments` (`commid`, `commrid`, `commdid`, `commrname`, `commdname`, `commcreated`, `comment`) 
VALUES (\'\', \'$login[id]\', \'$login[cid]\', \'$challgr[name]\', \'$challgd[name]\', NOW(), \'$login[comment]\');';

 

You don't have a mysql_query and you also have one too many ; at the end. Also, try error reporting:

 

$sql = 'INSERT INTO `comments` (`commid`, `commrid`, `commdid`, `commrname`, `commdname`, `commcreated`, `comment`) 
VALUES (\'\', \'$login[id]\', \'$login[cid]\', \'$challgr[name]\', \'$challgd[name]\', NOW(), \'$login[comment]\')' or die(mysql_error());

 

Also, I know what the NOW() function is, but are you sure you can insert it directly into the MySQL database? I have only seen it used in Access and ASP. You might want to try date() instead since you're using PHP.

I assume you mean this line:

 

$sql = 'INSERT INTO `comments` (`commid`, `commrid`, `commdid`, `commrname`, `commdname`, `commcreated`, `comment`) 
VALUES (\'\', \'$login[id]\', \'$login[cid]\', \'$challgr[name]\', \'$challgd[name]\', NOW(), \'$login[comment]\');';

 

You don't have a mysql_query and you also have one too many ; at the end. Also, try error reporting:

 

$sql = 'INSERT INTO `comments` (`commid`, `commrid`, `commdid`, `commrname`, `commdname`, `commcreated`, `comment`) 
VALUES (\'\', \'$login[id]\', \'$login[cid]\', \'$challgr[name]\', \'$challgd[name]\', NOW(), \'$login[comment]\')' or die(mysql_error());

 

Also, I know what the NOW() function is, but are you sure you can insert it directly into the MySQL database? I have only seen it used in Access and ASP. You might want to try date() instead since you're using PHP.

 

The now function was outputted from phpmyadmin. I tried your second code and it said that the comment has been sucessfully submitted, but there's nothing in the database ...

You should use double quotes around your string instead of single quotes:

<?php
$sql = "INSERT INTO `comments` (`commid`, `commrid`, `commdid`, `commrname`, `commdname`, `commcreated`, `comment`) 
VALUES ('', '$login[id]', '$login[cid]', '$challgr[name]', '$challgd[name]', NOW(), '$login[comment]');";
?>

 

That line just defines the query, you aren't doing anything with it.

 

<?php
$q = "INSERT INTO `comments` (`commid`, `commrid`, `commdid`, `commrname`, `commdname`, `commcreated`, `comment`) 
VALUES ('', '$login[id]', '$login[cid]', '$challgr[name]', '$challgd[name]', NOW(), '$login[comment]')";
$rs = mysql_query($q) or die("Error with the query <pre>$q</pre><br>" . mysql_error());
?>

 

Also, you really should do some validation on the input and at least apply the function mysql_real_escape_string() to each string value when inserting them into the database.

 

Ken

You should use double quotes around your string instead of single quotes:

<?php
$sql = "INSERT INTO `comments` (`commid`, `commrid`, `commdid`, `commrname`, `commdname`, `commcreated`, `comment`) 
VALUES ('', '$login[id]', '$login[cid]', '$challgr[name]', '$challgd[name]', NOW(), '$login[comment]');";
?>

 

That line just defines the query, you aren't doing anything with it.

 

<?php
$q = "INSERT INTO `comments` (`commid`, `commrid`, `commdid`, `commrname`, `commdname`, `commcreated`, `comment`) 
VALUES ('', '$login[id]', '$login[cid]', '$challgr[name]', '$challgd[name]', NOW(), '$login[comment]')";
$rs = mysql_query($q) or die("Error with the query <pre>$q</pre><br>" . mysql_error());
?>

 

Also, you really should do some validation on the input and at least apply the function mysql_real_escape_string() to each string value when inserting them into the database.

 

Ken

 

Thank you, i love you.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.