php - Why is it not inserting to the database? -
php - Why is it not inserting to the database? -
<?php if(!isset($_get['nick'])) { echo '<form action="ban.php" method="get"> <input placeholder="username" type="text" name="nick"/> <input placeholder="reason" type="text" name="reason"/> <input type="submit" value"ban!"/>'; } else { $nick = mysql_real_escape_string($_get['nick']); $reason = mysql_real_escape_string($_get['reason']); $query = mysql_query("select name users name='".$nick."'"); if (mysql_num_rows($query) != 0) { while($rows = mysql_fetch_assoc($query)) { $ip = $rows['ip']; } } else { echo "no user found!"; } $today = date("d/m/y"); $sql = "insert bans (`name`, `ip`, `breason`, `badmin`, `bdate`) values ('$nick', '$ip', '$reason', '$name', '$today')"; if ($connect->query($sql) === true) { echo "may business relationship rest in peace."; } else { echo "error: " . $sql . "<br>" . $conn->error; } } ?>
for reason, doesn't insert database. doesn't show message. tried lot can't seem find prepare it.
help please? give thanks you.
you have several issues, firstly really, replace mysql mysqli , read bit how edit sql create mysqli - doesn't take much time or effort alter mysql better.
as code:
$query = mysql_query("select name users name='".$nick."'"); if (mysql_num_rows($query) != 0) { while($rows = mysql_fetch_assoc($query)) { $ip = $rows['ip']; } }
you running $query returning values of name name = '"$nick"'.
it may not issue seems me work improve contain strings straight mysql -
name = '$nick'
but you're returning name searching name output of $query ever $rows['name'] = $nick. if want ip set query to:
$query = mysql_query("select ip users name='$nick' ");
so homecoming in $row key value pair of $row['ip'] = ip value want.
$connet->query() may work looks different form above mysql code, , may not work old mysql (rather mysqli). try:
if(mysql_query("insert bans (`name`, `ip`, `breason`, `badmin`, `bdate`) values ('$nick', '$ip', '$reason', '$name', '$today')")){ print "inserted ok!"; } else { print mysql_error(); <== output error if previous query fails. }
try above , see find .
edit: http://www.pontikis.net/blog/how-to-use-php-improved-mysqli-extension-and-why-you-should gives decent guide on how turn mysql mysqli . check version of php run mysql deprecated , doesn't work more recent php. check php error log file background info why don't responses expect.
php mysql
Comments
Post a Comment