php - sql connection error :(

Hello guys, im pretty new @ php and mysql and i have a project for my university to create an eshop site.
Im coding this project for quite a long time and today i kind of finished it, although i encountered some critical errors. It seems that my php code for mysql queries doesnt seem to work properly…If i give the same queries at mysql console its all fine, but with commands nothings works at all.I checked my code loads and loads of time and i cant understand what is wrong with it. If someone could help me cause my deadline is soon i would apreaciate it :slight_smile:

Here is my code:

[php]<?php
include(‘credentials.php’);
ini_set(‘display_errors’, ‘On’);
if (isset($_POST[‘username’]) && isset($_POST[‘password’]) ) {

$username= $_POST[‘username’];
$password= $_POST[‘password’];
$email= $_POST[‘email’];

$link=@mysqli_connect(“localhost”,$dbuser,$dbpass,$dbname);
if (mysqli_connect_errno()){
echo “Error at DB connection”;
echo mysqli_connect_error();
exit();
}

$query = “INSERT INTO users VALUES(’$username’,’$password’,’$email’,‘0’,‘null’,‘null’,‘null’)”;
mysqli_query($link,$query);
if ( mysqli_errno()) {
$error= mysqli_error();
header(“location: index.php?msg=$error”);
echo $error;
}
else {
header(“location: auth.php?msg=Need to authenticate thro your email dude”);

}

mysqli_close($link);

}

?>
[/php]

and the code from the form:

<body>

<div id="container">

  <div id="header">
<p class="top"> <strong> Dark Side Buisness Controller </strong> </p>
  </div>
	<div id="menu">
		<ul>
			<li><a href="index.php"> Home Page </a></li>
			<li><a href="about.php"> About US </a></li>
			<li><a href="register.php"> Register </a></li>
			<li><a href="login.php"> Login </a><li>
                        <?php if ( isset($_SESSION)) { ?>
                        <li><a href="control.php"> Control Panel</a><li>
			<li><a href="upload.php"> Upload </a><li>
			<li><a href="logout.php"> Logout</a><li>
                       <?php 
			}
			?>
		</ul>
	</div>

<div id="main">
<div id="formcontainer">
<form id="data" name="data" action="connection.php" method="POST">
<table width="100%" cellpadding="3" cellspacing="2">
<tr>
	<td width="25%"> </td>
</tr>
<tr>
	<td class="right" width="20%"> <strong> Username </strong> </td>
	<td>
	<input type="text" name="username" id="username" size="25" maxlength="25"/>
</td>
</tr>
<tr>
	<td class="right"> <strong> Password</strong> </td>
	<td>
	<input type="password" name="password" id="password" size="25" maxlength="25"/>
</td>
</tr>
<tr>
	<td class="right"> <strong> Email</strong> </td>
	<td>
	<input type="text" name="email" id="email"/>
	</td>
</tr>

<tr>   
 <td>
          <input name="reset" type="reset" id="reset" value="Reset" />
          <input name="submit" type="submit" id="submit" value="Submit" />

        </td>
</tr>
</table>
</form>
</div>

</div>
 
  <div id="footer">
    <p>&copy; 2012 - ΤΕΙ Λάρισας</p>
  </div>

</div>

</body>
</html>

Hi.

And the errormessage? They usually tell what is wrong. They can be very useful when trying to track an error.
Beside that, are you mixing up your ‘mysql’ and ‘mysqli’ ?

Catch you later. :smiley:

O.

Thats the prob. i dont get any error messages at all.

Try commenting out the header() redirect before echoing out the error to see what it says.

[php]
//header(“location: index.php?msg=$error”);
echo $error; // or var_dump($error);
exit();
[/php]

im a retard… I was loging @ phpmyadmin as root. When i loged as demouser that was the user that logging to mysqli-server i saw all my collums filled :smiley: :smiley:

now i have this problem :

this is my form code : http://pastebin.com/yMZRnbdT

and this is the insertion code:

[php]

<?php include('credentials.php') $afm= $_POST['afm']; $gender= $_POST['gender']; $year= $_POST['year']; $username=$_SESSION['name']; $link=@mysqli_connect("localhost",$dbuser,$dbpass,$dbname); if (mysqli_connect_errno()){ echo "Error at DB connection"; echo mysqli_connect_error(); die(mysqli_error()); $query="UPDATE users set year='$year',afm='$afm',gender='$gender' where username='$username' "; $result=mysqli_query($link,$query); if (mysqli_errno()) { die(mysqli_error()); } header("location:index.php?msg=Succuess"); mysqli_close($link); ?>

[/php]

root@bt:~# tail -f /var/log/apache2/error.log
[Sun Jun 03 05:25:42 2012] [error] [client 127.0.0.1] PHP Parse error: syntax error, unexpected T_VARIABLE in /var/www/insertmore.php on line 2, referer: http://127.0.0.1/control.php

it seems that post doesnt have any values at all :S :S :S

Sponsor our Newsletter | Privacy Policy | Terms of Service